From ed8b3652c91e4cd6729e6504df7420a22a3cd4f8 Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Fri, 17 Sep 2021 16:48:38 +0000 Subject: [PATCH] Include short datestamp for files in tests. The tests include Reiner Rottmann's suggestion of a short timestamp (i.e., YYMMDD) on files. --- README.org | 1 + test_date2name.py | 38 +++++++++++++++++++++++++++++++-- test_generator.org | 52 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/README.org b/README.org index 217166f..40477b2 100644 --- a/README.org +++ b/README.org @@ -32,6 +32,7 @@ Run "date2name --help" for usage hints such as: : -h, --help show the extended help message and exit : -d, --directories modify only directory names : -f, --files modify only file names +: -S, --short use short datestamp (YYMMDD) : -C, --compact use compact datestamp (YYYYMMDD) : -M, --month use datestamp with year and month (YYYY-MM) : -w, --withtime use datestamp including seconds (YYYY-MM-DDThh.mm.ss) diff --git a/test_date2name.py b/test_date2name.py index bbe86da..267c472 100644 --- a/test_date2name.py +++ b/test_date2name.py @@ -118,7 +118,7 @@ def test_compact_pattern_YYYYMMDD(arg1): "-C --ctime", "--compact --ctime"]: day = query_file_creation().split()[0] - # drop the hyphens in the date stamp: + # drop the hyphens in the datestamp: day = day.replace("-", "") new = "_".join([day, TFILE]) @@ -150,7 +150,7 @@ def test_compact_month_YYYY_MM(arg1): "-M --ctime", "--month --ctime"]: day = query_file_creation().split()[0] - # trim off the last three characters in the date stamp: + # trim off the last three characters in the datestamp: day = day[:-3] new = "_".join([day, TFILE]) @@ -190,3 +190,37 @@ def test_default_pattern_YYYY_MM_DDThh_mm_ss(arg1): test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}") assert os.path.isfile(new) os.remove(new) + +@pytest.mark.parametrize("arg1", ["-S", "--short", + "-S -f", "--short -f", + "-S --files", "--short --files", + "-S -m", "--short -m", + "-S --mtime", "--short --mtime", + "-S -c", "--short -c", + "-S --ctime", "--short --ctime"]) +def test_short_pattern_YYMMDD(arg1): + """Prepend 'YYMMDD_' to the file name.""" + prepare_testfile() + day = str("") + new = str("") + + if arg1 in ["-S", "--short", + "-S -f", "--short -f", + "-S --files", "--short --files", + "-S -m", "--short -m", + "-S --mtime", "--short --mtime"]: + day = query_file_modification().split()[0] + + elif arg1 in ["-S -c", "--short -c", + "-S --ctime", "--short --ctime"]: + day = query_file_creation().split()[0] + + # drop the hyphens in the datestamp: + day = day.replace("-", "") + # drop the first two characters about the year (e.g., 1789 -> 89) + day = day[2:] + + new = "_".join([day, TFILE]) + test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}") + assert os.path.isfile(new) + os.remove(new) diff --git a/test_generator.org b/test_generator.org index 58a39fd..c125923 100755 --- a/test_generator.org +++ b/test_generator.org @@ -8,10 +8,10 @@ * Intent - The application =date2name= by Karl Voit /et al./ ([[https://github.com/novoid/date2name][source)]] prepends date - stamps to files and folders (YYYY-MM-DD, YYYYMMDD, YYYY-MM, and - YYYY-MM-DDThh.mm.ss). This Emacs .org file is used to prepare the automatic - testing of the file processing by [[https://docs.pytest.org/en/latest/][pytest]]. + The application =date2name= by Karl Voit /et al./ ([[https://github.com/novoid/date2name][source)]] prepends datestamps + to files and folders (YYYY-MM-DD, YYYYMMDD, YYYY-MM, and YYYY-MM-DDThh.mm.ss). + This Emacs .org file is used to prepare the automatic testing of the file + processing by [[https://docs.pytest.org/en/latest/][pytest]]. By the command =C-c C-v t=, this =.org= file may (re)generate the tangled test script, file =test_date2name.py= as well as a dedicated =Makefile= to ease the @@ -176,7 +176,7 @@ #+end_src -*** perform the tests on files [4/4] +*** perform the tests on files [5/5] These tests check the addition of a time stamp ahead of the file name. @@ -231,7 +231,7 @@ "-C --ctime", "--compact --ctime"]: day = query_file_creation().split()[0] - # drop the hyphens in the date stamp: + # drop the hyphens in the datestamp: day = day.replace("-", "") new = "_".join([day, TFILE]) @@ -268,7 +268,7 @@ "-M --ctime", "--month --ctime"]: day = query_file_creation().split()[0] - # trim off the last three characters in the date stamp: + # trim off the last three characters in the datestamp: day = day[:-3] new = "_".join([day, TFILE]) @@ -314,3 +314,41 @@ os.remove(new) #+end_src + + [X] Preprend the short datestamp (YYMMDD, feature by Reiner Rottmann) + Related to the basic pattern, except truncating of the first two + characters. + #+begin_src python :tangle test_date2name.py + @pytest.mark.parametrize("arg1", ["-S", "--short", + "-S -f", "--short -f", + "-S --files", "--short --files", + "-S -m", "--short -m", + "-S --mtime", "--short --mtime", + "-S -c", "--short -c", + "-S --ctime", "--short --ctime"]) + def test_short_pattern_YYMMDD(arg1): + """Prepend 'YYMMDD_' to the file name.""" + prepare_testfile() + day = str("") + new = str("") + + if arg1 in ["-S", "--short", + "-S -f", "--short -f", + "-S --files", "--short --files", + "-S -m", "--short -m", + "-S --mtime", "--short --mtime"]: + day = query_file_modification().split()[0] + + elif arg1 in ["-S -c", "--short -c", + "-S --ctime", "--short --ctime"]: + day = query_file_creation().split()[0] + + # drop the hyphens in the datestamp: + day = day.replace("-", "") + # drop the first two characters about the year (e.g., 1789 -> 89) + day = day[2:] + + new = "_".join([day, TFILE]) + test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}") + assert os.path.isfile(new) + os.remove(new) + #+end_src