]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/CensusTest.py
Added unit tests for the Census.Database class.
[dead/census-tools.git] / src / Tests / Unit / CensusTest.py
1 import unittest
2
3 import Census
4 import Configuration.Defaults
5 import GPS
6 import SummaryFile1
7 import Tests.Fixtures
8
9
10 class DatabaseTest(unittest.TestCase):
11
12 def setUp(self):
13 self.cdb = Census.Database(Configuration.Defaults.DATABASE_HOST,
14 Configuration.Defaults.DATABASE_NAME,
15 Configuration.Defaults.DATABASE_USERNAME,
16 Configuration.Defaults.SRID)
17
18
19 def testEachBlockContainsItsOwnPopulation(self):
20 # These calculations are slightly off due to a discrepancy
21 # between the WKB/WKT format calculations. It would appear
22 # that converting from WKB to WKT and then back loses some
23 # information.
24 #
25 # The error is 1/100th of a person. Should be pretty safe.
26 error_threshold = 0.01
27
28 grp = SummaryFile1.GeoRecordParser()
29 fixtures_path = Tests.Fixtures.Path() + '/SummaryFile1/one_hundred_records.txt'
30 fixtures = grp.parse_blocks(fixtures_path)
31
32 for b in fixtures:
33 block_boundary = self.cdb.get_block_geometry_as_wkt(b.tiger_blkidfp00())
34 contained_population = self.cdb.find_contained_population(block_boundary)
35 error = abs(b.pop100 - contained_population)
36 self.assertTrue(error <= error_threshold)
37
38
39 def suite():
40 suite = unittest.TestSuite()
41 suite.addTest(unittest.makeSuite(DatabaseTest))
42 return suite
43