]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/SummaryFile1Test.py
Added a unique index on the tiger_lines "tlid" column.
[dead/census-tools.git] / src / Tests / Unit / SummaryFile1Test.py
1 import unittest
2
3 import Tests.Fixtures
4 import SummaryFile1
5 import GPS
6 import StringUtils
7
8
9 class BlockTest(unittest.TestCase):
10
11 def setUp(self):
12 self.grp = SummaryFile1.GeoRecordParser()
13
14
15 def testOneAverageDensityIsFloat(self):
16 """
17 We want to make sure no float->integer truncation
18 is taking place.
19 """
20
21 # Fill a GeoRecord with dummy values so that we
22 # can calculate its average population density.
23 gr = SummaryFile1.GeoRecord()
24 gr.state = '24'
25 gr.county = '001'
26 gr.tract = '123456'
27 gr.block = '1728'
28 gr.pop100 = '100'
29 gr.arealand = '40'
30 gr.areawatr = '40'
31 gr.intptlat = '0'
32 gr.intptlon = '0'
33
34 b = SummaryFile1.Block(gr)
35
36 # Should be 100/(40 + 40), which is 1.25 when
37 # intepreted as a float.
38 self.assertEqual(b.population_density(), 1.25)
39
40
41
42 def testAllAverageDensitiesAreFloat(self):
43 """
44 Test every GeoRecord in the Maryland file, and make sure
45 all of the average densities can be parsed as floats.
46 """
47
48 fixture_path = Tests.Fixtures.Path() + '/SummaryFile1/mdgeo.uf1'
49 blocks = self.grp.parse_blocks(fixture_path)
50
51 for b in blocks:
52 self.assertTrue(StringUtils.is_float(b.population_density()))
53
54
55
56 class GeoRecordParserTest(unittest.TestCase):
57
58 def setUp(self):
59 self.grp = SummaryFile1.GeoRecordParser()
60
61
62 def testAllOfSubsetParsed(self):
63 fixture_path = Tests.Fixtures.Path() + '/SummaryFile1/one_hundred_records.txt'
64 records = self.grp.parse_file(fixture_path)
65 self.assertEqual(len(records), 100)
66
67
68 def testSubsetOfBlocksParsed(self):
69 fixture_path = Tests.Fixtures.Path() + '/SummaryFile1/one_hundred_records.txt'
70 blocks = self.grp.parse_blocks(fixture_path)
71 self.assertEqual(len(blocks), 62)
72
73
74 def testErrorParsingShortLines(self):
75 self.assertRaises(SummaryFile1.RecordError, self.grp.parse_line, "This is a short line.")
76
77
78 def testMdGeoRecordCount(self):
79 fixture_path = Tests.Fixtures.Path() + '/SummaryFile1/mdgeo.uf1'
80 records = self.grp.parse_file(fixture_path)
81 self.assertEqual(len(records), 98763)
82
83
84 def testMdGeoBlockCount(self):
85 fixture_path = Tests.Fixtures.Path() + '/SummaryFile1/mdgeo.uf1'
86 blocks = self.grp.parse_blocks(fixture_path)
87 self.assertEqual(len(blocks), 79128)
88
89
90 def suite():
91 suite = unittest.TestSuite()
92 suite.addTest(unittest.makeSuite(GeoRecordParserTest))
93 suite.addTest(unittest.makeSuite(BlockTest))
94 return suite
95