Tests for Analysis Code

Tests for Analysis Code: Your First Tests with pytest, Testing pandas Functions with Small Tables, Testing a Chart Without Looking at It.

Updated

  1. Your First Tests with pytest (Journeyman): A test is a small function that runs your code on an example and makes sure the answer is right, and pytest finds every test, runs it, and shows exactly what came back when one fails.
  2. Testing pandas Functions with Small Tables (Journeyman): A real week of data is too big to check by hand, so a test runs the function on a few rows made by hand, where the right answer is clear, and checks one number, a column or a whole table with assert_frame_equal, then the empty table, the missing value and the table it was given.
  3. Testing a Chart Without Looking at It (Journeyman): A chart function that returns its Figure and Axes can be tested like any other function, by reading what the Axes holds, its title, axis labels, each bar's height and a line's data, with matplotlib's Agg backend set in conftest.py and every figure closed with plt.close.