Defining expectations

Version 0.2.0 Updated Nov 27, 2025

Combine methods to describe how a command should be invoked:

cmd_mox.mock("git") \
    .with_args("clone", "https://example.com/repo.git") \
    .returns(exit_code=0)

You can match arguments more flexibly using comparators:

from cmd_mox import Regex, Contains

cmd_mox.mock("curl") \
    .with_matching_args(Regex(r"--header=User-Agent:.*"), Contains("example"))

The design document lists the available comparators:

  • Any
  • IsA
  • Regex
  • Contains
  • StartsWith
  • Predicate

Each comparator is a callable that returns True on match. with_matching_args expects one comparator per argv element (excluding the program name, i.e., argv[1:]), and with_stdin accepts either an exact string or a predicate Callable[[str], bool] for flexible input checks.