]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/SummaryFile1Test.py
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()
25 b
= SummaryFile1
.Block(gr
)
27 # Should be 100/(40 + 40), which is 1.25 when
28 # intepreted as a float.
29 self
.assertEqual(b
.population_density(), 1.25)
32 class GeoRecordParserTest(unittest
.TestCase
):
35 self
.grp
= SummaryFile1
.GeoRecordParser()
38 def testAllOfSubsetParsed(self
):
39 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/one_hundred_records.txt'
40 records
= self
.grp
.parse_file(fixture_path
)
41 self
.assertEqual(len(records
), 100)
44 def testSubsetOfBlocksParsed(self
):
45 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/one_hundred_records.txt'
46 blocks
= self
.grp
.parse_blocks(fixture_path
)
47 self
.assertEqual(len(blocks
), 62)
50 def testErrorParsingShortLines(self
):
51 self
.assertRaises(SummaryFile1
.RecordError
, self
.grp
.parse_line
, "This is a short line.")
54 def testMdGeoRecordCount(self
):
55 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
56 records
= self
.grp
.parse_file(fixture_path
)
57 self
.assertEqual(len(records
), 98763)
60 def testMdGeoBlockCount(self
):
61 fixture_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
62 blocks
= self
.grp
.parse_blocks(fixture_path
)
63 self
.assertEqual(len(blocks
), 79128)
66 class SummaryFile1Test(unittest
.TestCase
):
68 def testEachBlockIsClosestToItself(self
):
69 blocks_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
70 grp
= SummaryFile1
.GeoRecordParser()
71 blocks
= grp
.parse_blocks(blocks_path
)
73 # Only test 100 of these guys (or however many blocks there
74 # are in those 100 records.
75 fixtures_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/one_hundred_records.txt'
76 fixtures
= grp
.parse_blocks(fixtures_path
)
79 # It's probably unnecessary to copy the coordinates
80 # into a new instance here, but whatever.
81 b_coords
= GPS
.Coordinates()
82 b_coords
.latitude
= b
.coordinates
.latitude
83 b_coords
.longitude
= b
.coordinates
.longitude
85 closest_block
= SummaryFile1
.FindClosestBlock(blocks
, b_coords
)
86 self
.assertEqual(b
.block
, closest_block
.block
)
89 def testEachBlockHasItsOwnAverageDensity(self
):
90 geo_file_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/mdgeo.uf1'
92 # Only test 5 of these guys; they take longer.
93 grp
= SummaryFile1
.GeoRecordParser()
94 fixtures_path
= Tests
.Fixtures
.Path() + '/SummaryFile1/five_blocks.txt'
95 fixtures
= grp
.parse_blocks(fixtures_path
)
98 # It's probably unnecessary to copy the coordinates
99 # into a new instance here, but whatever.
100 avg_density
= SummaryFile1
.FindAveragePopulationDensity(b
.coordinates
, geo_file_path
)
101 self
.assertEqual(b
.population_density(), avg_density
)
105 suite
= unittest
.TestSuite()
106 suite
.addTest(unittest
.makeSuite(GeoRecordParserTest
))
107 suite
.addTest(unittest
.makeSuite(SummaryFile1Test
))
108 suite
.addTest(unittest
.makeSuite(BlockTest
))