Skip to content

Commit 79b002c

Browse files
author
ExpDev07
committed
cleanup
1 parent d6330e4 commit 79b002c

File tree

8 files changed

+71
-73
lines changed

8 files changed

+71
-73
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
__pycache__/
99
*.py[cod]
1010

11+
# Testing
12+
.pytest_cache/
13+
1114
# C extensions
1215
*.so
1316

tests/test_coordinates.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
from unittest import mock
21
import pytest
3-
2+
from unittest import mock
43
from app import coordinates
54

6-
@pytest.mark.parametrize("latitude, longitude",
7-
[("1", "2"),
8-
(100, "2"),
9-
(-3, 0),
10-
(-10, -10000000)])
5+
@pytest.mark.parametrize("latitude, longitude", [
6+
("1", "2"),
7+
(100, "2"),
8+
(-3, 0),
9+
(-10, -10000000)])
1110
def test_coordinates_class(latitude, longitude):
12-
coord_obj = coordinates.Coordinates(latitude=latitude,
13-
longitude=longitude)
11+
coord_obj = coordinates.Coordinates(latitude=latitude, longitude=longitude)
1412

1513
#validate serialize
16-
check_obj = {'latitude' : latitude,
17-
'longitude': longitude}
14+
check_obj = {
15+
'latitude' : latitude,
16+
'longitude': longitude
17+
}
1818

1919
assert coord_obj.serialize() == check_obj

tests/test_countrycodes.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import pytest
2-
32
from app.utils import countrycodes
43

54
"""
65
Todo:
76
* Test cases for capturing of stdout/stderr
87
"""
98

10-
@pytest.mark.parametrize("country_name,expected_country_code",
11-
[("Germany", "DE"),
12-
("Bolivia, Plurinational State of", "BO"),
13-
("Korea, Democratic People's Republic of", "KP"),
14-
("BlaBla", "XX")])
9+
@pytest.mark.parametrize("country_name,expected_country_code", [
10+
("Germany", "DE"),
11+
("Bolivia, Plurinational State of", "BO"),
12+
("Korea, Democratic People's Republic of", "KP"),
13+
("BlaBla", "XX")])
1514
def test_countrycodes_is_3166_1(country_name, expected_country_code):
1615
assert countrycodes.country_code(country_name) == expected_country_code
1716

18-
@pytest.mark.parametrize("country_name_synonym, expected_country_code",
19-
[("Deutschland", "DE"),
20-
("Iran (Islamic Republic of)", "IR"),
21-
("British Virgin Islands", "VG")])
17+
@pytest.mark.parametrize("country_name_synonym, expected_country_code", [
18+
("Deutschland", "DE"),
19+
("Iran (Islamic Republic of)", "IR"),
20+
("British Virgin Islands", "VG")])
2221
def test_countrycodes_synonym(country_name_synonym, expected_country_code):
2322
assert countrycodes.country_code(country_name_synonym) == expected_country_code

tests/test_date.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import pytest
2-
32
from app.utils import date
43

5-
6-
@pytest.mark.parametrize("str_date, fuzzy_bool, expected_value",
7-
[("1990-12-1", False, True),
8-
("2005/3", False, True),
9-
("Jan 19, 1990", False, True),
10-
("today is 2019-03-27", False, False),
11-
("Monday at 12:01am", False, True),
12-
("xyz_not_a_date", False, False),
13-
("yesterday", False, False),
14-
("today is 2019-03-27", True, True)])
4+
@pytest.mark.parametrize("str_date, fuzzy_bool, expected_value", [
5+
("1990-12-1", False, True),
6+
("2005/3", False, True),
7+
("Jan 19, 1990", False, True),
8+
("today is 2019-03-27", False, False),
9+
("Monday at 12:01am", False, True),
10+
("xyz_not_a_date", False, False),
11+
("yesterday", False, False),
12+
("today is 2019-03-27", True, True)])
1513
def test_is_date(str_date, fuzzy_bool, expected_value):
1614
"""
1715
Testdata from https://stackoverflow.com/a/25341965/7120095

tests/test_jhu.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from unittest import mock
1+
import app
22
import datetime
33
import pytest
4-
5-
import app
4+
from unittest import mock
65
from app.utils import date
76
from app import location
87
from app.services.location import jhu
@@ -21,7 +20,6 @@ def __init__(self, url, filename, state):
2120
self.state = state
2221
self.text = self.read_file(self.state)
2322

24-
2523
def read_file(self, state):
2624
"""
2725
Mock HTTP GET-method and return text from file
@@ -33,8 +31,10 @@ def read_file(self, state):
3331

