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 tests suite #120

Merged
merged 18 commits into from
Apr 22, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: Add tests for get_historical_data
  • Loading branch information
lahdjirayhan committed Apr 21, 2022
commit 472f33d656c4ccf6db62978378656620bde9212f
47 changes: 47 additions & 0 deletions tests/test_get_historical_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pandas
import pytest

from utils import api, DEFAULT_OUTPUT_FOLDER, DEFAULT_OUTPUT_FILE


@pytest.mark.vcr
@pytest.mark.filterwarnings(
"ignore::UserWarning"
) # https://stackoverflow.com/a/58645998/11316205
def test_return_value_and_format():
result = api.get_historical_data(city="london")
assert isinstance(result, pandas.DataFrame)


@pytest.mark.vcr
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.filterwarnings("ignore::UserWarning")
def test_correct_data_format():
# There shouldn't be an output folder by default
assert not DEFAULT_OUTPUT_FOLDER.exists()

# 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
for fmt in ["xlsx", "csv", "json"]:
api.get_historical_data(city="london", data_format=fmt)
assert DEFAULT_OUTPUT_FILE.with_suffix(f".{fmt}").is_file()