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#
flip(exc_type=None, exc_val=None, exc_tb=None)[source]#

Swap the stored verbosity with the original

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]] = []#
setUpMock(owner, name, new)[source]#

Setup the mock here, taking name and function and returning (name, old)

setUp()[source]#

For each mock instruction, set it up and store the return

tearDown()[source]#

For each returned stored, tear it down and restore mock instruction

old_call(name)[source]#

Get the original caller

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] = []#
setUp()[source]#

For each mock instruction, set it up and store the return

classmethod cmddir()[source]#

Returns the location of all the mocked command results

record_tempdir(*args, **kwargs)[source]#

Record any attempts to make tempdirs

clean_paths(data, files)[source]#

Clean a string of any files or tempdirs

get_all_tempfiles()[source]#

Returns a set() of all files currently in any of the tempdirs

ignore_command_mock(program, arglst, path)[source]#

Return true if the mock is ignored

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)

add_call_file(msg, filename)[source]#

Add a single file to the given mime message

get_call_filename(program, key, create=False)[source]#

Get the filename for the call testing information.

static get_program_name(program)[source]#

Takes a program and returns a program name

get_call_path(program, create=True)[source]#

Get where this program would store it’s test data

load_call(program, key, files)[source]#

Load the given call

save_call(program, key, stdout, files, msg, ext='output')[source]#

Saves the results from the call into a debug output file, the resulting files should be a Mime msg file format with each attachment being one of the input files as well as any stdin and arguments used in the call.

save_key(program, key, keystr, ext='key')[source]#

Save the key file if we are debugging the key data