def test_split_block_size_lt_1(self): # If the specified block_size is less than 1, this is invalid. # We expect a RuntimeError to be raised. gen = general.split_into_blocks(self.job_id, self.all_sites, block_size=0) self.assertRaises(RuntimeError, gen.next) gen = general.split_into_blocks(self.job_id, self.all_sites, block_size=-1) self.assertRaises(RuntimeError, gen.next)
def test_split_block_size_lt_1(self): # If the specified block_size is less than 1, this is invalid. # We expect a RuntimeError to be raised. gen = general.split_into_blocks(self.job_id, self.all_sites, block_size=0) self.assertRaises(RuntimeError, gen.next) gen = general.split_into_blocks(self.job_id, self.all_sites, block_size=-1) self.assertRaises(RuntimeError, gen.next)
def test_split_empty_site_list(self): # If `split_into_blocks` is given an empty site list, the generator # shouldn't yield anything. actual = [block for block in general.split_into_blocks( self.job_id, [])] self.assertEqual([], actual)
def test_split_empty_site_list(self): # If `split_into_blocks` is given an empty site list, the generator # shouldn't yield anything. actual = [ block for block in general.split_into_blocks(self.job_id, []) ] self.assertEqual([], actual)
def test_split_block_size_eq_1(self): # Test splitting when block_size==1. expected = [Block(self.job_id, i, [self.all_sites[i]]) for i in xrange(len(self.all_sites))] actual = [block for block in general.split_into_blocks( self.job_id, self.all_sites, block_size=1)] self.assertEqual(expected, actual)
def test_split_block_size_gt_site_list_size(self): # If the block size is greater than the input site list size, # the generator should just yield a single block containing all of the # sites. actual = [block for block in general.split_into_blocks( self.job_id, self.all_sites, block_size=9)] self.assertEqual( [Block(self.job_id, 0, self.all_sites)], actual)
def test_split_block_size_eq_to_site_list_size(self): # If the block size is equal to the input site list size, # the generator should just yield a single block containing all of the # sites. actual = [block for block in general.split_into_blocks( self.calculation_id, self.all_sites, block_size=8)] self.assertEqual( [Block(self.calculation_id, 0, self.all_sites)], actual)
def test_split_block_size_gt_site_list_size(self): # If the block size is greater than the input site list size, # the generator should just yield a single block containing all of the # sites. actual = [ block for block in general.split_into_blocks( self.job_id, self.all_sites, block_size=9) ] self.assertEqual([Block(self.job_id, 0, self.all_sites)], actual)
def test_split_block_size_eq_1(self): # Test splitting when block_size==1. expected = [ Block(self.job_id, i, [self.all_sites[i]]) for i in xrange(len(self.all_sites)) ] actual = [ block for block in general.split_into_blocks( self.job_id, self.all_sites, block_size=1) ] self.assertEqual(expected, actual)
def test_split_into_blocks(self): # Test a typical split case. # We will use a block size of 3, which will # give us 2 blocks of 3 sites and 1 block of 2 sites. expected = [ Block(self.job_id, 0, self.all_sites[:3]), Block(self.job_id, 1, self.all_sites[3:6]), Block(self.job_id, 2, self.all_sites[6:]) ] actual = [block for block in general.split_into_blocks( self.job_id, self.all_sites, block_size=3)] self.assertEqual(expected, actual)
def test_split_into_blocks(self): # Test a typical split case. # We will use a block size of 3, which will # give us 2 blocks of 3 sites and 1 block of 2 sites. expected = [ Block(self.job_id, 0, self.all_sites[:3]), Block(self.job_id, 1, self.all_sites[3:6]), Block(self.job_id, 2, self.all_sites[6:]) ] actual = [ block for block in general.split_into_blocks( self.job_id, self.all_sites, block_size=3) ] self.assertEqual(expected, actual)