inkex.tester package#

Submodules#

Module contents#

Testing module. See Writing unit tests for details.

class inkex.tester.NoExtension(*args, **kwargs)[source]#

Bases: inkex.base.InkscapeExtension

Test case must specify ‘self.effect_class’ to assertEffect.

run(args=None, output=None)[source]#

Fake run

class inkex.tester.TestCase(*args, **kw)[source]#

Bases: inkex.tester.mock.MockCommandMixin, unittest.case.TestCase

Base class for all effects tests, provides access to data_files and test_without_parameters

effect_class#

alias of inkex.tester.NoExtension

property effect_name#
stderr_output = False#
stdout_protect = True#
stderr_protect = True#
setUp()[source]#

Make sure every test is seeded the same way

tearDown()[source]#

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

classmethod _testdir()[source]#

Get’s the folder where the test exists (so data can be found)

classmethod rootdir()[source]#

Return the full path to the extensions directory

classmethod datadir()[source]#

Get the data directory (can be over-ridden if needed)

property tempdir#

Generate a temporary location to store files

temp_file(prefix='file-', template='{prefix}{name}{suffix}', suffix='.tmp')[source]#

Generate the filename of a temporary file

classmethod data_file(filename, *parts, check_exists=True)[source]#

Provide a data file from a filename, can accept directories as arguments.

Changed in version 1.2: check_exists parameter added

property empty_svg#

Returns a common minimal svg file

assertAlmostTuple(found, expected, precision=8, msg='')[source]#

Floating point results may vary with computer architecture; use assertAlmostEqual to allow a tolerance in the result.

assertEffectEmpty(effect, **kwargs)[source]#

Assert calling effect without any arguments

assertEffect(*filename, **kwargs)[source]#

Assert an effect, capturing the output to stdout.

filename should point to a starting svg document, default is empty_svg

assertDeepAlmostEqual(first, second, places=None, msg=None, delta=None)[source]#

Asserts that two objects, possible nested lists, are almost equal.

assertTransformEqual(lhs, rhs, places=7)[source]#

Assert that two transform expressions evaluate to the same transformation matrix.

New in version 1.1.

property effect#

Generate an effect object

import_string(string, *args) inkex.elements._svg.SvgDocumentElement[source]#

Runs a string through an import extension, with optional arguments provided as “–arg=value” arguments

class inkex.tester.InkscapeExtensionTestMixin[source]#

Bases: object

Automatically setup self.effect for each test and test with an empty svg

setUp()[source]#

Check if there is an effect_class set and create self.effect if it is

test_default_settings()[source]#

Extension works with empty svg file

class inkex.tester.ComparisonMeta(name, bases, attrs)[source]#

Bases: type

Metaclass for ComparisonMixin which creates parametrized tests that can be run independently. See ComparisonMixin for details.

..versionadded :: 1.4

static create_test_method(comparison, file, addout)[source]#
class inkex.tester.ComparisonMixin[source]#

Bases: object

This mixin allows to easily specify a set of run-through unit tests for an extension, which is specified in inkex.tester.TestCase.effect_class.

The commandline parameters are passed in comparisons, the input file in compare_file (either a list of files, or a single file).

The ComparisonMeta metaclass creates a set of independent unit tests out of this data. Behavior notest:

  • The unit tests created are the cross product of comparisons and compare_file. If compare_file is a list, the comparison file name is suffixed with the current compare_file name.

  • Optionally, comparisons_cmpfile_dict may be specified as Dict[Tuple[str], str] where the keys are sets of command line parameters and the values are the filenames of the output file. This takes precedence over comparisons.

  • If any of those values are properties, their values cannot be accessed at test collection time and there will only be a single test, test_all_comparisons with otherwise identical behavior.

  • If the class overrides test_all_comparisons, no additional tests are generated to allow for custom comparison logic.

To create the comparison files for the unit tests, use the EXPORT_COMPARE environment variable.

compare_file: Union[List[str], Tuple[str], str] = 'svg/shapes.svg'#

This input svg file sent to the extension (if any)

compare_filters: List[Compare] = []#

The ways in which the output is filtered for comparision (see filters.py)

compare_filter_save = False#

If true, the filtered output will be saved and only applied to the extension output (and not to the reference file)

comparisons = [(), ('--id=p1', '--id=r3')]#

A list of comparison runs, each entry will cause the extension to be run.

compare_file_extension = 'svg'#
property _compare_file_extension#

The default extension to use when outputting check files in COMPARE_CHECK mode.

_test_comparisons(compare_file, addout=None)[source]#
_test_comparison(args, compare_file, addout=None)[source]#
assertCompare(infile, cmpfile, args, outfile=None)[source]#

Compare the output of a previous run against this one.

Parameters
  • infile – The filename of the pre-processed svg (or other type of file)

  • cmpfile – The filename of the data we expect to get, if not set the filename will be generated from the effect name and kwargs.

  • args – All the arguments to be passed to the effect run

  • outfile – Optional, instead of returning a regular output, this extension dumps it’s output to this filename instead.

write_compare_data(infile, outfile, data)[source]#

Write output

_base_compare(data_a, data_b, compare_mode)[source]#
_apply_compare_filters(data, is_saving=None)[source]#
get_compare_cmpfile(args, addout=None)[source]#

Generate an output file for the arguments given