Merge pull request #129 from mkinney/add_pytest

initial pytest
This commit is contained in:
Jm Casler
2021-12-01 08:51:08 -08:00
committed by GitHub
5 changed files with 84 additions and 1 deletions

View File

@@ -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

View File

Binary file not shown.

View File

@@ -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

View File

@@ -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'

5
pytest.ini Normal file
View File

@@ -0,0 +1,5 @@
[pytest]
markers =
unit: marks tests as unit tests
int: marks tests as integration tests