示例#1
0
 def test_should_return_True_always(self):
     test_mock = create_mock(TestClass)
     test_mock.when('method1', return_value=True)
     self.assertEqual(test_mock.method1(param1='iweyr', param2=123), True)
     self.assertEqual(test_mock.method1('ok'), True)
     self.assertEqual(test_mock.method1(), True)
     self.assertIsNone(test_mock.method2())
示例#2
0
 def test_should_reset_mock(self):
     test_mock = create_mock(TestClass)
     test_mock.when('method1', return_value=True)
     self.assertTrue(test_mock.method1())
     self.assertTrue(test_mock.has_been_called())
     test_mock.reset()
     self.assertFalse(test_mock.has_been_called())
     self.assertIsNone(test_mock.method1())
示例#3
0
 def test_should_raise_OSError_or_not_depending_on_arguments(self):
     test_mock = create_mock(TestClass)
     test_mock.when('method1', ('a', 2), raise_exception=OSError)
     test_mock.when('method1', ('b', 'c'), return_value=12)
     test_mock.when('method1', return_value='hi')
     with self.assertRaises(OSError): test_mock.method1('a', 2)
     self.assertEqual(test_mock.method1('b', 'c'), 12)
     self.assertEqual(test_mock.method1(1,1), 'hi')
示例#4
0
 def test_should_allow_default_ret_value_and_specific_ret_value(self):
     test_mock = create_mock(TestClass)
     test_mock.when('method1', return_value=36)
     test_mock.when('method1', ('a', 7), return_value=11)
     self.assertEqual(test_mock.method1(param1='iweyr', param2=123), 36)
     self.assertEqual(test_mock.method1('ok'), 36)
     self.assertEqual(test_mock.method1('a', 7), 11)
     self.assertEqual(test_mock.method1('a', 9), 36)
示例#5
0
 def test_should_count_times_has_been_called_each_method(self):
     test_mock = create_mock(TestClass)
     self.assertFalse(test_mock.has_been_called())
     test_mock.method1()
     self.assertTrue(test_mock.has_been_called(method='method1', times=1))
     test_mock.method2()
     self.assertTrue(test_mock.has_been_called(method='method2', times=1))
     test_mock.method1('a', 'b')
     self.assertTrue(test_mock.has_been_called(method='method1', times=2))
示例#6
0
 def test_should_count_times_has_been_called_each_method_with_parameters(self):
     test_mock = create_mock(TestClass)
     self.assertFalse(test_mock.has_been_called())
     test_mock.method1()
     test_mock.method1()
     self.assertTrue(test_mock.has_been_called_with('method1', ()))
     self.assertTrue(test_mock.has_been_called_with('method1', (), times=2))
     self.assertFalse(test_mock.has_been_called_with('method1', (), times=3))
     test_mock.method2('a')
     self.assertTrue(test_mock.has_been_called_with('method2', ('a',)))
     test_mock.method1('a', 'b')
     self.assertTrue(test_mock.has_been_called_with('method1', ('a', 'b'), times=1))
     self.assertFalse(test_mock.has_been_called_with('method1', ('a', 'c'), times=0))
     test_mock.method2(arg2=0, arg1='1')
     self.assertTrue(test_mock.has_been_called_with('method2', {'arg1': '1', 'arg2': 0}))
     self.assertTrue(test_mock.has_been_called_with('method2', {'arg1': '1', 'arg2': 0}, times=1))
     self.assertFalse(test_mock.has_been_called_with('method2', {'arg1': '1', 'arg2': 1}))
示例#7
0
 def test_compile_plan(self):
     with HTTMock(create_mock()):
         myrial = "a = empty(i:int);\nstore(a, a);"
         json = self.connection.compile_program(myrial, language="MyriaL")
         self.assertEqual(json['rawQuery'], myrial)
示例#8
0
 def __init__(self, args):
     with HTTMock(create_mock()):
         self.connection = MyriaConnection(hostname='localhost', port=12345)
     unittest.TestCase.__init__(self, args)
示例#9
0
 def test_should_have_been_called(self):
     test_mock = create_mock(TestClass)
     self.assertFalse(test_mock.has_been_called())
     test_mock.method1()
     self.assertTrue(test_mock.has_been_called())
示例#10
0
 def test_should_raise_OSError(self):
     test_mock = create_mock(TestClass)
     test_mock.when('method1', raise_exception=OSError)
     with self.assertRaises(OSError): test_mock.method1('a', 2)
示例#11
0
 def test_should_return_hi(self):
     test_mock = create_mock(TestClass)
     test_mock.when('method1', {'param1': 'iweyr', 'param2': 123}, return_value='hi')
     self.assertEqual(test_mock.method1(param1='iweyr', param2=123), 'hi')
     self.assertIsNone(test_mock.method1('ok'))
示例#12
0
 def test_should_return_12(self):
     test_mock = create_mock(TestClass)
     test_mock.when('method1', ('a', 'b'), return_value=12)
     self.assertEqual(test_mock.method1('a', 'b'), 12)
     self.assertIsNone(test_mock.method1(12))
示例#13
0
 def test_should_return_None_by_default(self):
     test_mock = create_mock(TestClass)
     self.assertIsNone(test_mock.method1(1, "hi!"))
示例#14
0
 def test_should_create_mock_for_class(self):
     test_mock = create_mock(TestClass)
     self.assertIsNotNone(test_mock)
     self.assertIsInstance(test_mock, Mock)
示例#15
0
 def test_should_create_mock(self):
     test_mock = create_mock()
     self.assertIsNotNone(test_mock, msg='test mock is None')
     self.assertIsInstance(test_mock, Mock)