]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/SummaryFile1Test.py
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)
91 suite
= unittest
.TestSuite()
92 suite
.addTest(unittest
.makeSuite(GeoRecordParserTest
))
93 suite
.addTest(unittest
.makeSuite(BlockTest
))