Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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]))
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
    def test_placeholder_initialize_defaults_output_type_to_none(self):
        p = pf.Placeholder()

        self.assertEqual(p._output_type, None)
Пример #9
0
 def setUp(self):
     self.disk = pf.output.DiskOutput(pf.Placeholder(out_type=pf.Image),
                                      pf.Placeholder(out_type=str))
Пример #10
0
    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')
Пример #11
0
    def test_colormask_initialize_defaults_id_to_colormask(self):
        mask = pf.transform.ColorMask(pf.Placeholder(out_type=pf.Image))

        self.assertEqual(mask.id, 'colormask')
Пример #12
0
    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')