cmd-mox package
Project description
🕵️♀️ CmdMox – Python-native command mocking so you never have to write another shell test again
Replace your flaky bats tests, your brittle log-parsing hacks, and that one Bash script that only works on Tuesdays. CmdMox intercepts external commands with Python shims, speaks fluent IPC over Unix domain sockets, and enforces your expectations like a disappointed parent.
- Mocks? Verified.
- Stubs? Quietly compliant.
- Spies? Judging everything you do.
Designed for pytest, built for people who’ve seen things—like ksh93 unit test
harnesses and AIX cronjobs running sccs.
If you've ever mocked curl with cat, this library is your penance.
For detailed instructions, see docs/usage-guide.md.
✅ Requirements
- Python 3.11 or newer (to leverage modern enum.StrEnum support)
🧪 Example: Testing a command-line script with CmdMox
Let’s say your script under test calls git clone and curl. You want to test
it without actually cloning anything because you value your bandwidth and
your sanity.
# test_my_script.py
def test_clone_and_fetch(cmd_mox):
# Define expectations (fixture auto-enters REPLAY before the test body)
cmd_mox.mock("git") \
.with_args("clone", "https://a.b/c.git") \
.returns(exit_code=0)
cmd_mox.mock("curl") \
.with_args("-s", "https://a.b/c/info.json") \
.returns(stdout='{"status":"ok"}')
# Code under test runs with mocked git and curl
result = my_tool.clone_and_fetch("https://a.b/c.git")
# Assert your code didn’t mess it up
assert result.status == "ok"
# Verification happens automatically during pytest teardown.
When it passes: your mocks were used exactly as expected.
When it fails: you'll get a surgically precise diff of what was expected vs what your misbehaving code actually did.
No subshells. No flaky greps. Just clean, high-fidelity, Pythonic command mocking.
🧯 Scope (and what’s gloriously out of it)
CmdMox is for mocking commands—not re-enacting bash(1) interpretive
dance theatre.
Out of scope (for now, or forever):
-
🧞 Shell function mocking – you want
eval, you wait a year. Or just don’t. -
🪟 Windows support – maybe one day. Until then: enjoy your
.batfiles and pray toCreateProcess(). -
🦕 Legacy UNIX support – AIX, Solaris, IRIX? Sorry boys, the boat sailed, caught fire, and sank in 2003.
-
🧩 Builtin mocking –
cd,exec,trap? No. Just no. -
🧪 Calling commands under test – use
subprocess,plumbum, or whatever black magic suits your taste. CmdMox doesn't care how you run them—as long as you run them like you mean it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cmd_mox-0.1.0.tar.gz.
File metadata
- Download URL: cmd_mox-0.1.0.tar.gz
- Upload date:
- Size: 96.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2e359207b03953d2a5d0dcbeed11bcf34d1cab6b34f6e54092d5d30a77f2754
|
|
| MD5 |
bcd80df76eba8fd5dfd61ae8e2ce6223
|
|
| BLAKE2b-256 |
1b98e0e1102c5a9f7d5268d9e9f9b82ae4467598d30a4f444a19a16d752efb40
|
File details
Details for the file cmd_mox-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cmd_mox-0.1.0-py3-none-any.whl
- Upload date:
- Size: 125.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8497c181bd9e5c93069c86419b35bf433f932c40832450b654ba0e2a97018acb
|
|
| MD5 |
27e26f9cba2995e349ce3d1b8e959f6e
|
|
| BLAKE2b-256 |
c3706544c48be2b4fad4e2fd8cd20742c2d1933b21eb3c6c764158250738cd6b
|