Home | Trees | Indices | Help |
|
---|
|
This is a top level package, hosting the entire CSB test framework. It is divided into several major parts:
/csb/test/data
(not a package)
/csb/test/app.py
This module, csb.test, contains all the glue-code functions, classes and decorators you would need in order to write tests for CSB.
Config is a common config object shared between CSB tests. Each config instance contains properties like:
Each Config
provides a convenient way to retrieve files from
/csb/test/data
. Be sure to check out Config.getTestFile and Config.getPickle. In case you need a temp file, use
Config.getTempStream or have a look at csb.io.TempFile
and csb.io.TempFolder.
All test data files should be placed in the data
folder. All test modules must be placed in the root package:
csb.test.cases. There is a strict naming convention for test modules:
the name of a test module should be the same as the name of the CSB
API package it tests. For example, if you are writing tests for
csb/bio/io/__init__.py
, the test module must be
csb/test/cases/bio/io/__init__.py
.
csb.test.cases
is the root package of all test modules
in CSB.
Writing a test is easy. All you need is to import csb.test and then create your own test cases, derived from csb.test.Case:
>>> import csb.test >>> @csb.test.unit class TestSomeClass(csb.test.Case): def setUp(self): super(TestSomeClass, self).setUp() # do something with self.config here...
In this way your test case instance is automatically equipped with a reference to the test config, so your test method can be:
>>> @csb.test.unit class TestSomeClass(csb.test.Case): def testSomeMethod(self): myDataFile = self.config.getTestFile('some.file') self.assert...
The "unit" decorator marks a test case as a collection of unit tests. All possibilities are: csb.test.unit, csb.test.functional, csb.test.custom, and csb.test.regression.
Writing custom (a.k.a. "data", "slow", "dynamic") tests is a little bit more work. Custom tests must be functions, not classes. Basically a custom test is a function, which builds a unittest.TestSuite instance and then returns it when called without arguments.
Regression tests are usually created in response to reported bugs. Therefore, the best practice is to mark each test method with its relevant bug ID:
>>> @csb.test.regression class SomeClassRegressions(csb.test.Case) def testSomeFeature(self) """ @see: [CSB 000XXXX] """ # regression test body...
if __name__ == '__main__': csb.test.Console() # Discovers and runs all test cases in the module
Test discovery is handled by test builders
and a test
runner app
. Test builders are subclasses of AbstractTestBuilder. For every test type (unit,
functional, regression, custom) there is a corresponding test
builder. AnyTestBuilder is a special builder which scans for
unit, regression and functional tests at the same time.
Test builder classes inherit the following test discovery methods:
loadTests
- load tests from a test namespace.
Wildcard namespaces are handled by loadAllTests
loadAllTests
- load tests from the given namespace,
and from all sub-packages (recursive)
loadFromFile
- load tests from an absolute file name
loadMultipleTests
- calls loadTests
for
a list of namespaces and combines all loaded tests in a single
suite
Each of those return test suite objects, which can be directly executed with python's unittest runner.
Much simpler way to execute a test suite is to use our test app
(csb/test/app.py
), which is simply an instance of csb.test.Console:
$ python csb/test/app.py --help
The app has two main arguments:
csb.test.cases.bio.io.* # io and sub-packages csb.test.cases.bio.utils # only utils . # current module
In addition to running the app from the command line, you can run it also programmatically by instantiating csb.test.Console. You can construct a test console object by passing a list of test namespace(s) and a test builder class to the Console's constructor.
Follow these guidelines when making changes to the repository:
Warning: for compatibility reasons do NOT import and use the unittest module directly. Always import unittest from csb.test, which is guaranteed to be python 2.7+ compatible.
Submodules | |
|
Classes | |
AbstractTestBuilder This is a base class, defining a test loader which exposes the loadTests method.
|
|
AnyTestBuilder Build a test suite of cases, marked as either unit, functional or regression tests. |
|
Attributes | |
Case Base class, defining a CSB Test Case. |
|
Config General CSB Test Config. |
|
Console Build and run all tests of the specified namespace and kind. |
|
CustomTestBuilder Build a test suite of cases, marked as custom tests. |
|
FunctionalTestBuilder Build a test suite of cases, marked as functional tests. |
|
InvalidNamespaceError | |
RegressionTestBuilder Build a test suite of cases, marked as regression tests. |
|
UnitTestBuilder Build a test suite of cases, marked as unit tests. |
Functions | |||
|
|||
|
|||
|
|||
|
|||
|
Variables | |
__package__ =
|
Function Details |
A function decorator, used to mark functions which build custom (dynamic) test suites when called.
|
A class decorator, used to label functional test cases.
|
A class decorator, used to label regression test cases.
|
Mark a test case or method for skipping.
|
A class decorator, used to label unit test cases.
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Jul 4 20:19:04 2017 | http://epydoc.sourceforge.net |