Design of the LineMonitor

Python has an excellent library called subprocess, which allows a quite generic inteface for launching subprocsses using its Popen class.

We want to have a LineMonitor class which:

  1. will launch subprocesses using subprocess under the hood

  2. will allow the caller to register callbacks that get called from every line of output from the subprocess

  3. will also implement an iterator form, e.g. you can write something like

    for line in line_monitor:
         print(f'this just in: {line}')
    

Since this is a Test Driven Development tutorial as well as a Testix tutorial, let’s discuss the tests.

First a short primer on types of tests.

Unit Tests

Unit tests check that each unit of code (usually a single class or module) performs the correct business logic.

Generally speaking, unit tests

  1. test logic

  2. do not perform I/O (perhaps only to local files)

  3. use mocks (not always, but many times) - this is where Testix comes in.

Integration Tests

Integration tests test that various “units” fit together.

Generally speaking, integration tests

  1. perform some actual I/O

  2. do not rigorously test logic (that’s the unit test’s job)

End-to-End (E2E) Tests

In our case, since the project is quite small, the integration test will actually test the scope of the entire project. and so it is more appropriately called an End-to-End (E2E) Test.

In real projects, E2E tests usually include

  1. an actual deployment, which is as similar as possible to real life deployments.

  2. various UI testing techniques, e.g. launching a web-browser to use some webapp

In our toy example, we don’t have such complications.

Let’s move on.