Mercurial > hg > GlobalNeighbors
comparison tests/test_read.py @ 3:49aae0c0293b
improved test coverage
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 14:48:31 -0700 |
parents | 1b94f3bf97e5 |
children |
comparison
equal
deleted
inserted
replaced
2:50ee13cddf58 | 3:49aae0c0293b |
---|---|
5 """ | 5 """ |
6 | 6 |
7 import os | 7 import os |
8 import unittest | 8 import unittest |
9 from globalneighbors import schema | 9 from globalneighbors import schema |
10 from globalneighbors.locations import locations | |
10 from globalneighbors.read import read_tsv | 11 from globalneighbors.read import read_tsv |
12 from globalneighbors.read import read_cities | |
11 from globalneighbors.read import read_city_list | 13 from globalneighbors.read import read_city_list |
12 | 14 |
13 | 15 |
14 here = os.path.dirname(os.path.abspath(__file__)) | 16 here = os.path.dirname(os.path.abspath(__file__)) |
15 data = os.path.join(here, 'data') | 17 data = os.path.join(here, 'data') |
50 | 52 |
51 def test_read_unicode(self): | 53 def test_read_unicode(self): |
52 """ensure we can read the cities as unicode""" | 54 """ensure we can read the cities as unicode""" |
53 | 55 |
54 cities = read_city_list(self.full_tsv) | 56 cities = read_city_list(self.full_tsv) |
57 for city in cities: | |
58 for field in schema.unicode_fields: | |
59 assert isinstance(city[field], unicode) | |
60 | |
61 def test_iterative_locations(self): | |
62 """assert we can read into locations as a generator""" | |
63 | |
64 with open(self.test_tsv) as f: | |
65 cities = locations(read_cities(f)) | |
66 for geonameid, (lat, lon) in cities.items(): | |
67 assert -90. <= lat <= 90. | |
68 assert -180. <= lon <= 180. | |
69 assert type(geonameid) == schema.types['geonameid'] | |
55 | 70 |
56 | 71 |
57 if __name__ == '__main__': | 72 if __name__ == '__main__': |
58 unittest.main() | 73 unittest.main() |