add minimal Emacs parameter block

To ensure e.g., coherent indentation of Python snippets tangled,
the explicit adjustment of Emacs' parameters is useful.  The .org
file now contains the block the previous commit omitted.  While
descriptions were edited, there is no functional change in the
files tangled.
This commit is contained in:
Norwid Behrnd 2022-01-03 16:53:31 +01:00
parent 6424dc6c2b
commit b92a5c23de
3 changed files with 104 additions and 65 deletions

View file

@ -13,10 +13,9 @@
# chmod +x * # chmod +x *
# make ./Makefile # make ./Makefile
# #
# to run the tests. The test sequence will explicitly report if a test # to run the tests. If you want pytest to exit the test sequence
# was passed successfully, or failed. If you want to script to stop on # right after the first test failing, use the -x flag to the
# the first encounter of a test failed, add option -x on the commands # instructions on the CLI in addition to the verbosity flag to (-v).
# set below
# pytest -v test_date2name.py # only pytest for Python 3 is present # pytest -v test_date2name.py # only pytest for Python 3 is present
pytest-3 -v test_date2name.py # pytest if Python 2 and Python 3 coexist pytest-3 -v test_date2name.py # pytest if Python 2 and Python 3 coexist

View file

@ -4,7 +4,7 @@
# author: nbehrnd@yahoo.com # author: nbehrnd@yahoo.com
# license: GPL v3, 2021. # license: GPL v3, 2021.
# date: 2021-08-30 (YYYY-MM-DD) # date: 2021-08-30 (YYYY-MM-DD)
# edit: 2021-12-30 (YYYY-MM-DD) # edit: 2022-01-03 (YYYY-MM-DD)
# #
"""Test pad for functions by date2name with pytest. """Test pad for functions by date2name with pytest.
@ -16,12 +16,14 @@ includes both legacy Python 2 and Python 3, pytest for Python 3 likely
is named pytest-3; otherwise only pytest. Thus, adjust your input on is named pytest-3; otherwise only pytest. Thus, adjust your input on
the CLI accordingly when running either one of the CLI accordingly when running either one of
pytest -xv test_date2name.py pytest -v test_date2name.py
pytest-3 -xv test_date2name.py pytest-3 -v test_date2name.py
The script either stops when one of the tests fail, or after completion These instruction initiate a verbose testing (flag -v) reported back to the CLI.re will be a verbose report to the CLI The script either stops when one of the tests fail (flag -x), or after
of the test sequence. In both cases, the progress of the ongoing tests completion of the test sequence. In both cases, the progress of the ongoing
is reported to the CLI.""" tests is reported to the CLI (flag -v).
"""
import os import os
import time import time
@ -467,7 +469,6 @@ def test_folder_remove_stamp(arg1, arg2, name=TFOLDER):
"withtime": "2021-09-21T13.59.59"} "withtime": "2021-09-21T13.59.59"}
prepend = substitution.get(arg1) prepend = substitution.get(arg1)
# os.mkdir(name)
BASIS = str(name) BASIS = str(name)
stamped_folder = "" stamped_folder = ""
stamped_folder = "_".join([prepend, BASIS]) stamped_folder = "_".join([prepend, BASIS])

View file

