-
Notifications
You must be signed in to change notification settings - Fork 23
/
test_get_multiple_coordinate_air.py
76 lines (61 loc) · 1.94 KB
/
test_get_multiple_coordinate_air.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import numpy
import pandas
import pandas.api.types as pd_types
import pytest
from utils import api
COORDS = [(0, 0), (50, 0), (40, -75)]
@pytest.mark.vcr
def test_return_value_and_format():
result = api.get_multiple_coordinate_air(COORDS)
# Check return value and format
assert isinstance(result, pandas.DataFrame)
assert len(result) == len(COORDS)
@pytest.mark.vcr
def test_column_expected_contents():
result = api.get_multiple_coordinate_air(COORDS)
# Coordinate was given, so city should be nan
assert numpy.isnan(result["city"]).all()
@pytest.mark.vcr
def test_column_types():
result = api.get_multiple_coordinate_air(COORDS)
STR_COLUMNS = [
"dominant_pollutant",
"AQI_meaning",
"AQI_health_implications",
"timestamp",
"timestamp_timezone",
]
FLOAT_COLUMNS = [
"latitude",
"longitude",
"aqi",
"pm2.5",
"pm10",
"o3",
"co",
"no2",
"so2",
"dew",
"h",
"p",
"t",
"w",
"wg",
]
assert all([pd_types.is_string_dtype(result[col]) for col in STR_COLUMNS])
assert all([pd_types.is_float_dtype(result[col]) for col in FLOAT_COLUMNS])
@pytest.mark.vcr
def test_bad_coordinates():
# NOTE, ???
# See test_get_multiple_city_air, same issue
BAD_COORDS = [(50, 0), (50, 1), ("lol", "bruh"), ("50.805778", "0.271611")]
result = api.get_multiple_coordinate_air(BAD_COORDS)
# Lat-lon columns should remain float even when given bad coords
assert pd_types.is_float_dtype(result["latitude"])
assert pd_types.is_float_dtype(result["longitude"])
# Rows with bad coord should have nan entire row
assert result.iloc[2, :].isna().all()
# Rows with float-able string should be float, because
# WAQI supports such operation on their backend
assert result.at[3, "latitude"] == 50.805778
assert result.at[3, "longitude"] == 0.271611