mirror of
https://github.com/novoid/date2name.git
synced 2026-06-14 11:01:19 +00:00
Sort sequence of entries present.
Because the pattern for testing on files will be used for the on folders, a reorganization of the instructions. Stamps checked so far are generated either in default pattern, or (compact, month, short) pattern, or with time. Thus, it appears reasonable to harmonize this sequence across the relevant files.
This commit is contained in:
parent
21935c7aac
commit
bda8757f01
4 changed files with 105 additions and 105 deletions
|
|
@ -71,15 +71,15 @@ parser.add_option("-d", "--directories", dest="onlydirectories",
|
||||||
parser.add_option("-f", "--files", dest="onlyfiles",
|
parser.add_option("-f", "--files", dest="onlyfiles",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="modify only file names")
|
help="modify only file names")
|
||||||
parser.add_option("-S", "--short", dest="short",
|
|
||||||
action="store_true",
|
|
||||||
help="use short datestamp (YYMMDD)")
|
|
||||||
parser.add_option("-C", "--compact", dest="compact",
|
parser.add_option("-C", "--compact", dest="compact",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="use compact datestamp (YYYYMMDD)")
|
help="use compact datestamp (YYYYMMDD)")
|
||||||
parser.add_option("-M", "--month", dest="month",
|
parser.add_option("-M", "--month", dest="month",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="use datestamp with year and month (YYYY-MM)")
|
help="use datestamp with year and month (YYYY-MM)")
|
||||||
|
parser.add_option("-S", "--short", dest="short",
|
||||||
|
action="store_true",
|
||||||
|
help="use short datestamp (YYMMDD)")
|
||||||
parser.add_option("-w", "--withtime", dest="withtime",
|
parser.add_option("-w", "--withtime", dest="withtime",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="use datestamp including seconds (YYYY-MM-DDThh.mm.ss)")
|
help="use datestamp including seconds (YYYY-MM-DDThh.mm.ss)")
|
||||||
|
|
|
||||||
10
pytest.ini
10
pytest.ini
|
|
@ -4,9 +4,9 @@ markers =
|
||||||
files: tests about affect by date2name on files
|
files: tests about affect by date2name on files
|
||||||
folders: tests about affect by date2name on folders
|
folders: tests about affect by date2name on folders
|
||||||
|
|
||||||
default: stamp pattern default
|
default: stamp pattern default, YYYY-MM-DD
|
||||||
compact: stamp pattern compact
|
compact: stamp pattern compact, YYYYMMDD
|
||||||
month: stamp pattern month
|
month: stamp pattern month, YYYY-MM
|
||||||
withtime: stamp pattern withtime
|
short: stamp pattern short, YYMMDD
|
||||||
short: stamp pattern short
|
withtime: stamp pattern withtime, YYYY-MM-DDThh.mm.ss
|
||||||
remove: stamp retraction
|
remove: stamp retraction
|
||||||
|
|
|
||||||
|
|
@ -186,41 +186,6 @@ def test_file_pattern_month(arg1):
|
||||||
assert os.path.isfile(new)
|
assert os.path.isfile(new)
|
||||||
os.remove(new)
|
os.remove(new)
|
||||||
|
|
||||||
@pytest.mark.files
|
|
||||||
@pytest.mark.withtime
|
|
||||||
@pytest.mark.parametrize("arg1", ["-w -f", "-w --files",
|
|
||||||
"--withtime -f", "--withtime --files",
|
|
||||||
"-w -m", "-w --mtime",
|
|
||||||
"--withtime -m", "--withtime --mtime",
|
|
||||||
"-w -c", "-w --ctime",
|
|
||||||
"--withtime -c", "--withtime --ctime"])
|
|
||||||
def test_file_pattern_withtime(arg1):
|
|
||||||
"""Prepend 'YYYY-MM-DDThh.mm.ss_' to the file name."""
|
|
||||||
prepare_testfile()
|
|
||||||
day = str("")
|
|
||||||
new = str("")
|
|
||||||
|
|
||||||
if arg1 in ["-w -f", "-w --files",
|
|
||||||
"--withtime -f", "--withtime --files",
|
|
||||||
"-w -m", "-w --mtime",
|
|
||||||
"--withtime -m", "--withtime --mtime"]:
|
|
||||||
day = query_modification_time().split()[0]
|
|
||||||
second = query_modification_time().split()[1]
|
|
||||||
|
|
||||||
elif arg1 in ["-w -c", "-w --ctime",
|
|
||||||
"--withtime -c", "--withtime --ctime"]:
|
|
||||||
day = query_creation_time().split()[0]
|
|
||||||
second = query_creation_time().split()[1]
|
|
||||||
|
|
||||||
second = second.split(".")[0] # use integer seconds only
|
|
||||||
second = second.replace(":", ".") # adjust representation
|
|
||||||
|
|
||||||
new = "".join([day, "T", second, "_", TFILE])
|
|
||||||
|
|
||||||
test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}")
|
|
||||||
assert os.path.isfile(new)
|
|
||||||
os.remove(new)
|
|
||||||
|
|
||||||
@pytest.mark.files
|
@pytest.mark.files
|
||||||
@pytest.mark.short
|
@pytest.mark.short
|
||||||
@pytest.mark.parametrize("arg1", ["-S", "--short",
|
@pytest.mark.parametrize("arg1", ["-S", "--short",
|
||||||
|
|
@ -257,6 +222,41 @@ def test_file_pattern_short(arg1):
|
||||||
assert os.path.isfile(new)
|
assert os.path.isfile(new)
|
||||||
os.remove(new)
|
os.remove(new)
|
||||||
|
|
||||||
|
@pytest.mark.files
|
||||||
|
@pytest.mark.withtime
|
||||||
|
@pytest.mark.parametrize("arg1", ["-w -f", "-w --files",
|
||||||
|
"--withtime -f", "--withtime --files",
|
||||||
|
"-w -m", "-w --mtime",
|
||||||
|
"--withtime -m", "--withtime --mtime",
|
||||||
|
"-w -c", "-w --ctime",
|
||||||
|
"--withtime -c", "--withtime --ctime"])
|
||||||
|
def test_file_pattern_withtime(arg1):
|
||||||
|
"""Prepend 'YYYY-MM-DDThh.mm.ss_' to the file name."""
|
||||||
|
prepare_testfile()
|
||||||
|
day = str("")
|
||||||
|
new = str("")
|
||||||
|
|
||||||
|
if arg1 in ["-w -f", "-w --files",
|
||||||
|
"--withtime -f", "--withtime --files",
|
||||||
|
"-w -m", "-w --mtime",
|
||||||
|
"--withtime -m", "--withtime --mtime"]:
|
||||||
|
day = query_modification_time().split()[0]
|
||||||
|
second = query_modification_time().split()[1]
|
||||||
|
|
||||||
|
elif arg1 in ["-w -c", "-w --ctime",
|
||||||
|
"--withtime -c", "--withtime --ctime"]:
|
||||||
|
day = query_creation_time().split()[0]
|
||||||
|
second = query_creation_time().split()[1]
|
||||||
|
|
||||||
|
second = second.split(".")[0] # use integer seconds only
|
||||||
|
second = second.replace(":", ".") # adjust representation
|
||||||
|
|
||||||
|
new = "".join([day, "T", second, "_", TFILE])
|
||||||
|
|
||||||
|
test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}")
|
||||||
|
assert os.path.isfile(new)
|
||||||
|
os.remove(new)
|
||||||
|
|
||||||
@pytest.mark.files
|
@pytest.mark.files
|
||||||
@pytest.mark.remove
|
@pytest.mark.remove
|
||||||
@pytest.mark.parametrize("arg1", ["default", "short", "compact",
|
@pytest.mark.parametrize("arg1", ["default", "short", "compact",
|
||||||
|
|
|
||||||
|
|
@ -115,11 +115,11 @@
|
||||||
files: tests about affect by date2name on files
|
files: tests about affect by date2name on files
|
||||||
folders: tests about affect by date2name on folders
|
folders: tests about affect by date2name on folders
|
||||||
|
|
||||||
default: stamp pattern default
|
default: stamp pattern default, YYYY-MM-DD
|
||||||
compact: stamp pattern compact
|
compact: stamp pattern compact, YYYYMMDD
|
||||||
month: stamp pattern month
|
month: stamp pattern month, YYYY-MM
|
||||||
withtime: stamp pattern withtime
|
short: stamp pattern short, YYMMDD
|
||||||
short: stamp pattern short
|
withtime: stamp pattern withtime, YYYY-MM-DDThh.mm.ss
|
||||||
remove: stamp retraction
|
remove: stamp retraction
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
@ -241,7 +241,7 @@
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
*** perform the tests on files [5/6]
|
*** perform the tests on files [6/6]
|
||||||
|
|
||||||
These tests check the addition of a time stamp ahead of the file name.
|
These tests check the addition of a time stamp ahead of the file name.
|
||||||
|
|
||||||
|
|
@ -270,9 +270,9 @@
|
||||||
os.remove(new)
|
os.remove(new)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
+ [X] prepend the day in the compact format YYYYMMDD_ to file test.txt
|
+ [X] compact pattern, i.e. prepend YYYYMMDD_ to file test.txt. This may
|
||||||
This may re-use much of the instructions used for the default pattern
|
re-use much of the instructions used for the default pattern and only
|
||||||
and only needs to drop the hyphens.
|
needs to drop the hyphens.
|
||||||
#+begin_src python :tangle test_date2name.py
|
#+begin_src python :tangle test_date2name.py
|
||||||
@pytest.mark.files
|
@pytest.mark.files
|
||||||
@pytest.mark.compact
|
@pytest.mark.compact
|
||||||
|
|
@ -309,7 +309,7 @@
|
||||||
os.remove(new)
|
os.remove(new)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
+ [X] Prepend year and month in the format YYYY-MM_ to file test.txt.
|
+ [X] month pattern, i.e. prepend YYYY-MM_ to file test.txt.
|
||||||
Departing from the standard format YYYY-MM-DD, it suffices to trim
|
Departing from the standard format YYYY-MM-DD, it suffices to trim
|
||||||
off the last three characters.
|
off the last three characters.
|
||||||
#+begin_src python :tangle test_date2name.py
|
#+begin_src python :tangle test_date2name.py
|
||||||
|
|
@ -348,48 +348,9 @@
|
||||||
os.remove(new)
|
os.remove(new)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
+ [X] To prepend date and time to file test.txt in a pattern of
|
+ [X] short pattern, i.e. preprend YYMMDD_ to file test.txt. A feature by
|
||||||
YYYY-MM-DDThh.mm.ss, the default pattern YYYY-MM-DD is extended.
|
Reiner Rottmann. Related to the basic pattern, except the two first
|
||||||
#+begin_src python :tangle test_date2name.py
|
characters are truncated.
|
||||||
@pytest.mark.files
|
|
||||||
@pytest.mark.withtime
|
|
||||||
@pytest.mark.parametrize("arg1", ["-w -f", "-w --files",
|
|
||||||
"--withtime -f", "--withtime --files",
|
|
||||||
"-w -m", "-w --mtime",
|
|
||||||
"--withtime -m", "--withtime --mtime",
|
|
||||||
"-w -c", "-w --ctime",
|
|
||||||
"--withtime -c", "--withtime --ctime"])
|
|
||||||
def test_file_pattern_withtime(arg1):
|
|
||||||
"""Prepend 'YYYY-MM-DDThh.mm.ss_' to the file name."""
|
|
||||||
prepare_testfile()
|
|
||||||
day = str("")
|
|
||||||
new = str("")
|
|
||||||
|
|
||||||
if arg1 in ["-w -f", "-w --files",
|
|
||||||
"--withtime -f", "--withtime --files",
|
|
||||||
"-w -m", "-w --mtime",
|
|
||||||
"--withtime -m", "--withtime --mtime"]:
|
|
||||||
day = query_modification_time().split()[0]
|
|
||||||
second = query_modification_time().split()[1]
|
|
||||||
|
|
||||||
elif arg1 in ["-w -c", "-w --ctime",
|
|
||||||
"--withtime -c", "--withtime --ctime"]:
|
|
||||||
day = query_creation_time().split()[0]
|
|
||||||
second = query_creation_time().split()[1]
|
|
||||||
|
|
||||||
second = second.split(".")[0] # use integer seconds only
|
|
||||||
second = second.replace(":", ".") # adjust representation
|
|
||||||
|
|
||||||
new = "".join([day, "T", second, "_", TFILE])
|
|
||||||
|
|
||||||
test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}")
|
|
||||||
assert os.path.isfile(new)
|
|
||||||
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
|
#+begin_src python :tangle test_date2name.py
|
||||||
@pytest.mark.files
|
@pytest.mark.files
|
||||||
@pytest.mark.short
|
@pytest.mark.short
|
||||||
|
|
@ -428,27 +389,66 @@
|
||||||
os.remove(new)
|
os.remove(new)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
+ [ ] Check the retraction of the date/time stamp
|
+ [X] withtime pattern, i.e. prepend YYYY-MM-DDThh.mm.ss_ to file test.txt.
|
||||||
|
This extends the default pattern YYYY-MM-DD.
|
||||||
|
#+begin_src python :tangle test_date2name.py
|
||||||
|
@pytest.mark.files
|
||||||
|
@pytest.mark.withtime
|
||||||
|
@pytest.mark.parametrize("arg1", ["-w -f", "-w --files",
|
||||||
|
"--withtime -f", "--withtime --files",
|
||||||
|
"-w -m", "-w --mtime",
|
||||||
|
"--withtime -m", "--withtime --mtime",
|
||||||
|
"-w -c", "-w --ctime",
|
||||||
|
"--withtime -c", "--withtime --ctime"])
|
||||||
|
def test_file_pattern_withtime(arg1):
|
||||||
|
"""Prepend 'YYYY-MM-DDThh.mm.ss_' to the file name."""
|
||||||
|
prepare_testfile()
|
||||||
|
day = str("")
|
||||||
|
new = str("")
|
||||||
|
|
||||||
The test is constrained to the five fix formats prepending the file name.
|
if arg1 in ["-w -f", "-w --files",
|
||||||
|
"--withtime -f", "--withtime --files",
|
||||||
|
"-w -m", "-w --mtime",
|
||||||
|
"--withtime -m", "--withtime --mtime"]:
|
||||||
|
day = query_modification_time().split()[0]
|
||||||
|
second = query_modification_time().split()[1]
|
||||||
|
|
||||||
/Not ready for inclusion into the main branch/ To trace the advancement of
|
elif arg1 in ["-w -c", "-w --ctime",
|
||||||
pytest's processing, long delays are set. A manual check of date2time on
|
"--withtime -c", "--withtime --ctime"]:
|
||||||
the CLI confirms that date2name writes the --withtime format, but is not
|
day = query_creation_time().split()[0]
|
||||||
successful to retract this stamp.
|
second = query_creation_time().split()[1]
|
||||||
|
|
||||||
|
second = second.split(".")[0] # use integer seconds only
|
||||||
|
second = second.replace(":", ".") # adjust representation
|
||||||
|
|
||||||
|
new = "".join([day, "T", second, "_", TFILE])
|
||||||
|
|
||||||
|
test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}")
|
||||||
|
assert os.path.isfile(new)
|
||||||
|
os.remove(new)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
+ [X] Check the retraction of the date/time stamp on files.
|
||||||
|
|
||||||
|
Based on a pattern comparison, a file like =20210921_test.txt= is renamed
|
||||||
|
=test.txt=. At present (Linux Debian 12/bookworm, branch testing),
|
||||||
|
date2name is known to struggle for files with the tag date2time prepended
|
||||||
|
by parameter =--withtime= (or =-w=). This is why the two corrsponding
|
||||||
|
tests fail.
|
||||||
|
|
||||||
#+begin_src python :tangle test_date2name.py
|
#+begin_src python :tangle test_date2name.py
|
||||||
@pytest.mark.files
|
@pytest.mark.files
|
||||||
@pytest.mark.remove
|
@pytest.mark.remove
|
||||||
@pytest.mark.parametrize("arg1", ["default", "short", "compact",
|
@pytest.mark.parametrize("arg1", ["default",
|
||||||
"month", "withtime"])
|
"compact", "month", "short",
|
||||||
|
"withtime"])
|
||||||
@pytest.mark.parametrize("arg2", ["-r", "--remove"])
|
@pytest.mark.parametrize("arg2", ["-r", "--remove"])
|
||||||
def test_file_remove_stamp(arg1, arg2):
|
def test_file_remove_stamp(arg1, arg2):
|
||||||
"""Check the retraction of the leading time stamp."""
|
"""Check the retraction of the leading time stamp."""
|
||||||
substitution = {"default" : "2021-09-21",
|
substitution = {"default" : "2021-09-21",
|
||||||
"short" : "210921",
|
|
||||||
"compact" : "20210921",
|
"compact" : "20210921",
|
||||||
"month" : "2021-09",
|
"month" : "2021-09",
|
||||||
|
"short" : "210921",
|
||||||
"withtime": "2021-09-21T13.59.59"}
|
"withtime": "2021-09-21T13.59.59"}
|
||||||
prepend = substitution.get(arg1)
|
prepend = substitution.get(arg1)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue