From d630277ed6a1a55896003e94748ac97fc62dc5be Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Wed, 29 Sep 2021 10:17:56 +0000 Subject: [PATCH] transplant file test (withtime) on folders --- test_date2name.py | 38 ++++++++++++++++++++++++++++++++++++++ test_generator.org | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/test_date2name.py b/test_date2name.py index 7426d42..868af2a 100644 --- a/test_date2name.py +++ b/test_date2name.py @@ -422,3 +422,41 @@ def test_folder_pattern_short(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.withtime +@pytest.mark.parametrize("arg1", ["-w -d", "-w --directories", + "--withtime -d", "--withtime --directories", + "-w -m", "-w --mtime", + "--withtime -m", "--withtime --mtime", + "-w -c", "-w --ctime", + "--withtime -c", "--withtime --ctime"]) +def test_file_pattern_withtime(arg1, name=TFOLDER): + """Prepend 'YYYY-MM-DDThh.mm.ss_' to the folder name.""" + prepare_testfolder(name) + day = str("") + new = str("") + + if arg1 in ["-w -d", "-w --directories", + "--withtime -d", "--withtime --directories", + "-w -m", "-w --mtime", + "--withtime -m", "--withtime --mtime"]: + day = query_modification_time(name).split()[0] + second = query_modification_time(name).split()[1] + + elif arg1 in ["-w -c", "-w --ctime", + "--withtime -c", "--withtime --ctime"]: + day = query_creation_time(name).split()[0] + second = query_creation_time(name).split()[1] + + second = second.split(".")[0] # use integer seconds only + second = second.replace(":", ".") # adjust representation + + new = "".join([day, "T", second, "_", 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 e05ed71..c22fd80 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 [4/6] +*** perform the tests on folders [5/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 @@ -624,7 +624,46 @@ assert os.path.isdir(new) is False # space cleaning #+end_src - + [ ] withtime pattern, YYYY-MM-DDThh.mm.ss_ prepended + + [X] withtime pattern, YYYY-MM-DDThh.mm.ss_ prepended + #+begin_src python :tangle test_date2name.py + @pytest.mark.folders + @pytest.mark.withtime + @pytest.mark.parametrize("arg1", ["-w -d", "-w --directories", + "--withtime -d", "--withtime --directories", + "-w -m", "-w --mtime", + "--withtime -m", "--withtime --mtime", + "-w -c", "-w --ctime", + "--withtime -c", "--withtime --ctime"]) + def test_file_pattern_withtime(arg1, name=TFOLDER): + """Prepend 'YYYY-MM-DDThh.mm.ss_' to the folder name.""" + prepare_testfolder(name) + day = str("") + new = str("") + + if arg1 in ["-w -d", "-w --directories", + "--withtime -d", "--withtime --directories", + "-w -m", "-w --mtime", + "--withtime -m", "--withtime --mtime"]: + day = query_modification_time(name).split()[0] + second = query_modification_time(name).split()[1] + + elif arg1 in ["-w -c", "-w --ctime", + "--withtime -c", "--withtime --ctime"]: + day = query_creation_time(name).split()[0] + second = query_creation_time(name).split()[1] + + second = second.split(".")[0] # use integer seconds only + second = second.replace(":", ".") # adjust representation + + new = "".join([day, "T", second, "_", 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 + [ ] retraction of the date/time stamp