Commit graph

2 commits

Author SHA1 Message Date
Michael Vogt
9393211b8a testutil: tweak mock_command to write a call_log
Instead of just mocking the binary also write a log of the way
it got called so that tests can use this to check if the right
options are passed.

Note that the API should be improved here, instead of returning
a "naked" path to the calllog file there should be a class wrapping
it. And of course there should be tests.
2024-03-18 20:37:21 +01:00
Michael Vogt
7b5d6e4bd9 testutil: add new mock_command context manager
The new `testutil.mock_command` context manager can be used to
mock commands in PATH and replace them with arbitrary shell
scripts. This is useful in testing to e.g. simulate exact error
conditions that would be hard to trigger otherwise or to replace
long running commands with faked results.

Example:
```
fake_cmd = textwrap.dedent("""\
do-something
""")
with mock_command("some-cmd", fake_cmd):
   your_code
```
2024-02-12 17:41:21 -08:00