def test_generates_the_correct_blocks(self): self.splitter = job.BlockSplitter((SITE, SITE, SITE), 3) expected_blocks = (job.Block((SITE, SITE, SITE)), ) self._assert_blocks_are(expected_blocks) self.splitter = job.BlockSplitter((SITE, SITE, SITE), 2) expected_blocks = (job.Block((SITE, SITE)), job.Block((SITE, ))) self._assert_blocks_are(expected_blocks)
def test_splitting_with_region_intersection(self): region_constraint = shapes.RegionConstraint.from_simple((0.0, 0.0), (2.0, 2.0)) sites = (shapes.Site(1.0, 1.0), shapes.Site(1.5, 1.5), shapes.Site(2.0, 2.0), shapes.Site(3.0, 3.0)) expected_blocks = (job.Block( (shapes.Site(1.0, 1.0), shapes.Site(1.5, 1.5))), job.Block((shapes.Site(2.0, 2.0), ))) self.splitter = job.BlockSplitter(sites, 2, constraint=region_constraint) self._assert_blocks_are(expected_blocks)
def test_prepares_blocks_using_the_input_region(self): """ This test might be currently catastrophically retarded. If it is blame Lars. """ block_path = test.do_test_file(BLOCK_SPLIT_TEST_FILE) print "In open job" a_job = Job.from_file(block_path) self.generated_files.append(a_job.super_config_path) verts = [float(x) for x in a_job.params['REGION_VERTEX'].split(",")] # Flips lon and lat, and builds a list of coord tuples coords = zip(verts[1::2], verts[::2]) expected = shapes.RegionConstraint.from_coordinates(coords) expected.cell_size = float(a_job.params['REGION_GRID_SPACING']) expected_sites = [] for site in expected: print site expected_sites.append(site) a_job._partition() blocks_keys = a_job.blocks_keys print blocks_keys self.assertEqual(1, len(blocks_keys)) self.assertEqual(job.Block(expected_sites), job.Block.from_kvs(blocks_keys[0]))
def test_prepares_blocks_using_the_exposure(self): a_job = Job({ EXPOSURE: os.path.join(test.SCHEMA_EXAMPLES_DIR, EXPOSURE_TEST_FILE) }) a_job._partition() blocks_keys = a_job.blocks_keys expected_block = job.Block( (shapes.Site(9.15000, 45.16667), shapes.Site(9.15333, 45.12200), shapes.Site(9.14777, 45.17999))) self.assertEqual(1, len(blocks_keys)) self.assertEqual(expected_block, job.Block.from_kvs(blocks_keys[0]))
def test_prepares_blocks_using_the_exposure_and_filtering(self): a_job = Job({ EXPOSURE: os.path.join(test.SCHEMA_EXAMPLES_DIR, EXPOSURE_TEST_FILE), INPUT_REGION: test.do_test_file(REGION_EXPOSURE_TEST_FILE) }) self.generated_files.append(a_job.super_config_path) a_job._partition() blocks_keys = a_job.blocks_keys expected_block = job.Block( (shapes.Site(9.15, 45.16667), shapes.Site(9.15333, 45.122), shapes.Site(9.14777, 45.17999))) self.assertEqual(1, len(blocks_keys)) self.assertEqual(expected_block, job.Block.from_kvs(blocks_keys[0]))
def test_can_serialize_a_block_into_kvs(self): block = job.Block((SITE, SITE)) block.to_kvs() self.assertEqual(block, job.Block.from_kvs(block.id))
def test_a_block_has_a_unique_id(self): self.assertTrue(job.Block(()).id) self.assertTrue(job.Block(()).id != job.Block(()).id)