Lessons 21–25 · About 60 min per lesson

Modules, command line and automated tests

Make processing reusable and testable, with a command-line entry point.

Lesson breakdown

  1. Lesson 21

    Separate file reading, aggregation and report writing.

  2. Lesson 22

    Reuse functions with import and put the command entry point in main.

  3. Lesson 23

    Accept input and output paths with argparse.

  4. Lesson 24

    Use unittest to verify pure functions and boundaries.

  5. Lesson 25

    Test one complete read-and-write run in a temporary directory.

Worked example

Give the aggregation function two Mia records and check the logic in isolation.

How to solve it

Pass Mia’s 2- and 3-minute records and assert that the total is 5. Call the function directly; no CSV setup is necessary.

Assignment

Test empty input, repeated names and sorting ties, then add one end-to-end command-line test.

Check your result

Empty input gives an empty report, ties sort by name, and CLI output agrees with the aggregation function.