inkex.tester.mock module#
Any mocking utilities required by testing. Mocking is when you need the test to exercise a piece of code, but that code may or does call on something outside of the target code that either takes too long to run, isn’t available during the test running process or simply shouldn’t be running at all.
- class inkex.tester.mock.Capture(io_name='stdout', swap=True)[source]#
Bases:
object
Capture stdout or stderr. Used as with Capture(‘stdout’) as stream:
- class inkex.tester.mock.ManualVerbosity(test, okay=True, dots=False)[source]#
Bases:
object
Change the verbosity of the test suite manually
- property result#
- class inkex.tester.mock.MockMixin[source]#
Bases:
object
Add mocking ability to any test base class, will set up mock on setUp and remove it on tearDown.
Mocks are stored in an array attached to the test class (not instance!) which ensures that mocks can only ever be setUp once and can never be reset over themselves. (just in case this looks weird at first glance)
- class SomeTest(MockingMixin, TestBase):
mocks = [(sys, ‘exit’, NoSystemExit(“Nope!”)]
- mocks: List[Tuple[Any, str, Any]] = []#
- class inkex.tester.mock.MockCommandMixin[source]#
Bases:
inkex.tester.mock.MockMixin
Replace all the command functions with testable replacements.
This stops the pipeline and people without the programs, running into problems.
- mocks: List[Tuple[Any, str, Any]] = [(<module 'inkex.command' from '/builds/inkscape/extensions/inkex/command.py'>, '_call', 'mock_call'), (<module 'tempfile' from '/.pyenv/versions/3.11.0/lib/python3.11/tempfile.py'>, 'mkdtemp', 'record_tempdir')]#
- recorded_tempdirs: List[str] = []#
- mock_call(program, *args, **kwargs)[source]#
Replacement for the inkex.command.call() function, instead of calling an external program, will compile all arguments into a hash and use the hash to find a command result.
- add_call_files(msg, args, kwargs)[source]#
Gather all files, adding input files to the msg (for hashing) and output files to the returned files list (for outputting in debug)
- get_call_filename(program, key, create=False)[source]#
Get the filename for the call testing information.