From 49254c4429670559332207b7308cf9617610a418 Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Sun, 9 Jan 2022 10:54:05 +0100 Subject: [PATCH 1/4] clarify the call sign issue of pytest Depending on the installation/Linux distribution used, pytest for Python 3 may be invoked by either pytest, or pytest-3. The issue is addressed. --- Makefile | 18 ++++----- test_generator.org | 94 +++++++++++++++++++++++----------------------- 2 files changed, 56 insertions(+), 56 deletions(-) mode change 100644 => 100755 Makefile diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index d49ed8d..299aff7 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ -# GNU Make file for the automation of pytest for appendfilename. +# GNU Make file for the automation of pytest for appendfilename # -# While the test script is written for Python 3.9.2, you might need to -# adjust the following instruction once in case your OS includes -# pytest for legacy Python 2 side by side to Python 3, or only hosts -# pytest for Python 3. The tests in script test_appendfilename.py are -# set up to work with pytest for Python 3; dependent on your -# installation, which may be named pytest-3, or (again) pytest. +# While the test script is written for Python 3.9.2, it depends on +# your installation of pytest (and in case of Linux, the authors of +# your distribution) if pytest for Python 3 is invoked either by +# pytest, or pytest-3. In some distributions, pytest actually may +# invoke pyest for legacy Python 2; the tests in test_date2name.py +# however are incompatible to this. # # Put this file like test_appendfilename.py in the root folder of # appendfilename fetched from PyPi or GitHub. Then run @@ -17,5 +17,5 @@ # right after the first test failing, use the -x flag to the # instructions on the CLI in addition to the verbosity flag to (-v). -# pytest -v test_appendfilename.py # only pytest for Python 3 is present -pytest-3 -v test_appendfilename.py # pytest if Python 2 and Python 3 coexist +# pytest -v test_appendfilename.py # the pattern by pytest's manual +pytest-3 -v test_appendfilename.py # the alternative pattern (e.g., Debian 12) diff --git a/test_generator.org b/test_generator.org index 148bb1e..a5931ea 100755 --- a/test_generator.org +++ b/test_generator.org @@ -1,7 +1,7 @@ # name: test_generator.org # author: nbehrnd@yahoo.com # date: 2022-01-05 (YYYY-MM-DD) -# edit: 2022-01-06 (YYYY-MM-DD) +# edit: 2022-01-09 (YYYY-MM-DD) # license: GPL3, 2022. # Export the tangled files with C-c C-v t @@ -22,24 +22,24 @@ * Deployment - On a computer with Python 3 only, the recommended call on the CLI to - run the tests is either one of the following instructions (you might - need to add the executable bit): + The programmatic tests are set up for pytest for Python 3. It + however depends on your installation (and in case of Linux, the + authors of your Linux distribution ([[https://github.com/pytest-dev/pytest/discussions/9481][reference]])) if this utility may + be started by =pytest= (e.g., the pattern in pytest's manual), or by + =pytest-3= by either one of the pattern below: #+begin_src bash :tangle no - python pytest -v test_appendfilename.py - ./Makefile +pytest -v test_appendfilename.py +pytest-3 -v test_appendfilename.py #+end_src - In case the computer you use equally includes an installation of - legacy Python 2 side-by-side to Python 3, you must explicitly call - for the later branch of the two. Depending on your OS, this - requires an adjustment of the command issued. In Linux Debian - 12/bookworm, branch testing, for example, + As of writing, the later pattern is the to be used e.g., in Linux + Debian 12/bookworm (branch testing) to discern pytest (for + contemporary Python 3) from pytest (for legacy Python 2). - #+begin_src bash :tangle no - python3 pytest-3 -v test_appendfilename.py - #+end_src + The =Makefile= this =org= file provides for convenience running + these tests assumes the later syntax pattern. (It might be + necessary to provide the executable bit to activate the Makefile.) * Setup of Emacs @@ -56,38 +56,38 @@ permission. #+begin_src emacs-lisp :tangle no -;; support these languages at all: -(org-babel-do-load-languages - 'org-babel-load-languages - '((emacs-lisp . t) - (org . t) - (shell . t) - (python . t))) + ;; support these languages at all: + (org-babel-do-load-languages + 'org-babel-load-languages + '((emacs-lisp . t) + (org . t) + (shell . t) + (python . t))) -;; enable syntax highlighting: -(setq org-src-fontify-natively t) + ;; enable syntax highlighting: + (setq org-src-fontify-natively t) -;; adjust indentations, set tabs as explicit 4 spaces: -(setq-default indent-tabs-mode nil) -(setq default-tab-width 4) + ;; adjust indentations, set tabs as explicit 4 spaces: + (setq-default indent-tabs-mode nil) + (setq default-tab-width 4) -(setq custom-tab-width 4) -(setq-default python-indent-offset custom-tab-width) + (setq custom-tab-width 4) + (setq-default python-indent-offset custom-tab-width) -(setq org-edit-src-content-indentation 0) -(setq org-src-tab-acts-natively t) -(setq org-src-preserve-indentation t) + (setq org-edit-src-content-indentation 0) + (setq org-src-tab-acts-natively t) + (setq org-src-preserve-indentation t) -;; some comfort functions Suenkler mentions: -(delete-selection-mode 1) -(defalias 'yes-or-no-p 'y-or-n-p) + ;; some comfort functions Suenkler mentions: + (delete-selection-mode 1) + (defalias 'yes-or-no-p 'y-or-n-p) -(show-paren-mode 1) -(setq show-paren-style 'parenthesis) + (show-paren-mode 1) + (setq show-paren-style 'parenthesis) -(column-number-mode nil) + (column-number-mode nil) -(setq org-src-fontify-natively t) + (setq org-src-fontify-natively t) #+end_src #+RESULTS: @@ -108,14 +108,14 @@ Makefile. #+BEGIN_SRC makefile :tangle Makefile -# GNU Make file for the automation of pytest for appendfilename. +# GNU Make file for the automation of pytest for appendfilename # -# While the test script is written for Python 3.9.2, you might need to -# adjust the following instruction once in case your OS includes -# pytest for legacy Python 2 side by side to Python 3, or only hosts -# pytest for Python 3. The tests in script test_appendfilename.py are -# set up to work with pytest for Python 3; dependent on your -# installation, which may be named pytest-3, or (again) pytest. +# While the test script is written for Python 3.9.2, it depends on +# your installation of pytest (and in case of Linux, the authors of +# your distribution) if pytest for Python 3 is invoked either by +# pytest, or pytest-3. In some distributions, pytest actually may +# invoke pyest for legacy Python 2; the tests in test_date2name.py +# however are incompatible to this. # # Put this file like test_appendfilename.py in the root folder of # appendfilename fetched from PyPi or GitHub. Then run @@ -127,8 +127,8 @@ # right after the first test failing, use the -x flag to the # instructions on the CLI in addition to the verbosity flag to (-v). -# pytest -v test_appendfilename.py # only pytest for Python 3 is present -pytest-3 -v test_appendfilename.py # pytest if Python 2 and Python 3 coexist +# pytest -v test_appendfilename.py # the pattern by pytest's manual +pytest-3 -v test_appendfilename.py # the alternative pattern (e.g., Debian 12) #+end_src ** Building a pytest.ini From 903b6adbe0ba64a081a5364383130d75df3c9007 Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Sun, 9 Jan 2022 11:08:56 +0100 Subject: [PATCH 2/4] extend pattern timestamps by date2name, 1/2 This extends the pattern tested to consider all five stamp formats issued by date2name when passing appendfilename either in default, or prepend mode. It doesn't yet the --smart-prepend mode as third option. --- Makefile | 0 test_appendfilename.py | 10 +++++++--- test_generator.org | 10 +++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) mode change 100755 => 100644 Makefile diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 diff --git a/test_appendfilename.py b/test_appendfilename.py index 994ede4..a26df1d 100644 --- a/test_appendfilename.py +++ b/test_appendfilename.py @@ -4,7 +4,7 @@ # author: nbehrnd@yahoo.com # license: GPL v3, 2022. # date: 2022-01-05 (YYYY-MM-DD) -# edit: 2022-01-07 (YYYY-MM-DD) +# edit: 2022-01-09 (YYYY-MM-DD) # """Test pad for functions by appendfilename with pytest. @@ -34,7 +34,9 @@ @pytest.mark.default @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", "2012-12_test.txt", + "211231_test.txt"]) @pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf", "--text book", "--text book_shelf"]) @pytest.mark.parametrize("arg3", [" ", "!", "@", "#", "$", "%", "*", "_", "+", @@ -63,7 +65,9 @@ def test_pattern_s1(arg1, arg2, arg3): @pytest.mark.prepend @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", "2012-12_test.txt", + "211231_test.txt"]) @pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf", "--text book", "--text book_shelf"]) @pytest.mark.parametrize("arg3", [" ", "!", "@", "#", "$", "%", "*", "_", "+", diff --git a/test_generator.org b/test_generator.org index a5931ea..ea09f3a 100755 --- a/test_generator.org +++ b/test_generator.org @@ -175,7 +175,7 @@ markers = # author: nbehrnd@yahoo.com # license: GPL v3, 2022. # date: 2022-01-05 (YYYY-MM-DD) -# edit: 2022-01-07 (YYYY-MM-DD) +# edit: 2022-01-09 (YYYY-MM-DD) # """Test pad for functions by appendfilename with pytest. @@ -213,7 +213,9 @@ PROGRAM = str("./appendfilename/__init__.py") #+begin_src python :tangle test_appendfilename.py @pytest.mark.default @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", "2012-12_test.txt", + "211231_test.txt"]) @pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf", "--text book", "--text book_shelf"]) @pytest.mark.parametrize("arg3", [" ", "!", "@", "#", "$", "%", "*", "_", "+", @@ -251,7 +253,9 @@ def test_pattern_s1(arg1, arg2, arg3): #+begin_src python :tangle test_appendfilename.py @pytest.mark.prepend @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", "2012-12_test.txt", + "211231_test.txt"]) @pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf", "--text book", "--text book_shelf"]) @pytest.mark.parametrize("arg3", [" ", "!", "@", "#", "$", "%", "*", "_", "+", From c44d7070c43f48865db25fff0547835472abd172 Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Sun, 9 Jan 2022 11:25:06 +0100 Subject: [PATCH 3/4] reorganize test section --smart-prepend for extension Ahead of the addition of checks about three stamp pattern issued by date2name, the checker about appendfilename's the option --smart-prepent is reorganized to be more compact/easier to be read. For now, this outweights each filename being checked twice. --- test_appendfilename.py | 40 +++++++++++++++++----------------------- test_generator.org | 40 +++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/test_appendfilename.py b/test_appendfilename.py index a26df1d..5852c55 100644 --- a/test_appendfilename.py +++ b/test_appendfilename.py @@ -122,29 +122,23 @@ def test_pattern_s3_02(arg1, arg2, arg3): # analysis section: old_filename = str(arg1) - if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): - # if (running date2name in default mode) then .true. - time_stamp = old_filename[:10] - time_stamp_separator = old_filename[10] - file_extension = old_filename.split(".")[-1] - - old_filename_no_timestamp = old_filename[11:] - stem_elements = old_filename_no_timestamp.split(".")[:-1] - stem = ".".join(stem_elements) - - new_filename = "".join([time_stamp, arg3, text, arg3, stem, str("."), file_extension]) - assert os.path.isfile(new_filename) - - os.remove(new_filename) - assert os.path.isfile(new_filename) is False - - 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:] + 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)): + + if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): + # if (running date2name in default mode) then .true. + time_stamp = old_filename[:10] + 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:] + stem_elements = old_filename_no_timestamp.split(".")[:-1] stem = ".".join(stem_elements) diff --git a/test_generator.org b/test_generator.org index ea09f3a..5d7f4fb 100755 --- a/test_generator.org +++ b/test_generator.org @@ -319,29 +319,23 @@ def test_pattern_s3_02(arg1, arg2, arg3): # analysis section: old_filename = str(arg1) - if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): - # if (running date2name in default mode) then .true. - time_stamp = old_filename[:10] - time_stamp_separator = old_filename[10] - file_extension = old_filename.split(".")[-1] - - old_filename_no_timestamp = old_filename[11:] - stem_elements = old_filename_no_timestamp.split(".")[:-1] - stem = ".".join(stem_elements) - - new_filename = "".join([time_stamp, arg3, text, arg3, stem, str("."), file_extension]) - assert os.path.isfile(new_filename) - - os.remove(new_filename) - assert os.path.isfile(new_filename) is False - - 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:] + 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)): + + if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): + # if (running date2name in default mode) then .true. + time_stamp = old_filename[:10] + 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:] + stem_elements = old_filename_no_timestamp.split(".")[:-1] stem = ".".join(stem_elements) From a282a32a0e7ce77cf368d52eb598f0424d419934 Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Sun, 9 Jan 2022 13:14:02 +0100 Subject: [PATCH 4/4] extend patten timestamps by date2name, 2/2 Addition of the pattern --compact, --month, and --short. --- test_appendfilename.py | 41 ++++++++++++++++++++++++++++++++++++----- test_generator.org | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 10 deletions(-) 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)