diff --git a/test_appendfilename.py b/test_appendfilename.py index 5852c55..9f8f99f 100644 --- a/test_appendfilename.py +++ b/test_appendfilename.py @@ -98,7 +98,8 @@ def test_pattern_s2(arg1, arg2, arg3, arg4): @pytest.mark.smart @pytest.mark.parametrize("arg1", ["test.txt", "2021-12-31_test.txt", - "2021-12-31T18.48.22_test.txt"]) + "2021-12-31T18.48.22_test.txt", "20211231_test.txt", + "2021-12_test.txt", "211231_test.txt"]) @pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf", "--text book", "--text book_shelf"]) @pytest.mark.parametrize("arg3", [" " , "#", "!", "@", "#", "$", "%", "*", "_", "+", @@ -118,12 +119,21 @@ def test_pattern_s3_02(arg1, arg2, arg3): newfile.write("This is a test file for test_appendfilename.") test = getoutput(f"python3 {PROGRAM} {arg1} {arg2} --separator={arg3} --smart-prepend") - + # analysis section: old_filename = str(arg1) + # test pattern issued by date2name vs. other pattern + # default (YYYY-MM-DD) + # --withtime (YYYY-MM-DDTHH.MM.SS) + # --compact (YYYYMMDD) + # --month (YYYY-MM) + # --short (YYMMDD) if (re.search("^\d{4}-[012]\d-[0-3]\d_", old_filename) or - re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename)): + re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename) or + re.search("^\d{4}[012]\d[0-3]\d_", old_filename) or + re.search("^\d{4}-[012]\d_", old_filename) or + re.search("^\d{2}[012]\d[0-3]\d_", old_filename)): if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): # if (running date2name in default mode) then .true. @@ -131,14 +141,35 @@ def test_pattern_s3_02(arg1, arg2, arg3): time_stamp_separator = old_filename[10] file_extension = old_filename.split(".")[-1] old_filename_no_timestamp = old_filename[11:] - + elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename): # if (running date2name --withtime) then .true. time_stamp = old_filename[:19] time_stamp_separator = old_filename[19] file_extension = old_filename.split(".")[-1] old_filename_no_timestamp = old_filename[20:] - + + elif re.search("^\d{4}\d{2}\d{2}_", old_filename): + # if (running date2name --compact) then .true. + time_stamp = old_filename[:8] + time_stamp_separator = old_filename[8] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[9:] + + elif re.search("^\d{4}-\d{2}_", old_filename): + # if (running date2name --month) then .true. + time_stamp = old_filename[:7] + time_stamp_separator = old_filename[7] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[8:] + + elif re.search("^\d{4}\d{2}\d{2}_", old_filename): + # if (running date2name --short) then .true. + time_stamp = old_filename[:6] + time_stamp_separator = old_filename[6] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[7:] + stem_elements = old_filename_no_timestamp.split(".")[:-1] stem = ".".join(stem_elements) diff --git a/test_generator.org b/test_generator.org index 5d7f4fb..4fad241 100755 --- a/test_generator.org +++ b/test_generator.org @@ -295,7 +295,8 @@ def test_pattern_s2(arg1, arg2, arg3, arg4): #+begin_src python :tangle test_appendfilename.py @pytest.mark.smart @pytest.mark.parametrize("arg1", ["test.txt", "2021-12-31_test.txt", - "2021-12-31T18.48.22_test.txt"]) + "2021-12-31T18.48.22_test.txt", "20211231_test.txt", + "2021-12_test.txt", "211231_test.txt"]) @pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf", "--text book", "--text book_shelf"]) @pytest.mark.parametrize("arg3", [" " , "#", "!", "@", "#", "$", "%", "*", "_", "+", @@ -315,12 +316,21 @@ def test_pattern_s3_02(arg1, arg2, arg3): newfile.write("This is a test file for test_appendfilename.") test = getoutput(f"python3 {PROGRAM} {arg1} {arg2} --separator={arg3} --smart-prepend") - + # analysis section: old_filename = str(arg1) + # test pattern issued by date2name vs. other pattern + # default (YYYY-MM-DD) + # --withtime (YYYY-MM-DDTHH.MM.SS) + # --compact (YYYYMMDD) + # --month (YYYY-MM) + # --short (YYMMDD) if (re.search("^\d{4}-[012]\d-[0-3]\d_", old_filename) or - re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename)): + re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename) or + re.search("^\d{4}[012]\d[0-3]\d_", old_filename) or + re.search("^\d{4}-[012]\d_", old_filename) or + re.search("^\d{2}[012]\d[0-3]\d_", old_filename)): if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): # if (running date2name in default mode) then .true. @@ -328,14 +338,35 @@ def test_pattern_s3_02(arg1, arg2, arg3): time_stamp_separator = old_filename[10] file_extension = old_filename.split(".")[-1] old_filename_no_timestamp = old_filename[11:] - + elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename): # if (running date2name --withtime) then .true. time_stamp = old_filename[:19] time_stamp_separator = old_filename[19] file_extension = old_filename.split(".")[-1] old_filename_no_timestamp = old_filename[20:] - + + elif re.search("^\d{4}\d{2}\d{2}_", old_filename): + # if (running date2name --compact) then .true. + time_stamp = old_filename[:8] + time_stamp_separator = old_filename[8] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[9:] + + elif re.search("^\d{4}-\d{2}_", old_filename): + # if (running date2name --month) then .true. + time_stamp = old_filename[:7] + time_stamp_separator = old_filename[7] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[8:] + + elif re.search("^\d{4}\d{2}\d{2}_", old_filename): + # if (running date2name --short) then .true. + time_stamp = old_filename[:6] + time_stamp_separator = old_filename[6] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[7:] + stem_elements = old_filename_no_timestamp.split(".")[:-1] stem = ".".join(stem_elements)