]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/SummaryFile1Test.py
a29e208cf7fa91ee2bbc20ce186b9f01e1d63d02
1 import Tests
.Fixtures
, SummaryFile1
, GPS
, unittest
4 class BlockTest(unittest
.TestCase
):
6 def testAverageDensityIsFloat(self
):
8 We want to make sure no float->integer truncation
12 # Fill a GeoRecord with dummy values so that we
13 # can calculate its average population density.
14 gr
= SummaryFile1
.GeoRecord()
22 b
= SummaryFile1
.Block(gr
)
24 # Should be 100/(40 + 40), which is 1.25 when
25 # intepreted as a float.
26 self
.assertEqual(b
.population_density(), 1.25)
29 class GeoRecordParserTest(unittest
.TestCase
):
32 self
.grp
= SummaryFile1
.GeoRecordParser()
35 def testAllOfSubsetParsed(self
):
36 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/one_hundred_records.txt'
37 records
= self
.grp
.parse_file(fixture_path
)
38 self
.assertEqual(len(records
), 100)
41 def testSubsetOfBlocksParsed(self
):
42 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/one_hundred_records.txt'
43 blocks
= self
.grp
.parse_blocks(fixture_path
)
44 self
.assertEqual(len(blocks
), 62)
47 def testErrorParsingShortLines(self
):
48 self
.assertRaises(SummaryFile1
.RecordError
, self
.grp
.parse_line
, "This is a short line.")
51 def testMdGeoRecordCount(self
):
52 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
53 records
= self
.grp
.parse_file(fixture_path
)
54 self
.assertEqual(len(records
), 98763)
57 def testMdGeoBlockCount(self
):
58 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
59 blocks
= self
.grp
.parse_blocks(fixture_path
)
60 self
.assertEqual(len(blocks
), 79128)
63 class SummaryFile1Test(unittest
.TestCase
):
65 def testEachBlockIsClosestToItself(self
):
66 blocks_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
67 grp
= SummaryFile1
.GeoRecordParser()
68 blocks
= grp
.parse_blocks(blocks_path
)
70 # Only test 100 of these guys (or however many blocks there
71 # are in those 100 records.
72 fixtures_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/one_hundred_records.txt'
73 fixtures
= grp
.parse_blocks(fixtures_path
)
76 # It's probably unnecessary to copy the coordinates
77 # into a new instance here, but whatever.
78 b_coords
= GPS
.Coordinates()
79 b_coords
.latitude
= b
.coordinates
.latitude
80 b_coords
.longitude
= b
.coordinates
.longitude
82 closest_block
= SummaryFile1
.FindClosestBlock(blocks
, b_coords
)
83 self
.assertEqual(b
.block_number
, closest_block
.block_number
)
86 def testEachBlockHasItsOwnAverageDensity(self
):
87 geo_file_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
89 # Only test 5 of these guys; they take longer.
90 grp
= SummaryFile1
.GeoRecordParser()
91 fixtures_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/five_blocks.txt'
92 fixtures
= grp
.parse_blocks(fixtures_path
)
95 # It's probably unnecessary to copy the coordinates
96 # into a new instance here, but whatever.
97 avg_density
= SummaryFile1
.FindAveragePopulationDensity(b
.coordinates
, geo_file_path
)
98 self
.assertEqual(b
.population_density(), avg_density
)
102 suite
= unittest
.TestSuite()
103 suite
.addTest(unittest
.makeSuite(GeoRecordParserTest
))
104 suite
.addTest(unittest
.makeSuite(SummaryFile1Test
))
105 suite
.addTest(unittest
.makeSuite(BlockTest
))