-
Notifications
You must be signed in to change notification settings - Fork 23
/
test_get_historical_data.py
51 lines (39 loc) · 1.51 KB
/
test_get_historical_data.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
import pandas
import pytest
from utils import (
api,
DEFAULT_OUTPUT_FOLDER,
DEFAULT_OUTPUT_FILE,
SUPPORTED_OUTPUT_FORMATS,
)
# Filterwarnings from: https://stackoverflow.com/a/58645998/11316205
@pytest.mark.vcr
@pytest.mark.slow
@pytest.mark.filterwarnings("ignore::UserWarning")
def test_return_value_and_format():
result = api.get_historical_data(city="london")
assert isinstance(result, pandas.DataFrame)
@pytest.mark.vcr
@pytest.mark.slow
def test_warnings_on_input_combo():
with pytest.warns(UserWarning, match="city_id was not supplied"):
api.get_historical_data(city="london")
# There should be no warning if supplying city_id only
api.get_historical_data(city_id=5724)
# Warn user when both city and city_id are supplied
with pytest.warns(UserWarning, match="will be ignored"):
api.get_historical_data(city="london", city_id=5724)
def test_arguments_not_named():
with pytest.raises(ValueError, match="must be specified"):
api.get_historical_data("london")
@pytest.mark.vcr
@pytest.mark.slow
@pytest.mark.parametrize("fmt", SUPPORTED_OUTPUT_FORMATS)
@pytest.mark.filterwarnings("ignore::UserWarning")
def test_output_data_formats(fmt):
# Not specifying data format shouldn't create an output directory
api.get_historical_data(city_id=5724)
assert not DEFAULT_OUTPUT_FOLDER.exists()
# Check that output file is made
api.get_historical_data(city="london", data_format=fmt)
assert DEFAULT_OUTPUT_FILE.with_suffix(f".{fmt}").is_file()