From 58db4303063e6a2d4e785c3eca2e7050a890c985 Mon Sep 17 00:00:00 2001 From: John SJ Anderson Date: Fri, 12 Jul 2024 10:56:44 -0700 Subject: [PATCH] Add some unit tests for validate_records() [#1539] --- tests/io/test_curate_validate_records.py | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/io/test_curate_validate_records.py diff --git a/tests/io/test_curate_validate_records.py b/tests/io/test_curate_validate_records.py new file mode 100644 index 000000000..72f5083f4 --- /dev/null +++ b/tests/io/test_curate_validate_records.py @@ -0,0 +1,47 @@ +import pytest +from augur.curate import validate_records +from augur.errors import AugurError + + +@pytest.fixture +def good_records(): + return [ + {"geo_loc_name": "Canada/Vancouver"}, + {"geo_loc_name": "Canada/Vancouver"}, + ] + + +@pytest.fixture +def bad_records(): + return [ + {"geo_loc_name": "Canada/Vancouver"}, + {"geo_loc_name2": "Canada/Vancouver"}, + ] + + +class TestCurateValidateRecords: + def test_validate_input(self, good_records): + validated_records = validate_records(good_records, "test_subcmd", True) + assert list(validated_records) == good_records, "good input records validate" + + def test_validate_output(self, good_records): + validated_records = validate_records(good_records, "test_subcmd", False) + + assert list(validated_records) == good_records, "good output records validate" + + def test_validate_bad_records(self, bad_records): + with pytest.raises(AugurError) as e: + list(validate_records(bad_records, "test_subcmd", True)) + assert str(e.value).startswith( + "Records do not have the same fields!" + ), "bad input records throw exception with expected message" + + def test_validate_bad_output(self, bad_records): + with pytest.raises(AugurError) as e: + list(validate_records(bad_records, "test_subcmd", False)) + assert str(e.value).startswith( + "Records do not have the same fields!" + ), "bad output records throw exception with expected message" + assert ( + "test_subcmd" in str(e.value) + ), "bad output records throw exception with subcmd name in the message"