Testing

Real I/O is a poor foundation for unit tests. Network operations are slow, non-deterministic, and do not fail on demand — so error-handling paths go untested until production breaks them. Capy replaces the transport with in-memory mocks. Because each mock satisfies the same concept as its production counterpart, test code reads the same as production code. The only difference is the type of the stream you pass in.

What This Section Covers

How the Pieces Fit

A typical test constructs one or more mocks, arms a fuse, and hands the mocks to the code under test inside a run_blocking call. The fuse repeats the test body automatically in two full sweeps — error-code mode, then exception mode. Buffer utilities such as bufgrind and buffer_to_string wrap the mock data for assertions. They let you verify that every split of an input buffer produces the same correct output.