コード例 #1
0
    def test_add_invalid_constructor(self):
        test_template_h = NodeTemplate(name="test_1",
                                       inputs=[('a', int), ('b', int)],
                                       outputs=[('output', int)])

        @DeltaBlock(allow_const=False)
        def simple_add_to_bool(a: int, b: int) -> bool:
            return bool(a + b)

        with self.assertRaises(ValueError):
            test_template_h.add_constructor(simple_add_to_bool)
コード例 #2
0
    def test_add_migen(self):
        test_template1 = NodeTemplate(name="test_1",
                                      inputs=[('a', DOptional(int)),
                                              ('b', DOptional(int))])

        test_template1.add_constructor(AMigenNode2())

        with DeltaGraph():
            n1 = test_template1.call(2, 3)

        self.assertEqual(len(n1.bodies), 1)
        self.assertIn(PyMigenBody, n1.body.access_tags)
コード例 #3
0
    def test_add_method(self):
        test_template_b = NodeTemplate(name="test_1",
                                       inputs=[('a', int), ('b', int)],
                                       outputs=[('output', int)])

        @DeltaBlock(template=test_template_b, allow_const=False)
        def _simple_add_2(a: int, b: int) -> int:
            return a + b

        test_template_b.add_constructor(OpCacher2.cached_add_2)

        with DeltaGraph():
            n1 = OpCacher2().cached_add_2(2, 3)

        self.assertEqual(len(n1.bodies), 2)
        self.assertIn('cached_add_2', n1.body.access_tags)
コード例 #4
0
    def test_add_func(self):
        test_template_a = NodeTemplate(name="test_1",
                                       inputs=[('a', int), ('b', int)],
                                       outputs=[('output', int)])

        @DeltaBlock(allow_const=False)
        def simple_add_2(a: int, b: int) -> int:
            return a + b

        test_template_a.add_constructor(simple_add_2)

        with DeltaGraph():
            n1 = test_template_a.call(2, 3)

        self.assertEqual(len(n1.bodies), 1)
        self.assertIn('simple_add_2', n1.body.access_tags)
コード例 #5
0
    def test_add_interactive(self):
        test_template1 = NodeTemplate(name="test_1",
                                      inputs=[('a', int), ('b', int)],
                                      outputs=int)

        @Interactive(inputs=[('a', int), ('b', int)], outputs=int)
        def broken_adder_2(node: RealNode):
            a = node.receive('a')
            b = node.receive('b')
            node.send(a + b + 1)

        test_template1.add_constructor(broken_adder_2)

        with DeltaGraph():
            n1 = test_template1.call(2, 3)

        self.assertEqual(len(n1.bodies), 1)
        self.assertIn('broken_adder_2', n1.body.access_tags)
コード例 #6
0
    def test_add_with_existing_same_template(self):
        """Test for when the constructor we are adding is already on the
        ``NodeTemplate``. The constructor should not be added twice.
        """
        test_template_g = NodeTemplate(name="test_1",
                                       inputs=[('a', int), ('b', int)],
                                       outputs=[('output', int)])

        @DeltaBlock(template=test_template_g, allow_const=False)
        def simple_add_2(a: int, b: int) -> int:
            return a + b

        test_template_g.add_constructor(simple_add_2)

        with DeltaGraph():
            n1 = test_template_g.call(2, 3)

        self.assertEqual(len(n1.bodies), 1)
        self.assertIn('simple_add_2', n1.body.access_tags)
コード例 #7
0
    def test_add_with_existing_other_template(self):
        """Test for when the constructor we are adding is already associated
        with some other ``NodeTemplate``.
        """
        test_template_e = NodeTemplate(name="test_1",
                                       inputs=[('a', int), ('b', int)],
                                       outputs=[('output', int)])

        test_template_f = NodeTemplate(name="test_2",
                                       inputs=[('a', int), ('b', int)],
                                       outputs=[('output', int)])

        @DeltaBlock(template=test_template_f, allow_const=False)
        def simple_add_2(a: int, b: int) -> int:
            return a + b

        test_template_e.add_constructor(simple_add_2)

        with DeltaGraph():
            n1 = test_template_e.call(2, 3)

        self.assertEqual(len(n1.bodies), 1)
        self.assertIn('simple_add_2', n1.body.access_tags)