meshtastic / python

The Python CLI and API for talking to Meshtastic devices
https://meshtastic.org
379 stars 160 forks source link

create simple smoke test #128

Closed mkinney closed 2 years ago

mkinney commented 2 years ago

Create a simple smoke test to validate if the package performs as expected.

Perhaps use: https://docs.pytest.org

mkinney commented 2 years ago

This is 3 simple tests that simply run 3 simple operations from the command line: meshtastic, meshtastic --version and meshtastic --help.

These very simple commands do so much. They ensure there are no syntax errors and the basic command actually does something (other than errors).

Here's how it could look when running:

**% pytest
======================================================================= test session starts ========================================================================
platform darwin -- Python 3.9.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /xxx/Meshtastic-python, configfile: pytest.ini
collected 3 items

meshtastic/tests/test_int.py ...                                                                                                                             [100%]

======================================================================== 3 passed in 0.64s =========================================================================**

Or in detailed form:

% pytest -vv
======================================================================= test session starts ========================================================================
platform darwin -- Python 3.9.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /usr/local/opt/python@3.9/bin/python3.9
cachedir: .pytest_cache
rootdir: /xxxMeshtastic-python, configfile: pytest.ini
collected 3 items

meshtastic/tests/test_int.py::test_int_no_args PASSED                                                                                                        [ 33%]
meshtastic/tests/test_int.py::test_int_version PASSED                                                                                                        [ 66%]
meshtastic/tests/test_int.py::test_int_help PASSED                                                                                                           [100%]

======================================================================== 3 passed in 0.88s =========================================================================
mkinney commented 2 years ago

Stuff like pskToString(psk: bytes) would be great candidates for unit tests.

see https://github.com/meshtastic/Meshtastic-python/blob/master/meshtastic/node.py#L67

mkinney commented 2 years ago

I just added a simple unit test of pskToString to show how it might look/work. I did just the "happy" paths, but in reality we should add negative tests, too.

Again, just demonstrating how it might work:

% pytest -vv
======================================================================= test session starts ========================================================================
platform darwin -- Python 3.9.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /usr/local/opt/python@3.9/bin/python3.9
cachedir: .pytest_cache
rootdir: /xxxMeshtastic-python, configfile: pytest.ini
collected 4 items

meshtastic/test/test_int.py::test_int_no_args PASSED                                                                                                         [ 25%]
meshtastic/test/test_int.py::test_int_version PASSED                                                                                                         [ 50%]
meshtastic/test/test_int.py::test_int_help PASSED                                                                                                            [ 75%]
meshtastic/test/test_node.py::test_pskToString PASSED                                                                                                        [100%]

======================================================================== 4 passed in 0.75s =========================================================================