@ -1,6 +1,6 @@
#+NAME: test_generator.org #+NAME: test_generator.org
#+AUTHOR: nbehrnd@yahoo.com #+AUTHOR: nbehrnd@yahoo.com
#+DATE: 2021-12-30 (YYYY-MM-DD) #+DATE: 2022-01-03 (YYYY-MM-DD)
# License: GPL3, 2021. # License: GPL3, 2021.
#+PROPERTY: header-args :tangle yes #+PROPERTY: header-args :tangle yes
@ -8,19 +8,13 @@
* Intent * Intent
The application =date2name= by Karl Voit /et al./ ([[https://github.com/novoid/date2name][source)]] prepends date stamps The application =date2name= by Karl Voit /et al./ ([[https://github.com/novoid/date2name][source)]] prepends date
to files and folders (YYYY-MM-DD, YYYYMMDD, YYYY-MM, and YYYY-MM-DDThh.mm.ss). stamps to files and folders (e.g., rename file =example.txt= to
This Emacs .org file is used to prepare the automatic testing of the file =2021-12-30_example.txt=). By the command =C-c C-v t=, Emacs may use the
processing by [[https://docs.pytest.org/en/latest/][pytest]]. present =.org= file to (re)generate a tangled test script, file
=test_date2name.py= for a programmatic testing by [[https://docs.pytest.org/en/latest/][pytest]]. (Though =pytest= is
By the command =C-c C-v t=, this =.org= file may (re)generate the tangled test not part of the Python standard library, it may be obtained easily e.g., from
script, file =test_date2name.py= as well as a dedicated =Makefile= to ease the [[https://pypi.org/project/pytest/][PyPi]].) Optionally, the testing may be run by the equally tangled =Makefile=.
automated testing even further. =pytest= is not part of the Python standard
library, but may be obtained easily e.g., from [[https://pypi.org/project/pytest/][PyPi]].
It is advantageous to retain the options to run =pytest= in a =Makefile=,
which equally is included in this development e.g. to retain if an
instruction like =pytest -xv= or =pytest-3 -xv= is necessary (/vide infra/).
* Deployment * Deployment
@ -28,29 +22,82 @@
tests is either one of the following instructions (you might need to add the tests is either one of the following instructions (you might need to add the
executable bit): executable bit):
#+begin_src bash :tangle no
python pytest -v test_date2name.py python pytest -v test_date2name.py
./Makefile ./Makefile
#+end_src
In case the computer you use equally includes an installation of legacy 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 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 branch of the two. Depending on your OS, this requires an adjustment of the
command issue. In Linux Debian 12/bookworm, branch testing, for example, command issued. In Linux Debian 12/bookworm, branch testing, for example,
#+begin_src bash :tangle no
python3 pytest-3 -v test_date2name.py python3 pytest-3 -v test_date2name.py
#+end_src
or, after adjustment of the =Makefile= and provision of the executable bit * Setup of Emacs
./Makefile The edit of this =.org= file in Emacs and the subsequent export (tangle) of
the files are affected by Emacs' own parameters (e.g., the indentation in
Python). It is recommended to access this file with Emacs in a session
started by =emacs -q test_generator.org &= and to evaluate the following block
by =C-c C-c=; this explicitly adjusts a few basic settings, but does not
permanently overwrite an already existing personalized Emacs configuration.
See section about building a =pytest.ini= for additional options prepared. Most of these instructions are elements of Hendrik Suenkler's annotated Emacs
configuration ([[https://www.suenkler.info/notes/emacs-config/][blog post]]) which are reused with his 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)))
;; 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)
(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)
;; 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)
(column-number-mode nil)
(setq org-src-fontify-natively t)
#+end_src
#+RESULTS:
: t
If the previous block was evaluated as .TRUE. (=t=), test script and
Makefile may be tangled right now by =C-c C-t v=. After closing
this =.org= file, deploy them as indicated earlier.
* Building the tests * Building the tests
** Building of the Makefile ** Building of the Makefile
Set up for GNU Make 4.3, as provided from the repositories of Linux Debian 12 The setup is for GNU Make 4.3 as provided e.g., by Linux Debian 12
(bookworm), branch testing. (bookworm), branch testing. Note, the Makefile tangled is a mere convenient
moderator for =test_date2name.py=; the eventual testing of date2name's action
does not depend on this Makefile.
#+BEGIN_SRC makefile :tangle Makefile #+BEGIN_SRC makefile :tangle Makefile
# GNU Make file for the automation of pytest for date2name. # GNU Make file for the automation of pytest for date2name.
@ -68,10 +115,9 @@
# chmod +x * # chmod +x *
# make ./Makefile # make ./Makefile
# #
# to run the tests. The test sequence will explicitly report if a test # to run the tests. If you want pytest to exit the test sequence
# was passed successfully, or failed. If you want to script to stop on # right after the first test failing, use the -x flag to the
# the first encounter of a test failed, add option -x on the commands # instructions on the CLI in addition to the verbosity flag to (-v).
# set below
# pytest -v test_date2name.py # only pytest for Python 3 is present # pytest -v test_date2name.py # only pytest for Python 3 is present
pytest-3 -v test_date2name.py # pytest if Python 2 and Python 3 coexist pytest-3 -v test_date2name.py # pytest if Python 2 and Python 3 coexist
@ -79,23 +125,22 @@ pytest-3 -v test_date2name.py # pytest if Python 2 and Python 3 coexist
** Building a pytest.ini ** Building a pytest.ini
This file defines markers which groups the tests into groups. Subsequently, This file defines markers to assign tests into groups. This allows to run
tests with pytest may focus on them rather than performing all tests (which =pytest= on a subset rather than all tests (which is set up as the default).
is set up as the default). In presence of =pytest.ini=, the typical call E.g., in presence of =pytest.ini=, a call like
then is
#+begin_src bash :tangle no #+begin_src bash :tangle no
pytest-3 test_date2name.py -v -m "elementary" pytest-3 test_date2name.py -v -m "elementary"
#+end_src #+end_src
to constrain the tester's action to all tests labeled as "elementary". At constrains the tester's action to all tests labeled as "elementary". At
present, tests are grouped as present, tests are grouped as
+ elementary; ahead of checking date2name's action on files or folders + elementary; ahead of checking date2name's action on files or folders
+ files; checking date2name's action on files, and + files; checking date2name's action on files, and
+ folders; checking date2name's action on folders. + folders; checking date2name's action on folders
in a first layer. Orthogonal to this, the five fixed pattern (keyword in a first layer. Orthogonal to this, the five fixed pattern (keyword
=default=, =compact=, =month=, =withtime=, or =short=) and the stamps' =default=, =compact=, =month=, =withtime=, or =short=) and the stamps'
retraction (keyword =remove=) may be used as mutually exclusive levels, retraction (keyword =remove=) may be used as mutually exclusive levels --
either alone, or in combination with the keyword =files= or =folders=, e.g. either alone, or in combination with the keyword =files= or =folders=, e.g.
#+begin_src bash :tangle no #+begin_src bash :tangle no
@ -131,7 +176,7 @@ markers =
# author: nbehrnd@yahoo.com # author: nbehrnd@yahoo.com
# license: GPL v3, 2021. # license: GPL v3, 2021.
# date: 2021-08-30 (YYYY-MM-DD) # date: 2021-08-30 (YYYY-MM-DD)
# edit: 2021-12-30 (YYYY-MM-DD) # edit: 2022-01-03 (YYYY-MM-DD)
# #
"""Test pad for functions by date2name with pytest. """Test pad for functions by date2name with pytest.
@ -143,12 +188,14 @@ includes both legacy Python 2 and Python 3, pytest for Python 3 likely
is named pytest-3; otherwise only pytest. Thus, adjust your input on is named pytest-3; otherwise only pytest. Thus, adjust your input on
the CLI accordingly when running either one of the CLI accordingly when running either one of
pytest -xv test_date2name.py pytest -v test_date2name.py
pytest-3 -xv test_date2name.py pytest-3 -v test_date2name.py
The script either stops when one of the tests fail, or after completion These instruction initiate a verbose testing (flag -v) reported back to the CLI.re will be a verbose report to the CLI The script either stops when one of the tests fail (flag -x), or after
of the test sequence. In both cases, the progress of the ongoing tests completion of the test sequence. In both cases, the progress of the ongoing
is reported to the CLI.""" tests is reported to the CLI (flag -v).
"""
import os import os
import time import time
@ -202,7 +249,7 @@ def query_modification_time(name=TFILE):
*** set up very elementary tests *** set up very elementary tests
These tests do not modify a file, nor folder by =date2time=. These tests do not yet modify a file, nor folder which already exist.
#+begin_src python :tangle test_date2name.py #+begin_src python :tangle test_date2name.py
@pytest.mark.elementary @pytest.mark.elementary
@ -337,9 +384,9 @@ def test_file_pattern_month(arg1):
os.remove(new) os.remove(new)
#+end_src #+end_src
+ [X] short pattern, i.e. prepend YYMMDD_ to file test.txt. A feature by + [X] short pattern, i.e. prepend YYMMDD_ to file test.txt. A feature
Reiner Rottmann. Related to the basic pattern, except the two first introduced to date2name by Reiner Rottmann. Related to the basic pattern,
characters are truncated. except the two first characters are truncated.
#+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
@ -420,10 +467,7 @@ def test_file_pattern_withtime(arg1):
+ [X] Check the retraction of the date/time stamp on files. + [X] Check the retraction of the date/time stamp on files.
Based on a pattern comparison, a file like =20210921_test.txt= is renamed Based on a pattern comparison, a file like =20210921_test.txt= is renamed
=test.txt=. At present (Linux Debian 12/bookworm, branch testing), =test.txt=.
date2name is known to struggle for files with the tag date2time prepended
by parameter =--withtime= (or =-w=). This is why the two corresponding
tests fail.
#+begin_src python :tangle test_date2name.py #+begin_src python :tangle test_date2name.py
@pytest.mark.files @pytest.mark.files
@ -459,10 +503,10 @@ def test_file_remove_stamp(arg1, arg2):
*** perform the tests on folders [6/6] *** perform the tests on folders [6/6]
At present, most of the instructions already defined and used in section At present, most of the instructions already defined and used in section
"test on files" is repeated with small adjustments for checking date2name's "test on files" are repeated with small adjustments for checking date2name's
action on folders. While this approach isn't dry, given current experience, action on folders. This approach isn't dry; though, given current
it however is more reliable in eventual code execution running pytest, than experience, it however is more reliable in eventual code execution running
stacking the files/folders levels as an additional parameter. pytest, than stacking the files/folders levels as an additional parameter.
+ [X] default pattern, YYYY-MM-DD_ prepended + [X] default pattern, YYYY-MM-DD_ prepended
#+begin_src python :tangle test_date2name.py #+begin_src python :tangle test_date2name.py
@ -656,10 +700,6 @@ def test_file_pattern_withtime(arg1, name=TFOLDER):
+ [X] retraction of the date/time stamp + [X] retraction of the date/time stamp
Similar to the retraction of a prepended time stamp on files, the two
checks to remove a time stamp added by =--withtime= or =-w= currently fail
when running =pytest-3= on Linux Debian 12/bookworm, branch testing.
#+begin_src python :tangle test_date2name.py #+begin_src python :tangle test_date2name.py
@pytest.mark.folders @pytest.mark.folders
@pytest.mark.remove @pytest.mark.remove
@ -676,7 +716,6 @@ def test_folder_remove_stamp(arg1, arg2, name=TFOLDER):
"withtime": "2021-09-21T13.59.59"} "withtime": "2021-09-21T13.59.59"}
prepend = substitution.get(arg1) prepend = substitution.get(arg1)
# os.mkdir(name)
BASIS = str(name) BASIS = str(name)
stamped_folder = "" stamped_folder = ""
stamped_folder = "_".join([prepend, BASIS]) stamped_folder = "_".join([prepend, BASIS])