From 301bdd6c96cbee2645dc651de8f01eececcbfbf7 Mon Sep 17 00:00:00 2001 From: jspeed-meyers Date: Tue, 23 Feb 2021 13:40:02 -0500 Subject: [PATCH 1/2] Add test for utils.py --- tracker/test_utils.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tracker/test_utils.py diff --git a/tracker/test_utils.py b/tracker/test_utils.py new file mode 100644 index 0000000..51e1656 --- /dev/null +++ b/tracker/test_utils.py @@ -0,0 +1,48 @@ +"""Unit tests for utils.py""" + +import pytest + +from utils import bearing, calc_travel, coordinate_distance, deg2rad, elevation + + +def test_deg2rad(): + """Unit tests for deg2rad().""" + # Note: python's math package includes a radians function that + # converts degrees to radians. This function could be eliminated + # to reduce custom code. + assert deg2rad(57.2958) == 1.0000003575641672 + assert deg2rad(1) == 0.017453292519943295 + assert deg2rad(-1) == -0.017453292519943295 + + +@pytest.mark.skip(reason="Insufficient documentation to test. No docstrings.") +def test_elevation(): + """Unit test for elevation().""" + pass + + +def test_bearing(): + """Unit test for bearing().""" + # Example from: https://www.igismap.com/formula-to-find-bearing-or-heading-angle-between-two-points-latitude-longitude/ + lat1, long1 = 39.099912, -94.581213 + lat2, long2 = 38.627089, -90.200203 + expected_bearing = 96.51262423499941 + assert bearing(lat1, long1, lat2, long2) == expected_bearing + + +def test_coordinate_distance(): + """Unit test for coordinate_distance().""" + # Used this app to calculate distance: https://www.movable-type.co.uk/scripts/latlong.html + lat1, long1 = 39.099912, -94.581213 + lat2, long2 = 38.627089, -90.200203 + expected_distance = 382900.05037560174 + assert coordinate_distance(lat1, long1, lat2, long2) == expected_distance + + +@pytest.mark.skip(reason="Insufficient documentation to test. What is lead_s?") +def test_calc_travel(): + """Unit test for calc_travel().""" + # note: the code in calc_travel is hard to understand because of the tangle + # of calculations. consider reformatting and explaining or explore the possibility + # using geopy + pass From aa9e7d91b4a5fc38853e0575ee17a631b6fd8cc1 Mon Sep 17 00:00:00 2001 From: jspeed-meyers Date: Tue, 23 Feb 2021 15:20:34 -0500 Subject: [PATCH 2/2] Add readme explanation of pytest and a requirements.txt --- README.md | 8 ++++++++ requirements.txt | 1 + 2 files changed, 9 insertions(+) create mode 100644 requirements.txt diff --git a/README.md b/README.md index 8c367f0..a838378 100644 --- a/README.md +++ b/README.md @@ -82,4 +82,12 @@ sudo raspi-config - Camera - Enable +### Testing with pytest + +To run tests with pytest, run: + +```bash +pytest +``` + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8aa50dd --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pytest==6.2.2 \ No newline at end of file