Testing PySB Models (pysb.testing.modeltests)

class pysb.testing.modeltests.ModelAssertion(*args, **kwargs)[source]

Base class for model assertions

class pysb.testing.modeltests.ReactionNetworkAssertion(*args, **kwargs)[source]

Base class for reaction network assertions

Checks the reaction network has been generated

class pysb.testing.modeltests.SpeciesAssertion(*args, **kwargs)[source]

Class for checking species within a reaction network

class pysb.testing.modeltests.SpeciesExists(*args, **kwargs)[source]

Checks a species pattern exists in the list of species

class pysb.testing.modeltests.SpeciesIsProduct(*args, **kwargs)[source]

Checks a species pattern appears on the product side of a reaction

class pysb.testing.modeltests.SpeciesIsReactant(*args, **kwargs)[source]

Checks a species pattern appears on the reactant side of a reaction

class pysb.testing.modeltests.SpeciesOnlyProduct(*args, **kwargs)[source]

Checks a species appears as a product but never as a reactant

class pysb.testing.modeltests.SpeciesOnlyReactant(*args, **kwargs)[source]

Checks a species appears as a reactant but never as a product

class pysb.testing.modeltests.TestSuite(model=None)[source]

A suite of tests for checking properties of a model

There are two modes of operation: building a test suite using add() and executing all the tests at once with check_all(), or executing tests immediately with check().


Create a test suite for the EARM 1.0 model:

>>> from pysb.testing.modeltests import TestSuite, SpeciesExists,         SpeciesDoesNotExist
>>> from pysb.bng import generate_equations
>>> from pysb.examples.earm_1_0 import model
>>> ts = TestSuite(model)

Create variables for model components (not needed for models defined interactively):

>>> AMito, mCytoC, mSmac, cSmac, L, CPARP = [model.monomers[m] for m in                                        ('AMito', 'mCytoC', 'mSmac', 'cSmac',                                         'L', 'CPARP')]

Add some assertions:

Check that AMito(b=1) % mSmac(b=1) exists in the species graph (note this doesn’t guarantee the species will actually be producted/consumed/change in concentration; that depends on the rate constants):

>>> ts.add(SpeciesExists(AMito(b=1) % mSmac(b=1)))

This is the opposite check, that the complex above doesn’t exist, which should of course fail:

>>> ts.add(SpeciesDoesNotExist(AMito(b=1) % mSmac(b=1)))

We can also specify that species matching a pattern should never exist in a model. For example, we shouldn’t ever be producing unbound ligand in the EARM 1.0 model:

>>> ts.add(SpeciesNeverProduct(L(b=None)))

We could also have used SpeciesOnlyReactant. The difference is the latter checks for an appearance as a reactant, whereas SpeciesNeverProduct would pass whether the species appeared as a reactant or not.

>>> ts.add(SpeciesOnlyReactant(L(b=None)))

CPARP is an output in this model, so it should appear as a product but never as a reactant:

>>> ts.add(SpeciesOnlyProduct(CPARP()))

When we’re ready, we can generate the reactions and check the assertions:

>>> generate_equations(model)
>>> ts.check_all()  
SpeciesExists(AMito() % mSmac())...OK...
SpeciesDoesNotExist(AMito() % mSmac())...FAIL...
  [AMito(b=1) % mSmac(b=1)]...
SpeciesExists(AMito(b=1) % mCytoC(b=1))...OK...

We can also execute any test immediately without adding it to the test suite (note that some tests require a reaction network to be generated):

>>> ts.check(SpeciesExists(L(b=None)))

Checks an assertion immediately without adding it to the test suite


assertion: ModelAssertion

An instance of the ModelAssertion subclass


True if assertion succeeded or raises a ModelAssertionFailure

exception if not


Runs all assertions in the test suite