import unittest import Census import SummaryFile1 import Tests.Fixtures class DatabaseTest(unittest.TestCase): def setUp(self): self.cdb = Census.Database() def testEachBlockContainsItsOwnPopulation(self): # These calculations are slightly off due to a discrepancy # between the WKB/WKT format calculations. It would appear # that converting from WKB to WKT and then back loses some # information. # # The error is 1/100th of a person. Should be pretty safe. error_threshold = 0.01 grp = SummaryFile1.GeoRecordParser() fixtures_path = Tests.Fixtures.Path() + '/SummaryFile1/one_hundred_records.txt' fixtures = grp.parse_blocks(fixtures_path) for b in fixtures: block_boundary = self.cdb.get_block_geometry_as_wkt(b.blkidfp00()) contained_population = self.cdb.find_contained_population(block_boundary) error = abs(b.pop100 - contained_population) self.assertTrue(error <= error_threshold) def suite(): # Tests that don't hit the database. suite = unittest.TestSuite() return suite def db_suite(): # The tests that hit the database. db_suite = unittest.TestSuite() db_suite.addTest(unittest.makeSuite(DatabaseTest)) return db_suite