Skip to content

Commit

Permalink
Add some unit tests for validate_records() [#1539]
Browse files Browse the repository at this point in the history
  • Loading branch information
genehack committed Jul 12, 2024
1 parent 790dcdc commit e535507
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/io/test_curate_validate_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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):
try:
list(validate_records(bad_records, "test_subcmd", True))
assert 1 == 0, "this should never be reached because the previous line should throw"
except AugurError as e:
assert str(e).startswith(
"Records do not have the same fields!"
), "bad input records throw exception with expected message"

def test_validate_bad_output(self, bad_records):
try:
list(validate_records(bad_records, "test_subcmd", False))
assert 1 == 0, "this should never be reached because the previous line should throw"
except AugurError as e:
assert str(e).startswith(
"Records do not have the same fields!"
), "bad output records throw exception with expected message"
assert(
"test_subcmd" in str(e)
), "bad output records throw exception with subcmd name in the message"

0 comments on commit e535507

Please sign in to comment.