|
| 1 | +from collections import defaultdict |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from names import group_names_by_country, data |
| 6 | + |
| 7 | +# another output to test with |
| 8 | +data2 = """last_name,first_name,country_code |
| 9 | +Poxton,Sydney,CZ |
| 10 | +Kynman,Bryant,NL |
| 11 | +Mockler,Leese,AF |
| 12 | +Gillicuddy,Raffaello,IR |
| 13 | +Renyard,Carlo,CO |
| 14 | +Beadham,Evonne,CZ |
| 15 | +Tunstall,Allissa,IR |
| 16 | +Kamenar,Augy,IR |
| 17 | +Insko,Ave,NL |
| 18 | +Pigney,Gavrielle,ID""" |
| 19 | + |
| 20 | + |
| 21 | +@pytest.fixture |
| 22 | +def grouping1(): |
| 23 | + return group_names_by_country(data) |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture |
| 27 | +def grouping2(): |
| 28 | + return group_names_by_country(data2) |
| 29 | + |
| 30 | + |
| 31 | +def test_return_type(grouping1, grouping2): |
| 32 | + assert type(grouping1) == defaultdict |
| 33 | + assert type(grouping2) == defaultdict |
| 34 | + |
| 35 | + |
| 36 | +def test_return_dict_len(grouping1, grouping2): |
| 37 | + assert len(grouping1) == 7 |
| 38 | + assert len(grouping2) == 6 |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.parametrize('key, expected', [ |
| 42 | + ('BR', ['Alphonso Harrold']), |
| 43 | + ('CN', ['Davie Halbard', 'Ines Parrett', 'Margo Apdell']), |
| 44 | + ('ID', ['Husain Watsham', 'Sula Wasielewski']), |
| 45 | + ('PL', ['Kermit Braunle']), |
| 46 | + ('RU', ['Deerdre Tomblings']), |
| 47 | + ('SE', ['Luke Brenston']), |
| 48 | + ('TD', ['Rudolph Jeffry']), |
| 49 | +]) |
| 50 | +def test_grouping1_return(grouping1, key, expected): |
| 51 | + assert sorted(grouping1[key]) == expected |
| 52 | + |
| 53 | + |
| 54 | +@pytest.mark.parametrize('key, expected', [ |
| 55 | + ('AF', ['Leese Mockler']), |
| 56 | + ('CO', ['Carlo Renyard']), |
| 57 | + ('CZ', ['Evonne Beadham', 'Sydney Poxton']), |
| 58 | + ('ID', ['Gavrielle Pigney']), |
| 59 | + ('IR', ['Allissa Tunstall', 'Augy Kamenar', 'Raffaello Gillicuddy']), |
| 60 | + ('NL', ['Ave Insko', 'Bryant Kynman']), |
| 61 | +]) |
| 62 | +def test_grouping2_return(grouping2, key, expected): |
| 63 | + assert sorted(grouping2[key]) == expected |
| 64 | + |
| 65 | +test_grouping1_return |
| 66 | +test_grouping2_return |
0 commit comments