Session 6: Testing and Advanced Argument Passing

Unit Testing and Advanced Argument Passing

Pre-class prep

Reading

Unit Testing

NOTE: you will find that most introductions to unit testing with Python use the built in unittest module. However, it is a bit heavyweight, and requires some knowledge of OOP – classes, etc. So we’ll be using pytest in this class: http://doc.pytest.org/en/latest/. But the principles of testing are the same.

In-class Activities

A bit more on mutability (and copies)

Exercises:

Testing mailroom:

Mailroom Part 4

Write a complete set of unit tests for your mailroom program.

  • You will likely find that it is really hard to test without refactoring.
  • This is Good!
  • If code is hard to test – it probably should be refactored.

Post-class Activities

Finish the exercises

Look at the next session for reading, etc:

Session 7: Object Oriented Programing

NOTE: there is not a lot of new stuff this week, but this will give all of you a chance to catch up if you don’t have mailroom and trigrams fully working yet.

And do spend time with the readings (and supplemental readings) – we are going to dive right in to OO programming next week.