Scripts and assert tools related to running unit tests.
These scripts also allow running test suites in separate processes and aggregating the results.
Tools for having doctest and unittest work together more nicely.
Eclipse’s PyDev plugin will run your unittest files for you very nicely. The doctest_for_module function allows you to easily run the doctest for a module along side your standard unit tests within Eclipse.
Create a TestCase from a module’s doctests that will be run by the standard unittest.main().
Example tests/test_foo.py:
import unittest
import foo
from traits.testing.api import doctest_for_module
class FooTestCase(unittest.TestCase):
...
class FooDocTest(doctest_for_module(foo)):
pass
if __name__ == "__main__":
# This will run and report both FooTestCase and the doctests in
# module foo.
unittest.main()
Alternatively, you can say:
FooDocTest = doctest_for_module(foo)
instead of:
class FooDocTest(doctest_for_module(foo)):
pass
Non-standard functions for the ‘nose’ testing framework.
Trait assert mixin class to simplify test implementation for Trait Classes.
Bases: object
Mixin class to augment the unittest.TestCase class with useful trait related assert methods.
Assert that the class trait changes exactly n times.
Used in a with statement to assert that a class trait has changed during the execution of the code inside the with context block (similar to the assertRaises method).
Please note that the context manager returns itself and the user can introspect the information of the fired events by accessing the events attribute of the context object. The attribute is a list with tuple elements containing the arguments of an on_trait_change event signature (<object>, <name>, <old>, <new>).
Example:
class MyClass(HasTraits):
number = Float(2.0)
my_class = MyClass()
with self.assertTraitChanges(my_class, 'number') as ctx:
my_class.number = 3.0
self.assert(ctx.events, [(my_class, 'number', 2.0, 3.0)]
Parameters: |
|
---|
Note
Assert that no trait event is fired.
Used in a with statement to assert that a class trait has not changed during the execution of the code inside the with statement block.
Example:
class MyClass(HasTraits):
number = Float(2.0)
name = String
my_class = MyClass()
with self.assertTraitDoesNotChange(my_class, 'name'):
my_class.number = 2.0
Parameters: |
|
---|
Note