Skip to main content

Cli Mock

See Build Status on Travis CI

This package provides two command line utilities: crecord and creplay. The former records the output (stdout and stderr) and the return code of a command and the latter replays the command invocation by reproducing its output and return code:

$ crecord echo foo
foo
$ creplay echo foo
foo
$ crecord ls foo
ls: foo: No such file or directory
$ creplay ls foo
ls: foo: No such file or directory
$ echo $?
1

This could be used to mock slow and environment-dependent command invocations for testing purposes.

Pytest plugin

There’s also a pytest plugin contained in cli_mock package. It exposes popen_controller fixture that can be used to replay crecord logs in response to subprocess.Popen invocations (and the APIs that call it under the hood):

def test_foo(popen_controller):
    popen_controller.set_replay_log(my_log)
    output = subprocess.check_output(['foo'])
    assert output == b'bar\n'

After the replay log is activated calls to subprocess.Popen and friends with the commands that are contained in the log will replay from the log. Commands that are not in the log will trigger an AssertionError.

Non-strict mode

It’s possible to allow executing commands that are not in the log via activating non-strict mode:

popen_controller.set_strict(False)

or:

popen_controller.set_replay_log(my_log, strict=False)

In non-strict mode any command that is not in the log will be passed to subprocess.Popen without modifications and will be executed in a usual fashion.

Metadata

Release files for cli-mock 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cli-mock 0.2.1
File Size Uploaded Provenance Actions
cli_mock-0.2.1.tar.gz 4.6 kB Without provenance Details for cli_mock-0.2.1.tar.gz

Release files / cli_mock-0.2.1.tar.gz

Download URL cli_mock-0.2.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c4ba87df89d33d1dda4f0bb5b333e41145cf059a273671a904994cf43afe7dae
BLAKE2b-256 checksum
How to use checksums
1f119cbb545a26674adb8c69dcef10c056873b43cfdda367838f3c20fd317ad0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for cli-mock 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page