diff --git a/README.md b/README.md index 58681db..3eee433 100644 --- a/README.md +++ b/README.md @@ -156,10 +156,21 @@ If you need to build a new release you'll need: ``` apt install pandoc -sudo pip3 install markdown pdoc3 webencodings pyparsing twine autopep8 pylint +sudo pip3 install markdown pdoc3 webencodings pyparsing twine autopep8 pylint pytest ``` To lint, run: ``` pylint meshtastic ``` + +To test, first install this code locally, then run pytest: +``` +pip3 install . +pytest +``` +Possible options for testing: +* for more verbosity, add "-v" or even "-vv" like this: pytest -vv +* to run just unit tests: pytest -munit +* to run just integration tests: pytest -mint +* if you want to add another classification of tests, then look in pytest.ini diff --git a/meshtastic/test/.test_node.py.swp b/meshtastic/test/.test_node.py.swp new file mode 100644 index 0000000..1df257b Binary files /dev/null and b/meshtastic/test/.test_node.py.swp differ diff --git a/meshtastic/test/test_int.py b/meshtastic/test/test_int.py new file mode 100644 index 0000000..ed359d4 --- /dev/null +++ b/meshtastic/test/test_int.py @@ -0,0 +1,30 @@ +"""Meshtastic integration tests""" +import re +import subprocess +import platform + +import pytest + + +@pytest.mark.int +def test_int_no_args(): + """Test without any args""" + return_value, out = subprocess.getstatusoutput('meshtastic') + assert re.match(r'usage: meshtastic', out) + assert return_value == 1 + + +@pytest.mark.int +def test_int_version(): + """Test '--version'.""" + return_value, out = subprocess.getstatusoutput('meshtastic --version') + assert re.match(r'[0-9]+\.[0-9]+\.[0-9]', out) + assert return_value == 0 + + +@pytest.mark.int +def test_int_help(): + """Test '--help'.""" + return_value, out = subprocess.getstatusoutput('meshtastic --help') + assert re.match(r'usage: meshtastic ', out) + assert return_value == 0 diff --git a/meshtastic/test/test_node.py b/meshtastic/test/test_node.py new file mode 100644 index 0000000..c04e49e --- /dev/null +++ b/meshtastic/test/test_node.py @@ -0,0 +1,37 @@ +"""Meshtastic unit tests for node.py""" +import re +import subprocess +import platform + +import pytest + +from meshtastic.node import pskToString + +@pytest.mark.unit +def test_pskToString_empty_string(): + """Test pskToString empty string""" + assert pskToString('') == 'unencrypted' + + +@pytest.mark.unit +def test_pskToString_string(): + """Test pskToString string""" + assert pskToString('hunter123') == 'secret' + + +@pytest.mark.unit +def test_pskToString_one_byte_zero_value(): + """Test pskToString one byte that is value of 0""" + assert pskToString(bytes([0x00])) == 'unencrypted' + + +@pytest.mark.unit +def test_pskToString_one_byte_non_zero_value(): + """Test pskToString one byte that is non-zero""" + assert pskToString(bytes([0x01])) == 'default' + + +@pytest.mark.unit +def test_pskToString_many_bytes(): + """Test pskToString many bytes""" + assert pskToString(bytes([0x02, 0x01])) == 'secret' diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..9c7d72e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] + +markers = + unit: marks tests as unit tests + int: marks tests as integration tests