This python 3 package makes it easy for you to write PSM(4) Assembly - even **test-first**!
Simply write a unit test for it in python, extending from `OpbTestCase`. It's easily integratable into your CI environment by leveraging the output of `python -m unittest`.
That's it! Load your Assembly file, apply setup (mocks, inputs), and verify expectations.
opbtest relies on [opbasm and opbsim](https://kevinpt.github.io/opbasm) to compile and evaluate your code.
Both executables should be in your `$PATH`.
The simulator will behave different compared to the actual hardware, so be aware that a set of green tests will not guarantee your code to work when deployed.
Only testing proc1, and nothing more, is usually tricky in Assembly because of the jump statement. opbtest will inject code into your Assembly to jump to the procedure to test, execute that, and jump to an exit label. That ensures no other state will be modified.
#### Mocking
If you explicitly do **not** want a certain procedure to be called, you can do so by calling `mockproc(procname)`.
This will replace all `call procname` statements with dummy statements, hence never actually executing the procedure.
You can replace your own statements with `replace(statement_to_replace, statement_to_replace_with)`.
#### Injecting register values
Before calling `execute()`, you can preload register values using `setreg()`.
For instance, `.setregs({"s5": 2, "s6": 3})` will preload register s5 with value 2 and register s6 with value 3. Psm statements like `output s5, 0` will load 2 into output port 0, because register s5 is preloaded.
#### Injecting input values
Before calling `execute()`, you can preload input port values using `mockinput()`.
For instance, `.mockinput(0, 4)` will preload input port 0 with value 4. Psm statements like `input s0, 0` will load 4 into register s4.
opbtest acutally replaces the statement with `load s0, 4`, so no actual input statements will be processed.