Skip to content

Commit

Permalink
Fix pylint issues and add pylint to workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
flederwiesel committed Oct 2, 2023
1 parent f82245c commit 29c3c9c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 79 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/code_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black pytest
pip install black pylint pytest
pip install -r requirements.txt
- name: Lint with black
- name: Lint wit pylint
env:
PYTHONPATH: ${GITHUB_WORKSPACE}
run: |
python -m pylint gcmath.py notify.py tests/
- name: Check formatting with black
run: |
python -m black --check gcmath.py
- name: Test with pytest
Expand Down
154 changes: 77 additions & 77 deletions tests/test_gcmath.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""Test gmath functions"""

# pylint: disable=line-too-long, disable=too-many-statements

import math
from gcmath import (
LatLon,
calc_bearing,
Expand All @@ -10,16 +11,14 @@
deg_to_km,
)

### Going nowhere...

def test_travel_nowhere():
"""Going nowhere..."""
assert travel(LatLon(0.0, 0.0), 0.0, 0.0) == LatLon(0.0, 0.0)
assert travel(LatLon(0.0, 0.0), 0.0, 90.0) == LatLon(0.0, 0.0)
assert travel(LatLon(90.0, 0.0), 0.0, 180.0) == LatLon(90.0, 0.0)

### Along circles of longitude

def test_travel_north():
"""Along circles of longitude"""
assert travel(LatLon(-90.0, 0), deg_to_km( 0), 0.0) == LatLon(-90.0, 0.0)
assert travel(LatLon(-90.0, 0), deg_to_km( 10), 0.0) == LatLon(-80.0, 0.0)
assert travel(LatLon(-90.0, 0), deg_to_km( 80), 0.0) == LatLon(-10.0, 0.0)
Expand Down Expand Up @@ -111,6 +110,7 @@ def test_travel_north():
assert travel(LatLon(90.0, 0), deg_to_km(100), 0.0) == LatLon( 90.0, 0.0)

def test_travel_south():
"""Along circles of longitude"""
assert travel(LatLon(90.0, 0.0), deg_to_km( 0), 180.0) == LatLon( 90.0, 0.0)
assert travel(LatLon(90.0, 0.0), deg_to_km( 10), 180.0) == LatLon( 80.0, 0.0)
assert travel(LatLon(90.0, 0.0), deg_to_km( 80), 180.0) == LatLon( 10.0, 0.0)
Expand Down Expand Up @@ -207,9 +207,8 @@ def test_travel_south():
assert travel(LatLon(-90.0, 0.0), deg_to_km( 0), 180.0) == LatLon(-90.0, 0.0)
assert travel(LatLon(-90.0, 0.0), deg_to_km(10), 180.0) == LatLon(-90.0, 0.0)

### Along circles of latitude

def test_travel_east():
"""Along circles of latitude"""
assert travel(LatLon(90.0, 60.0), deg_to_km(100, 60.0), 90.0) == LatLon(90.0, 60.0)

# Because of float imprecision, we get 180.00000000003, which leads to adjustment to -180.0
Expand Down Expand Up @@ -260,7 +259,8 @@ def test_travel_east():
assert travel(LatLon(-45.0, -170.0), deg_to_km(360, -45.0), 90.0) == LatLon(-45.0, -170.0)
assert travel(LatLon(-45.0, -170.0), deg_to_km(370, -45.0), 90.0) == LatLon(-45.0, -160.0)

def test_travel_east():
def test_travel_west():
"""Along circles of latitude"""
assert travel(LatLon(90.0, -180.0), deg_to_km(100, 90.0), 270.0) == LatLon(90.0, -180.0)

assert travel(LatLon(80.0, -180.0), deg_to_km( 0, 80.0), 270.0) == LatLon(80.0, -180.0)
Expand Down Expand Up @@ -310,212 +310,212 @@ def test_travel_east():

### Cross equator and/or 0-meridian like in 1.pdn

def test_travel_1_Q1_Q2():
# Q1 -> Q2
def test_travel_1_q1_q2():
"""Q1 -> Q2"""
assert(isclose(calc_bearing(LatLon(30.0, 30.0), LatLon(-30.0, 15.0)), 194.7514449152269))
assert(isclose(calc_distance(LatLon(30.0, 30.0), LatLon(-30.0, 15.0)), 6858.150413856773))
assert(travel(LatLon(30.0, 30.0), 6858.150413856773, 194.7514449152269) == LatLon(-30.0, 15.0))

def test_travel_1_Q1_Q3():
# Q1 -> Q3
def test_travel_1_q1_q3():
"""Q1 -> Q3"""
assert(isclose(calc_bearing(LatLon(30.0, 30.0), LatLon(-30.0, -15.0)), 219.63927223775613))
assert(isclose(calc_distance(LatLon(30.0, 30.0), LatLon(-30.0, -15.0)), 8197.30142711796))
assert(travel(LatLon(30.0, 30.0), 8197.30142711796, 219.63927223775613) == LatLon(-30.0, -15.0))

def test_travel_1_Q1_Q4():
# Q1 -> Q4
def test_travel_1_q1_q4():
"""Q1 -> Q4"""
assert(isclose(calc_bearing(LatLon(30.0, 30.0), LatLon(-15.0, -15.0)), 230.36948571096076))
assert(isclose(calc_distance(LatLon(30.0, 30.0), LatLon(-15.0, -15.0)), 6947.182442673351))
assert(travel(LatLon(30.0, 30.0), 6947.182442673351, 230.36948571096076) == LatLon(-15.0, -15.0))

def test_travel_1_Q2_Q1():
# Q2 -> Q1
def test_travel_1_q2_q1():
"""Q2 -> Q1"""
assert(isclose(calc_bearing(LatLon(-30.0, 30.0), LatLon(30.0, 15.0)), 345.2485550847731))
assert(isclose(calc_distance(LatLon(-30.0, 30.0), LatLon(30.0, 15.0)), 6858.150413856773))
assert(travel(LatLon(-30.0, 30.0), 6858.150413856773, 345.2485550847731) == LatLon(30.0, 15.0))

def test_travel_1_Q2_Q3():
# Q2 -> Q3
def test_travel_1_q2_q3():
"""Q2 -> Q3"""
assert(isclose(calc_bearing(LatLon(-30.0, 30.0), LatLon(-15.0, -15.0)), 279.74995402797686))
assert(isclose(calc_distance(LatLon(-30.0, 30.0), LatLon(-15.0, -15.0)), 4878.105519870221))
assert(travel(LatLon(-30.0, 30.0), 4878.105519870221, 279.74995402797686) == LatLon(-15.0, -15.0))

def test_travel_1_Q2_Q4():
# Q2 -> Q4
def test_travel_1_q2_q4():
"""Q2 -> Q4"""
assert(isclose(calc_bearing(LatLon(-30.0, 30.0), LatLon(30.0, -15.0)), 320.36072776224387))
assert(isclose(calc_distance(LatLon(-30.0, 30.0), LatLon(30.0, -15.0)), 8197.30142711796))
assert(travel(LatLon(-30.0, 30.0), 8197.30142711796, 320.36072776224387) == LatLon(30.0, -15.0))

def test_travel_1_Q3_Q1():
# Q3 -> Q1
def test_travel_1_q3_q1():
"""Q3 -> Q1"""
assert(isclose(calc_bearing(LatLon(-30.0, -30.0), LatLon(30.0, 15.0)), 39.63927223775613))
assert(isclose(calc_distance(LatLon(-30.0, -30.0), LatLon(30.0, 15.0)), 8197.30142711796))
assert(travel(LatLon(-30.0, -30.0), 8197.30142711796, 39.63927223775613) == LatLon(30.0, 15.0))

def test_travel_1_Q3_Q2():
# Q3 -> Q2
def test_travel_1_q3_q2():
"""Q3 -> Q2"""
assert(isclose(calc_bearing(LatLon(-30.0, -30.0), LatLon(-15.0, -15.0)), 45.88869972297674))
assert(isclose(calc_distance(LatLon(-30.0, -30.0), LatLon(-15.0, -15.0)), 2265.8122607469577))
assert(travel(LatLon(-30.0, -30.0), 2265.8122607469577, 45.88869972297674) == LatLon(-15.0, -15.0))

def test_travel_1_Q3_Q4():
# Q3 -> Q4
def test_travel_1_q3_q4():
"""Q3 -> Q4"""
assert(isclose(calc_bearing(LatLon(-30.0, -30.0), LatLon(30.0, -15.0)), 14.751444915226907))
assert(isclose(calc_distance(LatLon(-30.0, -30.0), LatLon(30.0, -15.0)), 6858.150413856773))
assert(travel(LatLon(-30.0, -30.0), 6858.150413856773, 14.751444915226907) == LatLon(30.0, -15.0))

def test_travel_1_Q4_Q1():
# Q4 -> Q1
def test_travel_1_q4_q1():
"""Q4 -> Q1"""
assert(isclose(calc_bearing(LatLon(30.0, -30.0), LatLon(15.0, 15.0)), 99.74995402797683))
assert(isclose(calc_distance(LatLon(30.0, -30.0), LatLon(15.0, 15.0)), 4878.105519870221))
assert(travel(LatLon(30.0, -30.0), 4878.105519870221, 99.74995402797683) == LatLon(15.0, 15.0))

def test_travel_1_Q4_Q2():
# Q4 -> Q2
def test_travel_1_q4_q2():
"""Q4 -> Q2"""
assert(isclose(calc_bearing(LatLon(30.0, -30.0), LatLon(-30.0, 15.0)), 140.36072776224387))
assert(isclose(calc_distance(LatLon(30.0, -30.0), LatLon(-30.0, 15.0)), 8197.30142711796))
assert(travel(LatLon(30.0, -30.0), 8197.30142711796, 140.36072776224387) == LatLon(-30.0, 15.0))

def test_travel_1_Q4_Q3():
# Q4 -> Q3
def test_travel_1_q4_q3():
"""Q4 -> Q3"""
assert(isclose(calc_bearing(LatLon(30.0, -30.0), LatLon(-30.0, -15.0)), 165.2485550847731))
assert(isclose(calc_distance(LatLon(30.0, -30.0), LatLon(-30.0, -15.0)), 6858.150413856773))
assert(travel(LatLon(30.0, -30.0), 6858.150413856773, 165.2485550847731) == LatLon(-30.0, -15.0))

### Cross equator and/or 0-meridian like in 2.pdn

def test_travel_2_Q1_Q2():
# Q1 -> Q2
def test_travel_2_q1_q2():
"""Q1 -> Q2"""
assert(isclose(calc_bearing(LatLon(30.0, -150.0), LatLon(-30.0, -165.0)), 194.7514449152269))
assert(isclose(calc_distance(LatLon(30.0, -150.0), LatLon(-30.0, -165.0)), 6858.150413856773))
assert(travel(LatLon(30.0, -150.0), 6858.150413856773, 194.7514449152269) == LatLon(-30.0, -165.0))

def test_travel_2_Q1_Q3():
# Q1 -> Q3
def test_travel_2_q1_q3():
"""Q1 -> Q3"""
assert(isclose(calc_bearing(LatLon(30.0, -150.0), LatLon(-30.0, 165.0)), 219.63927223775613))
assert(isclose(calc_distance(LatLon(30.0, -150.0), LatLon(-30.0, 165.0)), 8197.30142711796))
assert(travel(LatLon(30.0, -150.0), 8197.30142711796, 219.63927223775613) == LatLon(-30.0, 165.0))

def test_travel_2_Q1_Q4():
# Q1 -> Q4
def test_travel_2_q1_q4():
"""Q1 -> Q4"""
assert(isclose(calc_bearing(LatLon(30.0, -150.0), LatLon(15.0, 165)), 260.25004597202314))
assert(isclose(calc_distance(LatLon(30.0, -150.0), LatLon(15.0, 165)), 4878.1055198702215))
assert(travel(LatLon(30.0, -150.0), 4878.1055198702215, 260.25004597202314) == LatLon(15.0, 165))

def test_travel_2_Q2_Q1():
# Q2 -> Q1
def test_travel_2_q2_q1():
"""Q2 -> Q1"""
assert(isclose(calc_bearing(LatLon(-30.0, -150.0), LatLon(30.0, -165.0)), 345.2485550847731))
assert(isclose(calc_distance(LatLon(-30.0, -150.0), LatLon(30.0, -165.0)), 6858.150413856773))
assert(travel(LatLon(-30.0, -150.0), 6858.150413856773, 345.2485550847731) == LatLon(30.0, -165.0))

def test_travel_2_Q2_Q3():
# Q2 -> Q3
def test_travel_2_q2_q3():
"""Q2 -> Q3"""
assert(isclose(calc_bearing(LatLon(-30.0, -150.0), LatLon(-15.0, 165.0)), 279.7499540279768))
assert(isclose(calc_distance(LatLon(-30.0, -150.0), LatLon(-15.0, 165.0)), 4878.1055198702215))
assert(travel(LatLon(-30.0, -150.0), 4878.1055198702215, 279.7499540279768) == LatLon(-15.0, 165.0))

def test_travel_2_Q2_Q4():
# Q2 -> Q4
def test_travel_2_q2_q4():
"""Q2 -> Q4"""
assert(isclose(calc_bearing(LatLon(-30.0, -150.0), LatLon(15.0, 165.0)), 309.63051428903924))
assert(isclose(calc_distance(LatLon(-30.0, -150.0), LatLon(15.0, 165.0)), 6947.182442673351))
assert(travel(LatLon(-30.0, -150.0), 6947.182442673351, 309.63051428903924) == LatLon(15.0, 165.0))

def test_travel_2_Q3_Q1():
# Q3 -> Q1
def test_travel_2_q3_q1():
"""Q3 -> Q1"""
assert(isclose(calc_bearing(LatLon(-30.0, 150.0), LatLon(30.0, -165.0)), 39.639272237756146))
assert(isclose(calc_distance(LatLon(-30.0, 150.0), LatLon(30.0, -165.0)), 8197.30142711796))
assert(travel(LatLon(-30.0, 150.0), 8197.30142711796, 39.639272237756146) == LatLon(30.0, -165.0))

def test_travel_2_Q3_Q2():
# Q3 -> Q2
def test_travel_2_q3_q2():
"""Q3 -> Q2"""
assert(isclose(calc_bearing(LatLon(-30.0, 150.0), LatLon(-15.0, -165.0)), 80.25004597202319))
assert(isclose(calc_distance(LatLon(-30.0, 150.0), LatLon(-15.0, -165.0)), 4878.1055198702215))
assert(travel(LatLon(-30.0, 150.0), 4878.1055198702215, 80.25004597202319) == LatLon(-15.0, -165.0))

def test_travel_2_Q3_Q4():
# Q3 -> Q4
def test_travel_2_q3_q4():
"""Q3 -> Q4"""
assert(isclose(calc_bearing(LatLon(-30.0, 150.0), LatLon(30.0, 165.0)), 14.751444915226907))
assert(isclose(calc_distance(LatLon(-30.0, 150.0), LatLon(30.0, 165.0)), 6858.150413856773))
assert(travel(LatLon(-30.0, 150.0), 6858.150413856773, 14.751444915226907) == LatLon(30.0, 165.0))

def test_travel_2_Q4_Q1():
# Q4 -> Q1
def test_travel_2_q4_q1():
"""Q4 -> Q1"""
assert(isclose(calc_bearing(LatLon(30.0, 150.0), LatLon(15.0, 165.0)), 134.11130027702328))
assert(isclose(calc_distance(LatLon(30.0, 150.0), LatLon(15.0, 165.0)), 2265.8122607469577))
assert(travel(LatLon(30.0, 150.0), 2265.8122607469577, 134.11130027702328) == LatLon(15.0, 165.0))

def test_travel_2_Q4_Q2():
# Q4 -> Q2
def test_travel_2_q4_q2():
"""Q4 -> Q2"""
assert(isclose(calc_bearing(LatLon(30.0, 150.0), LatLon(-30.0, -165.0)), 140.36072776224387))
assert(isclose(calc_distance(LatLon(30.0, 150.0), LatLon(-30.0, -165.0)), 8197.30142711796))
assert(travel(LatLon(30.0, 150.0), 8197.30142711796, 140.36072776224387) == LatLon(-30.0, -165.0))

def test_travel_2_Q4_Q3():
# Q4 -> Q3
def test_travel_2_q4_q3():
"""Q4 -> Q3"""
assert(isclose(calc_bearing(LatLon(30.0, 150.0), LatLon(-30.0, 165.0)), 165.2485550847731))
assert(isclose(calc_distance(LatLon(30.0, 150.0), LatLon(-30.0, 165.0)), 6858.150413856773))
assert(travel(LatLon(30.0, 150.0), 6858.150413856773, 165.2485550847731) == LatLon(-30.0, 165.0))

### Travel to a point of same latitude, as in 3.pdn

def test_travel_3_A_B():
# A -> B
def test_travel_3_a_b():
"""A -> B"""
assert(isclose(calc_bearing(LatLon(60.0, 15.0), LatLon(60.0, -150.0)), 351.35612163513326))
assert(isclose(calc_distance(LatLon(60.0, 15.0), LatLon(60.0, -150.0)), 6608.848934146663))
assert(travel(LatLon(60.0, 15.0), 6608.848934146663, 351.35612163513326) == LatLon(60.0, -150.0))

def test_travel_3_A_B():
# A-> C
def test_travel_3_a_c():
"""A-> C"""
assert(isclose(calc_bearing(LatLon(60.0, 15.0), LatLon(60.0, 150.0)), 25.56144583679776))
assert(isclose(calc_distance(LatLon(60.0, 15.0), LatLon(60.0, 150.0)), 6118.467805800631))
assert(travel(LatLon(60.0, 15.0), 6118.467805800631, 25.56144583679776) == LatLon(60.0, 150.0))

def test_travel_3_B_C():
# B -> C
def test_travel_3_b_c():
"""B -> C"""
assert(isclose(calc_bearing(LatLon(60.0, -150.0), LatLon(60.0, 150.0)), 296.56505117707798))
assert(isclose(calc_distance(LatLon(60.0, -150.0), LatLon(60.0, 150.0)), 3219.6522077283666))
assert(travel(LatLon(60.0, -150.0), 3219.6522077283666, 296.56505117707798) == LatLon(60.0, 150.0))

def test_travel_3_C_B():
# C -> B
def test_travel_3_c_b():
"""C -> B"""
assert(isclose(calc_bearing(LatLon(60.0, 150.0), LatLon(60.0, -150.0)), 63.43494882292202))
assert(isclose(calc_distance(LatLon(60.0, 150.0), LatLon(60.0, -150.0)), 3219.6522077283666))
assert(travel(LatLon(60.0, 150.0), 3219.6522077283666, 63.43494882292202) == LatLon(60.0, -150.0))

def test_travel_3_D_C():
# D -> B
def test_travel_3_d_c():
"""D -> B"""
assert(isclose(calc_bearing(LatLon(60.0, -90.0), LatLon(60.0, 150.0)), 326.30993247402023))
assert(isclose(calc_distance(LatLon(60.0, -90.0), LatLon(60.0, 150.0)), 5706.281104765323))
assert(travel(LatLon(60.0, -90.0), 5706.281104765323, 326.30993247402023) == LatLon(60.0, 150.0))

def test_travel_3_D_E():
# D -> C
def test_travel_3_d_e():
"""D -> C"""
assert(isclose(calc_bearing(LatLon(60.0, -90.0), LatLon(60.0, 60.0)), 17.192123734020974))
assert(isclose(calc_distance(LatLon(60.0, -90.0), LatLon(60.0, 60.0)), 6422.418272993739))
assert(travel(LatLon(60.0, -90.0), 6422.418272993739, 17.192123734020974) == LatLon(60.0, 60.0))

### Travel to a point of same latitude, as in 4.pdn

def test_travel_4_A_B():
# A -> B
def test_travel_4_a_b():
"""A -> B"""
assert(isclose(calc_bearing(LatLon(-60.0, 100.0), LatLon(-60.0, -150.0)), 141.04342059936801))
assert(isclose(calc_distance(LatLon(-60.0, 100.0), LatLon(-60.0, -150.0)), 5376.987893935466))
assert(travel(LatLon(-60.0, 100.0), 5376.987893935466, 141.04342059936801) == LatLon(-60.0, -150.0))

def test_travel_4_A_C():
# A -> C
def test_travel_4_a_c():
"""A -> C"""
assert(isclose(calc_bearing(LatLon(-60.0, 100.0), LatLon(-60.0, -30.0)), 208.30005243274795))
assert(isclose(calc_distance(LatLon(-60.0, 100.0), LatLon(-60.0, -30.0)), 5992.565597324029))
assert(travel(LatLon(-60.0, 100.0), 5992.565597324029, 208.30005243274795) == LatLon(-60.0, -30.0))

def test_travel_4_B_C():
# B -> C
def test_travel_4_b_c():
"""B -> C"""
assert(isclose(calc_bearing(LatLon(-60.0, -150.0), LatLon(-60.0, -30.0)), 146.30993247402023))
assert(isclose(calc_distance(LatLon(-60.0, -150.0), LatLon(-60.0, -30.0)), 5706.281104765322))
assert(travel(LatLon(-60.0, -150.0), 5706.281104765322, 146.30993247402023) == LatLon(-60.0, -30.0))

def test_travel_4_C_B():
# C -> B
def test_travel_4_c_b():
"""C -> B"""
assert(isclose(calc_bearing(LatLon(-60.0, -30.0), LatLon(-60.0, -150.0)), 213.69006752597977))
assert(isclose(calc_distance(LatLon(-60.0, -30.0), LatLon(-60.0, -150.0)), 5706.281104765322))
assert(travel(LatLon(-60.0, -30.0), 5706.281104765322, 213.69006752597977) == LatLon(-60.0, -150.0))
5 changes: 5 additions & 0 deletions tests/test_notify.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Test whether notifications aber being (not) triggered
around the boeder of the default radius"""

import notify

USER_SETTINGS = [
Expand Down Expand Up @@ -41,10 +44,12 @@


def test_positive():
"""Check whether notifications are being sent for all `POSITIVE` traces"""
notifications = notify.get_notifications(POSITIVE, USER_SETTINGS)
assert len(notifications) == 8


def test_negative():
"""Check whether no notifications are being sent for `NEGATIVE` traces"""
notifications = notify.get_notifications(NEGATIVE, USER_SETTINGS)
assert len(notifications) == 0

0 comments on commit 29c3c9c

Please sign in to comment.