Ejemplo n.º 1
0
    def test_any_input_with_output(self):
        def sample_a(): pass
        def sample_b() -> int: pass
        def sample_C(a: int) -> int: pass
        def sample_d(a: int): pass

        self.assertFalse(visit(self.any_input_node.validate(sample_a, '')).valid)
        self.assertTrue(visit(self.any_input_node.validate(sample_b, '')).valid)
        self.assertTrue(visit(self.any_input_node.validate(sample_C, '')).valid)
        self.assertFalse(visit(self.any_input_node.validate(sample_d, '')).valid)
Ejemplo n.º 2
0
    def test_any_input_with_output(self):
        def sample_a():
            pass

        def sample_b() -> int:
            pass

        def sample_C(a: int) -> int:
            pass

        def sample_d(a: int):
            pass

        self.assertFalse(
            visit(self.any_input_node.validate(sample_a, "")).valid)
        self.assertTrue(
            visit(self.any_input_node.validate(sample_b, "")).valid)
        self.assertTrue(
            visit(self.any_input_node.validate(sample_C, "")).valid)
        self.assertFalse(
            visit(self.any_input_node.validate(sample_d, "")).valid)
Ejemplo n.º 3
0
    def test_visit(self):
        """
        Verifies that 'visit' function returns a result returned by the given generator
        """
        def generator_foo(a):
            result = yield generator_multiply_add(a, a+1)
            result = yield generator_multiply_add(result, result+1)
            yield result

        def generator_multiply_add(a, b):
            yield a + 2*b

        result = visit(generator_foo(1))

        self.assertEqual(result, 17)
Ejemplo n.º 4
0
    def test_callable_validates_callable_object(self):
        class AddOne:
            def __call__(self, x: int) -> int:
                return x + 1

        self.assertTrue(visit(self.node.validate(AddOne(), "")).valid)
Ejemplo n.º 5
0
    def test_any_callable(self):
        def add():
            pass

        self.assertTrue(visit(self.any_node.validate(add, "")).valid)
Ejemplo n.º 6
0
    def test_callable_validates_function(self):
        def add1(x: int) -> int:
            return x + 1

        self.assertTrue(visit(self.node.validate(add1, "")).valid)
Ejemplo n.º 7
0
    def test_callable_validates_callable_object(self):
        class AddOne:
            def __call__(self, x: int) -> int:
                return x+1

        self.assertTrue(visit(self.node.validate(AddOne(), '')))
Ejemplo n.º 8
0
 def test_callable_validates_function(self):
     def add1(x: int) -> int:
         return x+1
     self.assertTrue(visit(self.node.validate(add1, '')))
Ejemplo n.º 9
0
    def test_any_callable(self):
        def add(): pass

        self.assertTrue(visit(self.any_node.validate(add, '')).valid)