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)
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)
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)
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)
def test_any_callable(self): def add(): pass self.assertTrue(visit(self.any_node.validate(add, "")).valid)
def test_callable_validates_function(self): def add1(x: int) -> int: return x + 1 self.assertTrue(visit(self.node.validate(add1, "")).valid)
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(), '')))
def test_callable_validates_function(self): def add1(x: int) -> int: return x+1 self.assertTrue(visit(self.node.validate(add1, '')))
def test_any_callable(self): def add(): pass self.assertTrue(visit(self.any_node.validate(add, '')).valid)