예제 #1
0
    def test_and_is_lazy(self):
        with patch(
                'pycan._assert_authorization_parameters') as assert_parameters:
            assert_parameters.return_value = True
            test_functions = [Mock(), Mock(), Mock()]
            combined_function = pycan.and_(*test_functions)

            test_functions[0].return_value = False
            combined_function(1, 2, 1)
            test_functions[0].assert_called_once_with(1, 2, 1)
            self.assertEquals(test_functions[1].call_count, 0)
            self.assertEquals(test_functions[2].call_count, 0)

            test_functions[0].return_value = True
            test_functions[1].return_value = False
            combined_function(1, 1, 2)
            self.assertEquals(test_functions[0].call_count, 2)
            test_functions[1].assert_called_once_with(1, 1, 2)
            self.assertEquals(test_functions[2].call_count, 0)

            test_functions[0].return_value = True
            test_functions[1].return_value = True
            test_functions[2].return_value = True
            combined_function(2, 2, 2)
            self.assertEquals(test_functions[0].call_count, 3)
            self.assertEquals(test_functions[1].call_count, 2)
            test_functions[2].assert_called_once_with(2, 2, 2)
예제 #2
0
    def test_combine_with_and(self):
        test_function = pycan.and_(lambda u, c, r: u == c,
                                   lambda u, c, r: u == r,
                                   lambda u, c, r: c == r)

        self.assertTrue(test_function(1, 1, 1))
        self.assertFalse(test_function(1, 1, 0))
        self.assertFalse(test_function(1, 0, 1))
        self.assertFalse(test_function(0, 1, 1))
        self.assertFalse(test_function(1, 2, 3))