3432
#get url from `request.get`
3533
url = args[0]
34+
3635
#get filename from url
3736
filename = url.split("/")[-1]
37+
3838
#clean up for id token (e.g. Deaths)
3939
state = filename.split("-")[-1].replace(".csv", "").lower().capitalize()
4040

@@ -58,16 +58,15 @@ def isoformat(self):
5858

5959
return DateTimeStrpTime(date, strformat)
6060

61-
@pytest.mark.parametrize("category, capitalize_category",
62-
[("deaths", "Deaths"),
63-
("recovered", "Recovered"),
64-
("confirmed", "Confirmed")])
61+
@pytest.mark.parametrize("category, capitalize_category", [
62+
("deaths", "Deaths"),
63+
("recovered", "Recovered"),
64+
("confirmed", "Confirmed")])
6565
@mock.patch('app.services.location.jhu.requests.get', side_effect=mocked_requests_get)
6666
def test_validate_category(mock_request_get, category, capitalize_category):
67-
base_url = 'https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/\
68-
master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-%s.csv'
69-
67+
base_url = 'https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-%s.csv'
7068
request = app.services.location.jhu.requests.get(base_url % category)
69+
7170
assert request.state == capitalize_category
7271

7372
@pytest.mark.parametrize("category, datetime_str, latest_value, country_name, \

tests/test_location.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from unittest import mock
21
import pytest
3-
4-
from app import (location, coordinates, timeline)
2+
from unittest import mock
3+
from app import location, coordinates, timeline
54

65
def mocked_timeline(*args, **kwargs):
76
class TestTimeline:

tests/test_routes.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
import app
12
import unittest
2-
from unittest import mock
33
import json
4-
5-
import app
4+
from unittest import mock
65
from app import services
76

8-
from .test_jhu import (mocked_requests_get, mocked_strptime_isoformat,
9-
DATETIME_STRING)
7+
from .test_jhu import mocked_requests_get, mocked_strptime_isoformat, DATETIME_STRING
108

119
@mock.patch('app.services.location.jhu.datetime')
1210
@mock.patch('app.services.location.jhu.requests.get', side_effect=mocked_requests_get)
@@ -17,7 +15,7 @@ class FlaskRoutesTest(unittest.TestCase):
1715
Store all integration testcases in one class to ensure app context
1816
"""
1917

20-
#load app context only once
18+
#load app context only once.
2119
app = app.create_app()
2220

2321
def setUp(self):
@@ -97,11 +95,9 @@ def test_v2_locations_id(self, mock_request_get, mock_datetime):
9795

9896
state = "locations"
9997
test_id = 1
100-
return_data = self.client.get("/v2/{}/{}".format(state, test_id)) \
101-
.data.decode()
98+
return_data = self.client.get("/v2/{}/{}".format(state, test_id)).data.decode()
10299

103-
filepath = "tests/expected_output/v2_{state}_id_{test_id}.json".format(state=state,
104-
test_id=test_id)
100+
filepath = "tests/expected_output/v2_{state}_id_{test_id}.json".format(state=state, test_id=test_id)
105101
with open(filepath, "r") as file:
106102
expected_json_output = file.read()
107103

tests/test_timeline.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1+
import pytest
12
from unittest import mock
23
from collections import OrderedDict
3-
import pytest
4-
54
from app import timeline
65

76
def test_timeline_class():
8-
#unordered series
9-
timeseries = {'1/24/20': 5,
10-
'1/22/20': 2,
11-
'1/25/20': 7,
12-
'1/23/20': 3}
7+
# Unordered timeseries.
8+
timeseries = {
9+
'1/24/20': 5,
10+
'1/22/20': 2,
11+
'1/25/20': 7,
12+
'1/23/20': 3,
13+
}
1314

1415
history_data = timeline.Timeline(history=timeseries)
1516

16-
#validate last value
17+
# validate last value
1718
assert history_data.latest == 7
1819

19-
#validate order
20-
assert list(dict(history_data.timeline).keys()) \
21-
== ['1/22/20', '1/23/20', '1/24/20', '1/25/20']
20+
# validate order
21+
assert list(dict(history_data.timeline).keys()) == ['1/22/20', '1/23/20', '1/24/20', '1/25/20']
2222

23-
#validate serialize
24-
check_serialize = {'latest': 7,
25-
'timeline': OrderedDict([('1/22/20', 2),
26-
('1/23/20', 3),
27-
('1/24/20', 5),
28-
('1/25/20', 7)])}
23+
# validate serialize
24+
check_serialize = {
25+
'latest': 7,
26+
'timeline': OrderedDict([
27+
('1/22/20', 2),
28+
('1/23/20', 3),
29+
('1/24/20', 5),
30+
('1/25/20', 7),
31+
])
32+
}
2933

3034
assert dict(history_data.serialize()) == check_serialize

0 commit comments

Comments
 (0)