|
|
def | __init__ (self, args, kwargs) |
| |
|
def | setUp (self) |
| |
| def | diffMatchPatchAssertEqual (self, expected, actual, msg=None) |
| |
| def | tearDown (self) |
| |
| def | assertTextEqual (self, goal, results, msg=None, trim_tabs=' ', trim_spaces=' ', trim_plus='+', trim_lines=None, indent="") |
| |
| def | unidiff_output (self, expected, actual) |
| |
|
|
| maxDiff = None |
| | Set the maximum size of the assertion error message when Unit Test fail.
|
| |
|
int | diffMode = 1 |
| | Whether characters diff=0, words diff=1 or lines diff=2 will be used.
|
| |
Holds common features across all Unit Tests.
Definition at line 115 of file testing_utilities.py.
◆ assertTextEqual()
| def assertTextEqual |
( |
|
self, |
|
|
|
goal, |
|
|
|
results, |
|
|
|
msg = None, |
|
|
|
trim_tabs = ' ', |
|
|
|
trim_spaces = ' ', |
|
|
|
trim_plus = '+', |
|
|
|
trim_lines = None, |
|
|
|
indent = "" |
|
) |
| |
Remove both input texts indentation and trailing white spaces, then assertEquals() both
of the inputs.
Definition at line 180 of file testing_utilities.py.
References TestingUtilities.diffMatchPatchAssertEqual().
180 def assertTextEqual(self, goal, results, msg=None, trim_tabs=' ', trim_spaces=' ', trim_plus='+', trim_lines=None, indent=""):
182 Remove both input texts indentation and trailing white spaces, then assertEquals() both 185 goal = wrap_text( goal, trim_tabs=trim_tabs, trim_spaces=trim_spaces,
186 trim_plus=trim_plus, indent=indent, trim_lines=trim_lines )
188 results = wrap_text( results, trim_tabs=trim_tabs, trim_spaces=trim_spaces,
189 trim_plus=trim_plus, indent=indent, trim_lines=trim_lines )
192 self.diffMatchPatchAssertEqual( goal, results, msg=msg )
195 super( TestingUtilities, self ).assertEqual( goal, results, msg )
◆ diffMatchPatchAssertEqual()
| def diffMatchPatchAssertEqual |
( |
|
self, |
|
|
|
expected, |
|
|
|
actual, |
|
|
|
msg = None |
|
) |
| |
How to wrap correctly the unit testing diff?
https://stackoverflow.com/questions/52682351/how-to-wrap-correctly-the-unit-testing-diff
Definition at line 135 of file testing_utilities.py.
References TestingUtilities.diffMode.
Referenced by TestingUtilities.assertTextEqual().
135 def diffMatchPatchAssertEqual(self, expected, actual, msg=None):
137 How to wrap correctly the unit testing diff? 138 https://stackoverflow.com/questions/52682351/how-to-wrap-correctly-the-unit-testing-diff 147 if expected != actual:
148 diff_match = diffmatchpatch()
150 if self.diffMode == 0:
151 diffs = diff_match.diff_main(expected, actual)
154 diff_struct = diff_match.diff_linesToWords(expected, actual,
155 re.compile(
r'\b| ')
if self.diffMode == 1
else re.compile(
r'\n|\r\n') )
157 lineText1 = diff_struct[0]
158 lineText2 = diff_struct[1]
159 lineArray = diff_struct[2]
161 diffs = diff_match.diff_main(lineText1, lineText2,
False);
162 diff_match.diff_charsToLines(diffs, lineArray);
163 diff_match.diff_cleanupSemantic(diffs)
169 msg =
"The strings does not match...\n" 171 self.fail( msg + diff_match.diff_prettyText(diffs) )
◆ tearDown()
Called right after each Unit Test finish its execution, to clean up settings values.
Definition at line 173 of file testing_utilities.py.
175 Called right after each Unit Test finish its execution, to clean up settings values. 177 LockableType.USE_STRING =
True 178 super(TestingUtilities, self).tearDown()
◆ unidiff_output()
| def unidiff_output |
( |
|
self, |
|
|
|
expected, |
|
|
|
actual |
|
) |
| |
Helper function. Returns a string containing the unified diff of two multiline strings.
https://stackoverflow.com/questions/845276/how-to-print-the-comparison-of-two-multiline-strings-in-unified-diff-format
https://stackoverflow.com/questions/15864641/python-difflib-comparing-files
https://stackoverflow.com/questions/32359402/comparison-of-multi-line-strings-in-python-unit-test
Definition at line 197 of file testing_utilities.py.
197 def unidiff_output(self, expected, actual):
199 Helper function. Returns a string containing the unified diff of two multiline strings. 201 https://stackoverflow.com/questions/845276/how-to-print-the-comparison-of-two-multiline-strings-in-unified-diff-format 202 https://stackoverflow.com/questions/15864641/python-difflib-comparing-files 203 https://stackoverflow.com/questions/32359402/comparison-of-multi-line-strings-in-python-unit-test 205 expected = expected.splitlines( 1 )
206 actual = actual.splitlines( 1 )
209 if expected != actual:
210 diff = difflib.context_diff( expected, actual, fromfile=
'expected input', tofile=
'actual output', lineterm=
'\n' )
211 self.fail(
'\n' +
''.join( diff ) )
The documentation for this class was generated from the following file: