-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
152 lines (134 loc) · 3.89 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import yaml
import itertools
import json
import pprint
from deepdiff import DeepDiff
from unittest import TestCase
from collections import Counter
class BaseTests(TestCase):
@staticmethod
def dump(data, stop=True):
print(json.dumps(data, indent=True))
if stop:
raise
def assertDictEqual(self, before, after):
diff = DeepDiff(before, after, ignore_order=True)
if diff:
pprint.pprint(diff)
return self.assertTrue(False)
return self.assertTrue(True)
class LocationTests(BaseTests):
"""
Location Tests
"""
def setUp(self) -> None:
self.locations = yaml.load(open('locations.yaml'), Loader=yaml.Loader)
def test_nz(self):
items = {k: v for k, v in self.locations.items() if any(c for c in v.values() if c['iso'] == 'NZL')}
# self.dump(items)
self.assertDictEqual(
{
64: {
"New Zealand": {
"iso": "NZL",
"aliases": []
},
"Pitcairn": {
"iso": "PCN",
"aliases": []
}
},
64240: {
"Scott Base (New Zealand)": {
"iso": "NZL",
"aliases": [
"Scott Base",
"NEW ZEALAND Scott Base"
]
}
}
},
items
)
def test_duplicate_codes(self):
items = {k: list(v.keys()) for k, v in self.locations.items() if len(v) > 1}
# self.dump(items)
self.assertDictEqual(
{
1: [
"Canada",
"USA"
],
212: [
"Morocco",
"Western Sahara"
],
246: [
"British Indian Ocean Territory",
"Diego Garcia"
],
262: [
"Mayotte",
"Reunion"
],
358: [
"Finland",
"Aland Islands"
],
590: [
"Saint Barthelemy",
"Saint Martin",
"Guadeloupe"
],
599: [
"Curacao",
"Caribbean Netherlands"
],
61891: [
"Christmas Island",
"Cocos Islands"
],
64: [
"New Zealand",
"Pitcairn"
]
},
items
)
def test_duplicate_countries(self):
countries = [k for k, count in Counter(itertools.chain(*[v for k, v in self.locations.items()])).items() if
count > 1]
items = {k: list(v.keys()) for k, v in self.locations.items() if any(x for x in v if x in countries)}
# self.dump(items)
self.assertDictEqual(
{
1658: [
"Jamaica"
],
1787: [
"Puerto Rico"
],
1809: [
"Dominican Republic"
],
1829: [
"Dominican Republic"
],
1849: [
"Dominican Republic"
],
1876: [
"Jamaica"
],
1939: [
"Puerto Rico"
],
76: [
"Kazakhstan"
],
77: [
"Kazakhstan"
]
},
items
)