Add Python regression tests; eliminate shell portability workarounds#1438
Open
ecrist wants to merge 1 commit intofix/bugs-and-efficiencyfrom
Open
Add Python regression tests; eliminate shell portability workarounds#1438ecrist wants to merge 1 commit intofix/bugs-and-efficiencyfrom
ecrist wants to merge 1 commit intofix/bugs-and-efficiencyfrom
Conversation
unit-tests-pr1436.py reimplements the same seven regression tests
using Python 3 stdlib only (no third-party packages). Python's
native primitives eliminate every portability workaround that the
shell version required:
subprocess.run(stdin=DEVNULL, timeout=10)
FIX-1's EOF/infinite-loop test becomes a single call.
TimeoutExpired is a typed exception — no background processes,
no signal juggling, no SECONDS busy-wait, no platform ifdefs.
subprocess.run() kills the child process automatically when the
timeout fires, on every platform including Windows.
tempfile.mkdtemp()
Returns a writable temp directory on every OS using the platform's
native temp mechanism (TMPDIR on Unix, TEMP/TMP on Windows).
No mkdir, no /tmp hard-coding, no fallback chain needed.
shutil.rmtree()
Portable recursive directory removal — no rm.exe dependency.
pathlib.Path / Path.glob() / Path.iterdir()
Path manipulation and directory listing without ls, find, or
any external tool.
path.write_text() / path.read_text()
File I/O without cat or redirected printf.
_easyrsa_cmd() detects Windows (sys.platform == 'win32') and
prepends 'sh' to the easyrsa invocation, because the Windows
kernel does not process POSIX shebangs.
op-test.sh: run_local_regression_tests() now prefers the Python
version and falls back to the shell version only if Python 3 is
absent. The Python executable is detected by probing 'python3'
then 'python' and checking that the reported version starts with
'Python 3'.
The shell version (unit-tests-pr1436.sh) is retained as the fallback
and remains the correct choice for environments without Python (e.g.
minimal embedded Linux, some CI images).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
unit-tests-pr1436.py— a Python 3 rewrite of the PR #1436 regression suite that requires no external binaries other thaneasyrsaandopenssl.Updates
op-test.shto prefer the Python version and fall back to the shell version only when Python 3 is unavailable.Motivation
The original shell test script (
unit-tests-pr1436.sh) had to work around the absence of standard POSIX utilities on Windows, where the EasyRSA distribution ships outdated GNU-for-Windows binaries. PR #1437 rewrote the shell script to avoid those tools using shell built-ins.Python removes the problem entirely:
catnot reliablewhile IFS= read -rlooppath.read_text()lsnot reliableforlooppath.glob()/path.iterdir()sleepabsent on Windows$SECONDSbusy-wait or SKIPsubprocess.run(timeout=N)— kills automatically/tmpabsent on WindowsTMPDIR/TEMP/TMP/CWDchaintempfile.mkdtemp()mkdir -pflag issuestempfile.mkdtemp()rm -rfmay be absentshutil.rmtree(ignore_errors=True)_easyrsa_cmd()prependsshonwin32Design
unit-tests-pr1436.py— stdlib only, Python ≥ 3.6:The seven tests map 1-to-1 with the shell version:
FIX-1-passphrase-eof-exitssubprocess.run(stdin=DEVNULL, timeout=10)raisesTimeoutExpiredif the process hangs — no background jobs, no signalsFIX-2a/b/c/dset_var validationpath.write_text()writes vars files;subprocess.run()checks exit codeFIX-3passphrase comparisonFIX-4mktemp namingPath.glob("temp.*")replaces thels+ for-loop in shellop-test.sh—run_local_regression_tests()updated:python3thenpython, verify version starts withPython 3.pyfile present: run Python version.shversion-v/-vvop-test verb flags to Python's-vCompatibility
.py.py.py.shfallback.shfallbackTest plan
python3 unit-tests-pr1436.py -v— 7 PASS on macOS/Linuxpython3 unit-tests-pr1436.py version— prints version string, exits 0sh op-test.sh -v— confirm Python path is taken, 7 PASS in logpython3from PATH temporarily, runsh op-test.sh -v— confirm fallback to.shis loggedwop-test.bat→op-test.sh→ Python tests pass🤖 Generated with Claude Code