Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katybaulch committed Aug 28, 2024
1 parent 98e1c47 commit af90377
Showing 1 changed file with 49 additions and 19 deletions.
68 changes: 49 additions & 19 deletions tests/unit_tests/test_read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,57 @@

from gcf_data_mapper.read import read_data_file

print()
unit_tests_folder = os.path.dirname(os.path.abspath(__file__))
fixtures_folder = os.path.join(unit_tests_folder, "test_fixtures")

@pytest.fixture(
params=[
"tests/unit_tests/test_fixtures/test.json",
"tests/unit_tests/test_fixtures/test.csv",
]

def good_test_json():
"""Fixture to yield expected data structure based on file type.
what would you expected the output of read_data_file() to be with
the JSON data in your file read in?
return that data type with the above data in as the function would
be expected to output
"""
pass


def good_test_csv():
"""Fixture to yield expected data structure based on file type.
what would you expected the output of read_data_file() to be with
the following data read in?
country,capital,avg_temp_celsius,annual_rainfall_mm,climate_zone
Brazil,Brasilia,21.5,1500,Tropical
Canada,Ottawa,6.3,940,Continental
Egypt,Cairo,22.1,25,Desert
return that data type with the above data in as the function would
be expected to output
"""
pass


@pytest.mark.parametrize(
"filepath, expected_output",
(
(os.path.join(fixtures_folder, "test.json"), good_test_json()),
(os.path.join(fixtures_folder, "test.csv"), good_test_csv()),
),
)
def get_test_data(request):
"""Fixture to yield expected data structure based on file type."""
file_path = request.param
assert os.path.exists(file_path)
yield read_data_file(file_path)


def test_reads_files(get_test_data):
if isinstance(get_test_data, list):
data = read_data_file("tests/unit_tests/test_fixtures/test.csv")
assert get_test_data == data
elif isinstance(get_test_data, dict):
data = read_data_file("tests/unit_tests/test_fixtures/test.json")
assert get_test_data == data
def test_reads_files(filepath):
assert os.path.exists(filepath)
data = read_data_file(filepath)
assert data is not None
# if isinstance(get_test_data, list):
# data = read_data_file("tests/unit_tests/test_fixtures/test.csv")
# assert get_test_data == data
# elif isinstance(get_test_data, dict):
# data = read_data_file("tests/unit_tests/test_fixtures/test.json")
# assert get_test_data == data


def test_errors_on_invalid_file():
Expand Down

0 comments on commit af90377

Please sign in to comment.