From ec1a3ccf2b848baf8a474ca37170d11f23388f84 Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Wed, 29 Sep 2021 09:50:58 +0000 Subject: [PATCH] transplant file test (month) on folders --- test_date2name.py | 37 +++++++++++++++++++++++++++++++++++++ test_generator.org | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/test_date2name.py b/test_date2name.py index 5d605e7..abcc357 100644 --- a/test_date2name.py +++ b/test_date2name.py @@ -346,3 +346,40 @@ def test_folder_pattern_compact(arg1, name=TFOLDER): assert os.path.isdir(new) # presence stamped folder os.rmdir(new) assert os.path.isdir(new) is False # space cleaning + +@pytest.mark.folders +@pytest.mark.month +@pytest.mark.parametrize("arg1", ["-M", "--month", + "-M -d", "--month -d", + "-M --directories", "--month --directories", + "-M -m", "--month -m", + "-M --mtime", "--month --mtime", + "-M -c", "--month -c", + "-M --ctime", "--month --ctime"]) +def test_file_pattern_month(arg1, name=TFOLDER): + """Prepend 'YYYY-MM_' to the file name.""" + prepare_testfolder(name) + day = str("") + new = str("") + + if arg1 in ["-M", "--month", + "-M -d", "--month -d", + "-M --directories", "--month --directories", + "-M -m", "--month -m", + "-M --mtime", "--month --mtime"]: + day = query_modification_time(name).split()[0] + + elif arg1 in ["-M -c", "--month -c", + "-M --ctime", "--month --ctime"]: + day = query_creation_time(name).split()[0] + + # trim off the last three characters in the datestamp: + day = day[:-3] + + new = "_".join([day, name]) + test = getoutput(f"python3 {PROGRAM} {name} {arg1}") + + assert os.path.isdir(name) is False # absence unstamped folder + assert os.path.isdir(new) # presence stamped folder + os.rmdir(new) + assert os.path.isdir(new) is False # space cleaning diff --git a/test_generator.org b/test_generator.org index 0f76fba..ade8710 100755 --- a/test_generator.org +++ b/test_generator.org @@ -467,7 +467,7 @@ assert os.path.isfile("test.txt") is False #+end_src -*** perform the tests on folders [2/6] +*** perform the tests on folders [3/6] At present, most of the instructions already defined and used in section "test on files" is repeated with small adjustments for checking date2name's @@ -540,10 +540,47 @@ assert os.path.isdir(new) # presence stamped folder os.rmdir(new) assert os.path.isdir(new) is False # space cleaning - #+end_src - + [ ] month pattern, YYYY-MM_ prepended + + [X] month pattern, YYYY-MM_ prepended + #+begin_src python :tangle test_date2name.py + @pytest.mark.folders + @pytest.mark.month + @pytest.mark.parametrize("arg1", ["-M", "--month", + "-M -d", "--month -d", + "-M --directories", "--month --directories", + "-M -m", "--month -m", + "-M --mtime", "--month --mtime", + "-M -c", "--month -c", + "-M --ctime", "--month --ctime"]) + def test_file_pattern_month(arg1, name=TFOLDER): + """Prepend 'YYYY-MM_' to the file name.""" + prepare_testfolder(name) + day = str("") + new = str("") + + if arg1 in ["-M", "--month", + "-M -d", "--month -d", + "-M --directories", "--month --directories", + "-M -m", "--month -m", + "-M --mtime", "--month --mtime"]: + day = query_modification_time(name).split()[0] + + elif arg1 in ["-M -c", "--month -c", + "-M --ctime", "--month --ctime"]: + day = query_creation_time(name).split()[0] + + # trim off the last three characters in the datestamp: + day = day[:-3] + + new = "_".join([day, name]) + test = getoutput(f"python3 {PROGRAM} {name} {arg1}") + + assert os.path.isdir(name) is False # absence unstamped folder + assert os.path.isdir(new) # presence stamped folder + os.rmdir(new) + assert os.path.isdir(new) is False # space cleaning + #+end_src + [ ] short pattern, YYMMDD_ prepended