unittest.mock, from stand-ins to spies

Python · Testing

A mock is a stand-in you put where a real function or object used to be, for as long as a test runs. It answers the way you tell it to, it remembers every call it got, and when the test ends the original comes back. This guide covers both halves — controlling and recording — and then the part most tutorials skip: wraps=, a spy that lets the real code run.

A | B means either: reading union type hints in Python

Python · Type hints

def sensor_id(sensor: Sensor | int | None) -> int has three bars in one signature and looks like bit arithmetic. It is not arithmetic and it is not new syntax to memorise: each bar is the word or, and the whole annotation is one sentence — "a Sensor, or an int, or nothing".

MareArts ANPR App: On-Device Plates, MMC Vehicle Info, Team Sync, Web and Desktop Viewers

MareArts ANPR is a license-plate recognition app for iOS and Android, with a web viewer and a desktop viewer on the same account. Plates are read on the phone. Cloud MMC (make, model, colour, type, side, nation), team sync, rules, maps, and stats sit on marearts.com.