Skip to main content

Testing

Zener tests validate module connectivity, component properties, and circuit topology. Define tests in .zen files and run them with pcb test.

Define a test bench

TestBench evaluates a module for one or more input cases and runs each check function against the result:
This example assumes that MyCircuit has no required inputs. Supply each module input in the case dictionary when the module requires arguments. Each check receives the evaluated module and the active case’s input dictionary. Call check(condition, message) or error(message) to fail a test. An unhandled evaluation error also fails the test. pcb test reports failures with their source locations.

Inspect the evaluated module

The evaluated module exposes its nets and components: Component values expose name, type, pins, properties, sourcing fields, and component-specific properties such as resistance when present.

Search circuit paths

module.graph() returns the circuit graph. Use graph.paths() to find simple paths between component pins or public module nets:
start and end accept a (component, pin) tuple or the name of a public net. max_depth limits the number of traversed components and defaults to 10. Each returned path provides:
  • ports: traversed (component, pin) tuples
  • components: traversed component values
  • nets: traversed net names

Match components in a path

count, any, all, and none accept a function that validates one component. The matcher succeeds when it returns without an error:
any, all, and none fail when their condition is not satisfied.

Match a component sequence

path.matches() validates the complete ordered component sequence. Each matcher receives the path and the current component index, then returns the number of components it consumed.
Use the matchers in a topology check:
Matcher helpers are not prelude symbols. Define them in the test file or load them from a project-local helper module. Pass suppress_errors=True when a failed sequence is an expected search result. The method then returns False instead of failing the test: