diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 16381af..a382739 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -17,6 +17,7 @@ jobs: - '3.12' - '3.13' - '3.14' + - '3.15.0-beta - 3.15.0' os: [ubuntu-latest] include: - python-version: '3.7' diff --git a/CHANGES.rst b/CHANGES.rst index bbab04c..26cabf7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,9 +10,10 @@ Changelog Internal -------- -+ `#26`_: add two more test cases. ++ `#26`_, `#27`_: review test suite. .. _#26: https://github.com/RKrahl/auto-patch/pull/26 +.. _#27: https://github.com/RKrahl/auto-patch/pull/27 .. _changes-1_2_0: diff --git a/tests/conftest.py b/tests/conftest.py index 761d903..5623778 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,9 +33,12 @@ class mock_subprocess_run: It fakes all invocations of the zypper binary. """ def __init__(self, results): + self.expected_calls = len(results) + self.calls = 0 self.results_iter = iter(results) def __call__(self, cmd, stdout=None, **kwargs): + self.calls += 1 zypp_res = next(self.results_iter) assert Path(cmd[0]).name == "zypper" args = zypper_arg_parser.parse_args(args=cmd[1:]) @@ -50,6 +53,9 @@ def __call__(self, cmd, stdout=None, **kwargs): stderr=zypp_res.stderr) return proc + def check_num_calls(self): + return self.calls == self.expected_calls + class mock_smtp(contextlib.AbstractContextManager): """A mock replacement for smtplib.SMTP. Instead of sending the mail, it pickles it to a well known file. @@ -69,12 +75,24 @@ def invoke_auto_patch(zypper_results): """Patch the current Python intepreter and execute auto-patch.py. This function is supposed to be the target of a Process. """ + import logging import subprocess import smtplib - subprocess.run = mock_subprocess_run(zypper_results) + import sys + mock_run = mock_subprocess_run(zypper_results) + subprocess.run = mock_run smtplib.SMTP = mock_smtp - with auto_patch_path.open("rt") as script: - exec(script.read(), dict(__name__="__main__")) + log = logging.getLogger(__name__) + with auto_patch_path.open("rt") as f: + auto_patch = f.read() + try: + exec(auto_patch, dict(__name__="__main__")) + except SystemExit: + if not mock_run.check_num_calls(): + log.critical("premature exit of auto-patch script") + sys.exit(-1) + else: + raise class ZypperResult: """Represent the result of one mock zypper call in AutoPatchCaller.