easybuild.base.testing module

Shared module for vsc software testing

TestCase: use instead of unittest TestCase
from easybuild.base.testing import TestCase
author:Stijn De Weirdt (Ghent University)
author:Kenneth Hoste (Ghent University)
class easybuild.base.testing.TestCase(methodName='runTest')

Bases: unittest.case.TestCase

Enhanced test case, provides extra functionality (e.g. an assertErrorRegex method).

ASSERT_MAX_DIFF = 100
DIFF_OFFSET = 5
assertEqual(a, b, msg=None)

Make assertEqual always print useful messages

assertErrorRegex(error, regex, call, *args, **kwargs)

Convenience method to match regex with the expected error message. Example: self.assertErrorRegex(OSError, “No such file or directory”, os.remove, ‘/no/such/file’)

convert_exception_to_str(err)

Convert an Exception instance to a string.

get_stderr()

Return output captured from stderr until now.

get_stdout()

Return output captured from stdout until now.

is_string(x)

test if the variable x is a string)

longMessage = True
mock_stderr(enable)

Enable/disable mocking stdout.

mock_stdout(enable)

Enable/disable mocking stdout.

mocked_stdout_stderr(mock_stdout=True, mock_stderr=True)

Context manager to mock stdout and stderr

setUp()

Prepare test case.

tearDown()

Cleanup after running a test.

easybuild.base.testing.nicediff(txta, txtb, offset=5)
generate unified diff style output
ndiff has nice indicators what is different, but prints the whole content
each line that is interesting starts with non-space

unified diff only prints changes and some offset around it

return list with diff (one per line) (not a generator like ndiff or unified_diff)