Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for utils.py #7

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@ sudo raspi-config
- Camera
- Enable

### Testing with pytest

To run tests with pytest, run:

```bash
pytest
```


1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==6.2.2
48 changes: 48 additions & 0 deletions tracker/test_utils.py
Original file line number Diff line number Diff line change
@@ -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