Mercurial > hg > GlobalNeighbors
comparison tests/test_read.py @ 0:5dba84370182
initial commit; half-working prototype
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 12:03:39 -0700 |
parents | |
children | 1b94f3bf97e5 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5dba84370182 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 test data reading + loading | |
5 """ | |
6 | |
7 import os | |
8 import unittest | |
9 from globalneighbors import schema | |
10 from globalneighbors.read import read_tsv | |
11 | |
12 | |
13 here = os.path.dirname(os.path.abspath(__file__)) | |
14 data = os.path.join(here, 'data') | |
15 | |
16 class TestDataRead(unittest.TestCase): | |
17 | |
18 # created with | |
19 # head -n 10 cities1000.txt > GlobalNeighbors/tests/data/sample.tsv | |
20 test_tsv = os.path.join(data, 'sample.tsv') | |
21 test_tsv_lines = 10 | |
22 | |
23 # full dataset: test with caution | |
24 full_tsv = os.path.join(data, 'cities1000.txt') | |
25 full_tsv_lines = 149092 | |
26 | |
27 def test_read_tsv(self): | |
28 """test reading a tsv file chunk""" | |
29 | |
30 assert os.path.isfile(self.test_tsv) | |
31 sample = read_tsv(self.test_tsv) | |
32 | |
33 assert len(sample) == 10 | |
34 for row in sample: | |
35 assert len(row) == len(schema.descriptions) | |
36 | |
37 def test_full_dataset(self): | |
38 """ensure we can operate on the full dataset""" | |
39 | |
40 assert os.path.isfile(self.full_tsv) | |
41 cities = read_tsv(self.full_tsv) | |
42 assert len(cities) == self.full_tsv_lines | |
43 for row in cities: | |
44 assert len(row) == len(schema.descriptions) | |
45 | |
46 # cast the data into types we want | |
47 for row in cities: | |
48 row = schema.cast_row(row, types=schema.types) | |
49 | |
50 | |
51 if __name__ == '__main__': | |
52 unittest.main() |