Include short datestamp for files in tests.

The tests include Reiner Rottmann's suggestion of a short timestamp
(i.e., YYMMDD) on files.
This commit is contained in:
Norwid Behrnd 2021-09-17 16:48:38 +00:00
parent 7dc1dc6d2e
commit ed8b3652c9
3 changed files with 82 additions and 9 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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