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.
- 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#
- 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.
- 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
- 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
- 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 incompare_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
andcompare_file
. Ifcompare_file
is a list, the comparison file name is suffixed with the currentcompare_file
name.Optionally,
comparisons_cmpfile_dict
may be specified asDict[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 overcomparisons
.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.
- 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.