MCPcopy Index your code
hub / github.com/pyinvoke/invoke / expect

Function expect

tests/_util.py:75–107  ·  view source on GitHub ↗

Run ``invocation`` via ``program`` and expect resulting output to match. May give one or both of ``out``/``err`` (but not neither). ``program`` defaults to ``Program()``. To skip automatically assuming the argv under test starts with ``"invoke "``, say ``invoke=False``.

(
    invocation, out=None, err=None, program=None, invoke=True, test=None
)

Source from the content-addressed store, hash-verified

73
74
75def expect(
76 invocation, out=None, err=None, program=None, invoke=True, test=None
77):
78 """
79 Run ``invocation`` via ``program`` and expect resulting output to match.
80
81 May give one or both of ``out``/``err`` (but not neither).
82
83 ``program`` defaults to ``Program()``.
84
85 To skip automatically assuming the argv under test starts with ``"invoke
86 "``, say ``invoke=False``.
87
88 To customize the operator used for testing (default: equality), use
89 ``test`` (which should be an assertion wrapper of some kind).
90 """
91 stdout, stderr = run(invocation, program, invoke)
92 # Perform tests
93 if out is not None:
94 if test:
95 test(stdout, out)
96 else:
97 assert out == stdout
98 if err is not None:
99 if test:
100 test(stderr, err)
101 else:
102 assert err == stderr
103 # Guard against silent failures; since we say exit=False this is the only
104 # real way to tell if stuff died in a manner we didn't expect.
105 elif stderr:
106 assert False, "Unexpected stderr: {}".format(stderr)
107 return stdout, stderr
108
109
110class MockSubprocess:

Calls 2

runFunction · 0.70
testFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…