JPHutchins / smp

Simple Management Protocol (SMP) for remotely managing MCU firmware
Apache License 2.0
8 stars 6 forks source link

Improve (or document) _do_test #5

Open JPHutchins opened 9 months ago

JPHutchins commented 9 months ago

There's this confusing _do_test function that I've duplicated throughout the tests. It ends up making a lot of the unit tests look like magic and doesn't necessarily help someone if they are using the unit tests to understand normal usage of the library.

def test_EchoWriteRequest() -> None:
    _do_test(
        smpos.EchoWriteRequest,
        smphdr.OP.WRITE,
        oscmd.ECHO,
        {"d": "Hello world!"},
    )

Nothing is accessed, asserted, etc.

I feel like the tests themselves should be updated to at least show that the CBOR payload members are accessible as part of the type:

def test_EchoWriteRequest() -> None:
    r = _do_test(
        smpos.EchoWriteRequest,
        smphdr.OP.WRITE,
        oscmd.ECHO,
        {"d": "Hello world!"},
    )
    assert r.d == "Hello world!"

Further, _do_test should be generalized, rewritten with better variable names, comments etc. if the code cannot be made more legible, so that maintainers don't have to copy it to each test suite.

_do_test ITSELF should be unit tested if tests depend on it!