
Checkpoint
Checkpoint: The Pump Inspector
Every lighthouse has an oil pump with an alarm. When the oil level
drops below 20, check_pump sends a "refill" message to the
keeper and returns True. Otherwise it sends nothing and returns
False.
The Guild wants a proper unittest suite for it, so nobody can
break the alarm by accident. Use what you learned in this chapter:
setUp, a Mock in place of the real messenger, and tests on
both sides of the boundary.
Assignment
Finish TestPump. Don't change check_pump.
- In
setUp, store a freshMock()inself.keeper. test_low_oil_sends_refill: at level19, check thatcheck_pumpreturnsTrueand thatself.keeper.sendwas called once with"refill".test_enough_oil_is_quiet: at level20, check that it returnsFalseand thatself.keeper.sendwas never called (useassert_not_called()).
Finish TestPump. Don't change check_pump.
- In
setUp, store a freshMock()inself.keeper. test_low_oil_sends_refill: at level19, check thatcheck_pumpreturnsTrueand thatself.keeper.sendwas called once with"refill".test_enough_oil_is_quiet: at level20, check that it returnsFalseand thatself.keeper.sendwas never called (useassert_not_called()).
main.py Python sleeping
Press Run to try your code, then Check to test it.