]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - SummaryFile1Test.py
18825dde9c10d3ced05cade2364173948c70d0b2
9 class BlockTest(unittest
.TestCase
):
12 self
.grp
= SummaryFile1
.GeoRecordParser()
15 def testOneAverageDensityIsFloat(self
):
17 We want to make sure no float->integer truncation
21 # Fill a GeoRecord with dummy values so that we
22 # can calculate its average population density.
23 gr
= SummaryFile1
.GeoRecord()
34 b
= SummaryFile1
.Block(gr
)
36 # Should be 100/(40 + 40), which is 1.25 when
37 # intepreted as a float.
38 self
.assertEqual(b
.population_density(), 1.25)
42 def testAllAverageDensitiesAreFloat(self
):
44 Test every GeoRecord in the Maryland file, and make sure
45 all of the average densities can be parsed as floats.
48 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
49 blocks
= self
.grp
.parse_blocks(fixture_path
)
52 self
.assertTrue(StringUtils
.is_float(b
.population_density()))
56 class GeoRecordParserTest(unittest
.TestCase
):
59 self
.grp
= SummaryFile1
.GeoRecordParser()
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)
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)
74 def testErrorParsingShortLines(self
):
75 self
.assertRaises(SummaryFile1
.RecordError
, self
.grp
.parse_line
, "This is a short line.")
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)
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)
90 class SummaryFile1Test(unittest
.TestCase
):
92 def testEachBlockIsClosestToItself(self
):
93 blocks_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
94 grp
= SummaryFile1
.GeoRecordParser()
95 blocks
= grp
.parse_blocks(blocks_path
)
97 # Only test 100 of these guys (or however many blocks there
98 # are in those 100 records.
99 fixtures_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/one_hundred_records.txt'
100 fixtures
= grp
.parse_blocks(fixtures_path
)
103 # It's probably unnecessary to copy the coordinates
104 # into a new instance here, but whatever.
105 b_coords
= GPS
.Coordinates()
106 b_coords
.latitude
= b
.coordinates
.latitude
107 b_coords
.longitude
= b
.coordinates
.longitude
109 closest_block
= SummaryFile1
.FindClosestBlock(blocks
, b_coords
)
110 self
.assertEqual(b
.block
, closest_block
.block
)
113 def testEachBlockHasItsOwnAverageDensity(self
):
114 geo_file_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
116 # Only test 5 of these guys; they take longer.
117 grp
= SummaryFile1
.GeoRecordParser()
118 fixtures_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/five_blocks.txt'
119 fixtures
= grp
.parse_blocks(fixtures_path
)
122 # It's probably unnecessary to copy the coordinates
123 # into a new instance here, but whatever.
124 avg_density
= SummaryFile1
.FindAveragePopulationDensity(b
.coordinates
, geo_file_path
)
125 self
.assertEqual(b
.population_density(), avg_density
)
129 suite
= unittest
.TestSuite()
130 suite
.addTest(unittest
.makeSuite(GeoRecordParserTest
))
131 suite
.addTest(unittest
.makeSuite(SummaryFile1Test
))
132 suite
.addTest(unittest
.makeSuite(BlockTest
))