Unit TestingΒΆ

In this notebook we’ll demonstrate some basic unit testing for models.

We build on the standard python unittest libarary, which is documented here. Other testing suites are available, with their own advantages, but this is the most basic, so we’ll use it for our demonstration.

Unit testing us usually done not in the ipython notebook, but in a standalone python file. Tests for this demo are found in the accompanying file testsite.py:

import pysd
import unittest

class TestTeacupModel(unittest.TestCase):
    """ Test Import functionality """
    def set_up_class(cls):
        cls.model = pysd.read_vensim('../../models/Teacup/Teacup.mdl')

    def test_initialization(self):

    def test_heatflow_calc(self):
        self.assertEqual(self.model.components.heat_loss_to_room(), 11.0)
    def test_output(self):
                               75, delta=1)

if __name__ == '__main__':
%run testsuite.py
Ran 3 tests in 0.053s