-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add tests suite #120
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
19520f3
test: Add test dependencies
lahdjirayhan e104d5d
test: Add initial setup for test files
lahdjirayhan 7ba5a2f
test: Add tests for get_city_air
lahdjirayhan 421eb16
test: Add tests for get_city_forecast
lahdjirayhan 8c9b01f
test: Add tests for get_city_station_options
lahdjirayhan 489abf1
test: Add tests for get_coordinate_air.py
lahdjirayhan 472f33d
test: Add tests for get_historical_data
lahdjirayhan e94e41a
Save VCR cassettes into source control
lahdjirayhan d9be5d0
test: Add tests for get_multiple_city_air
lahdjirayhan 3098ee1
test: Add tests for get_multiple_coordinate_air
lahdjirayhan 7690a7e
test: Add tests for get_range_coordinates_air
lahdjirayhan 29995e5
test: Add tests for get_specific_parameter
lahdjirayhan d46809c
test: Ensure no output folder is present at beginning of each test
lahdjirayhan 19e151c
test: Move definition of DEFAULT_OUTPUT_FOLDER down
lahdjirayhan b66277f
test: Save more VCR cassettes into source control
lahdjirayhan 6c88e35
test: Update tests to better reflect real conditions
lahdjirayhan 4f5e2ca
test: Fix typo
lahdjirayhan c303611
docs: Add writeup for test instructions etc
lahdjirayhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: Add tests for get_range_coordinates_air
- Loading branch information
commit 7690a7e1e880de23dcc44e84520943ff01c67f51
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import numpy | ||
import pandas | ||
import pandas.api.types as pd_types | ||
import pytest | ||
|
||
from utils import api, DEFAULT_OUTPUT_FOLDER, DEFAULT_OUTPUT_FILE | ||
|
||
LOWER_BOUND = (51, -0.2) | ||
UPPER_BOUND = (52, 1) | ||
|
||
|
||
@pytest.mark.vcr | ||
def test_return_value_and_format(): | ||
result = api.get_range_coordinates_air(LOWER_BOUND, UPPER_BOUND) | ||
|
||
# Check return value and format | ||
assert isinstance(result, pandas.DataFrame) | ||
assert len(result) > 0 # Should be 32, actually | ||
|
||
|
||
@pytest.mark.vcr | ||
def test_column_expected_contents(): | ||
result = api.get_range_coordinates_air(LOWER_BOUND, UPPER_BOUND) | ||
|
||
# Sanity check: make sure lat-lon are within range | ||
assert (result["latitude"] > LOWER_BOUND[0]).all() | ||
assert (result["latitude"] < UPPER_BOUND[0]).all() | ||
assert (result["longitude"] < LOWER_BOUND[1]).all() | ||
assert (result["longitude"] > UPPER_BOUND[1]).all() | ||
|
||
# Range of coordinates: no city was given, hence city must all be nan | ||
assert numpy.isnan(result["city"]).all() | ||
|
||
|
||
@pytest.mark.vcr | ||
def test_column_types(): | ||
result = api.get_range_coordinates_air(LOWER_BOUND, UPPER_BOUND) | ||
STR_COLUMNS = [ | ||
"dominant_pollutant", | ||
"AQI_meaning", | ||
"AQI_health_implications", | ||
"timestamp", | ||
"timestamp_timezone", | ||
] | ||
FLOAT_COLUMNS = [ | ||
"latitude", | ||
"longitude", | ||
"aqi", | ||
"pm25", | ||
"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_excluded_params(): | ||
# Param should be really excluded when specified as such | ||
custom_params = ["aqi", "pm25", "o3"] | ||
result = api.get_range_coordinates_air( | ||
LOWER_BOUND, UPPER_BOUND, params=custom_params | ||
) | ||
assert "pm10" not in result | ||
assert "pm25" in result | ||
|
||
|
||
@pytest.mark.vcr | ||
def test_nonexistent_requested_params(): | ||
# Return asked params even when the response does not contain that specific param | ||
BAD_PARAM_NAME = "param_that_is_not_in_london_aqi" | ||
result = api.get_range_coordinates_air( | ||
LOWER_BOUND, UPPER_BOUND, params=[BAD_PARAM_NAME] | ||
) | ||
param_value = result.at[0, BAD_PARAM_NAME] | ||
assert numpy.isnan(param_value) | ||
|
||
|
||
@pytest.mark.vcr | ||
def test_bad_coordinates(): | ||
with pytest.raises(Exception): | ||
api.get_range_coordinates_air(lower_bound=("lol", "bruh"), upper_bound=(0, 0)) | ||
|
||
|
||
@pytest.mark.vcr | ||
def test_bad_data_format(): | ||
with pytest.raises(Exception, match="Invalid file format"): | ||
api.get_range_coordinates_air( | ||
LOWER_BOUND, UPPER_BOUND, data_format="a definitely wrong data format" | ||
) | ||
|
||
# Calling wrong data format shouldn't create an output folder | ||
assert not DEFAULT_OUTPUT_FOLDER.exists() | ||
|
||
|
||
@pytest.mark.vcr | ||
def test_output_formats(): | ||
# 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_range_coordinates_air(LOWER_BOUND, UPPER_BOUND) | ||
assert not DEFAULT_OUTPUT_FOLDER.exists() | ||
|
||
# Check that output file is made | ||
for fmt in ["xlsx", "csv", "json"]: | ||
api.get_range_coordinates_air(LOWER_BOUND, UPPER_BOUND, data_format=fmt) | ||
assert DEFAULT_OUTPUT_FILE.with_suffix(f".{fmt}").is_file() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hahahaha 'lol' and 'bruh'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So ... hehe.