Code testing and beyond

Let's start with a simple example

We want to generate some code that is removing the linear trend from an arbitray timeseries to obtain a detrended timeseries. This means that we look for

$y - (mx + b)$

whereas $m$ and $b$ are linear slope estimators.

Let's have a look on the example file ...

What do we need or can test to ensure that our code works properly?

What kind of testing is existing?

There are numerous different testing approaches existing. For a summary see here:

  • unittesting = small units are tested
  • integration testing = entire modules/programs are tested how they integrate with other components of the same software
  • ...

How can we do that?

Our friend are code testing modules. Probably the most common one is unittest, but others (e.g. pytest) exist as well.

A very good introduction can be found int the Hitchhickers guide to Python. Numerous other online ressources exist however as well.

Typically, we then run tests using nose.

Let's do it!

Testing approaches

  • Test driven development = write tests first (turn coding upside down)
  • Continuous integration and testing

Continuous integration and testing

Continuous integration facilitates your life! Code repository platforms like github or bitbucket allow you to link your code to external services. This can be a lot of different (usefull) things.

Some examples from the RT1 project:

  • travis.ci = installs and builds your code automatically in different environments (e.g. python 2.7, 3.4, 3.5, 3.6 und Linux, OSX, Windows) and runs your tests --> everything works? Get a go! :-)
  • ReadTheDocs = automatically builds a nice documentation for your code and hosts it on a website (highly configurable)
  • stickler-ci: automatically test your code for compliance with a specific standard (e.g. PEP8 standard for python)

In [ ]: