def test_broadcast_initialize_sets_count(self): expected_count = pf.Constant(42) broadcast = pf.flow.Broadcast(pf.Placeholder(out_type=int), count=expected_count) self.assertEqual(broadcast.count, expected_count)
def test_placeholder_apply_returns_same_value(self): p = pf.Placeholder() value = 42 output = [x for x in p.apply(42)] self.assertEqual(len(output), 1) self.assertEqual(output[0], value)
def test_colormask_initialize_defaults_colormask_to_empty_mask(self): empty_mask = [None, None, None] mask = pf.transform.ColorMask(pf.Placeholder(out_type=pf.Image)) self.assertEqual(len(mask.parents), 2) self.assertIsInstance(mask.parents[1], pf.Constant) self.assertEqual(next(mask.parents[1]), empty_mask)
def setUp(self): self.img_id = 'someID' self.img_data = np.random.randn(10, 10, 3) self.image = pf.Image(self.img_id, 'jpg', self.img_data) self.mask = pf.transform.ColorMask(pf.Placeholder(out_type=pf.Image), pf.Constant([None, None, None]))
def test_colormask_initialize_accepts_masks(self): target_mask = [138, 222, 156] mask = pf.transform.ColorMask(pf.Placeholder(out_type=pf.Image), pf.Constant(target_mask)) self.assertEqual(len(mask.parents), 2) self.assertIsInstance(mask.parents[1], pf.Constant) self.assertEqual(next(mask.parents[1]), target_mask)
def test_broadcast_apply_correctly_broadcasts_values(self): input_vals = [1, 2, 3, 4] count = 2 expected_out = [1, 1, 2, 2, 3, 3, 4, 4] broadcast = pf.flow.Broadcast(pf.Placeholder(out_type=int), count=pf.Constant(42)) actual_out = [] for val in input_vals: actual_out += [x for x in broadcast.apply(val, count)] self.assertEqual(actual_out, expected_out)
def test_placeholder_initialize_sets_output_type(self): out_type = str p = pf.Placeholder(out_type=out_type) self.assertEqual(p._output_type, out_type)
def test_placeholder_initialize_defaults_output_type_to_none(self): p = pf.Placeholder() self.assertEqual(p._output_type, None)
def setUp(self): self.disk = pf.output.DiskOutput(pf.Placeholder(out_type=pf.Image), pf.Placeholder(out_type=str))
def test_diskoutput_defaults_id_to_disk(self): disk = pf.output.DiskOutput(pf.Placeholder(out_type=pf.Image), pf.Placeholder(out_type=str)) self.assertEqual(disk.id, 'disk')
def test_colormask_initialize_defaults_id_to_colormask(self): mask = pf.transform.ColorMask(pf.Placeholder(out_type=pf.Image)) self.assertEqual(mask.id, 'colormask')
def test_broadcast_initialize_defaults_id_to_broadcast(self): broadcast = pf.flow.Broadcast(pf.Placeholder(out_type=int), count=pf.Constant(42)) self.assertEqual(broadcast.id, 'broadcast')