From 120e8cf09fb1dd31dce779124b0c9a1f1488233e Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Wed, 8 Dec 2021 15:18:50 +0200 Subject: [PATCH] tests/test_check.py: add checks for countries without regions --- tests/test_check.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test_check.py b/tests/test_check.py index d96e3fe..ef2bd00 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -438,3 +438,43 @@ def test_title_not_in_citation(capsys): captured.out == f"{Fore.YELLOW}Title is not present in citation: {Fore.RESET}{title}\n" ) + + +def test_country_matches_region(): + """Test an item with regions matching its country list.""" + + country = "Kenya" + region = "Eastern Africa" + + # Emulate a column in a transposed dataframe (which is just a series) + d = {"cg.coverage.country": country, "cg.coverage.region": region} + series = pd.Series(data=d) + + result = check.countries_match_regions(series) + + assert result == None + + +def test_country_not_matching_region(capsys): + """Test an item with regions not matching its country list.""" + + title = "Testing an item with no matching region." + country = "Kenya" + region = "" + missing_region = "Eastern Africa" + + # Emulate a column in a transposed dataframe (which is just a series) + d = { + "dc.title": title, + "cg.coverage.country": country, + "cg.coverage.region": region, + } + series = pd.Series(data=d) + + check.countries_match_regions(series) + + captured = capsys.readouterr() + assert ( + captured.out + == f"{Fore.YELLOW}Missing region ({missing_region}): {Fore.RESET}{title}\n" + )