Example #1
0
    def test_expect_call_not_come_with_string_param(self):
        expect = mockPlugin().mockRecord(myfun,'1')
        e = mockPlugin().UnexpectedCallError(expect)
        expectStr = '''
    Expecting Call: myfun('1')
'''
        self.assertEqual(expectStr, str(e))
Example #2
0
    def test_expect_call_not_come(self):
        expect = mockPlugin().mockRecord(myfun,1)
        e = mockPlugin().UnexpectedCallError(expect)
        expectStr = '''
    Expecting Call: myfun(1)
'''
        self.assertEqual(expectStr, str(e))
Example #3
0
 def test_fail_if_key_param_different(self):
     self.mock.mock_function(myfun).with_param(1,p1=2,p2=3)
     with self.assertRaises(mockPlugin().UnexpectedCallError) as cm:
         myfun(1, p1=2)
     expect = mockPlugin().mockRecord(myfun, 1, p1=2, p2=3)
     real = mockPlugin().mockRecord(myfun, 1, p1=2)
     self._check_unexpectedCall_exception_content(cm.exception, expect, real)
Example #4
0
    def test_expect_call_not_come_with_class_param(self):
        expect = mockPlugin().mockRecord(myfun, self.c)
        e = mockPlugin().UnexpectedCallError(expect)
        expectStr = '''
    Expecting Call: myfun({0})
'''.format(repr(self.c))
        self.assertEqual(expectStr, str(e))
Example #5
0
 def test_fail_if_param_not_the_expected(self):
     self.mock.mock_function(myfun).with_param(1,'1','anything')
     with self.assertRaises(mockPlugin().UnexpectedCallError) as cm:
         myfun(1,1)
     expect = mockPlugin().mockRecord(myfun, 1, '1', 'anything')
     real = mockPlugin().mockRecord(myfun, 1, 1)
     self._check_unexpectedCall_exception_content(cm.exception, expect, real)
Example #6
0
    def test_expect_class_call_not_come(self):
        expect = mockPlugin().mockRecord(myclass.fun)
        e = mockPlugin().UnexpectedCallError(expect) 
        expectStr = '''
    Expecting Call: fun({0})
'''.format(repr(myclass))
        self.assertEqual(expectStr, str(e))
Example #7
0
    def test_expect_call_not_come_with_key_param(self):
        expect = mockPlugin().mockRecord(myfun, '123', p1=1, p2='good afternoon', p3=self.c)
        e = mockPlugin().UnexpectedCallError(expect)
        expectStr = '''
    Expecting Call: myfun('123', p1=1, p2='good afternoon', p3={0})
'''.format(repr(self.c))
        self.assertEqual(expectStr, str(e))
Example #8
0
 def test_fail_if_class_type_different(self):
     self.mock.mock_function(myclass.myfun)
     self.mock.mock_function(myfun)
     with self.assertRaises(mockPlugin().UnexpectedCallError) as cm:
         myfun()
     expect = mockPlugin().mockRecord(myclass.myfun)
     real = mockPlugin().mockRecord(myfun)
     self._check_unexpectedCall_exception_content(cm.exception, expect, real)
Example #9
0
 def test_fail_if_mocked_function_call_in_wrong_sequence(self):
     self.mock.mock_function(myfun).and_return('myfun').with_param('AnythingIsOk', p1=1)
     self.mock.mock_function(os.listdir)
     with self.assertRaises(mockPlugin().UnexpectedCallError) as cm:
         os.listdir()
     expect = mockPlugin().mockRecord(myfun, 'AnythingIsOk', p1=1)
     real = mockPlugin().mockRecord(os.listdir)
     self._check_unexpectedCall_exception_content(cm.exception, expect, real)
Example #10
0
    def test_expect_instance_call_not_come(self):
        c = myclass()
        expect = mockPlugin().mockRecord(c.fun, 1, p1='1')
        e = mockPlugin().UnexpectedCallError(expect)
        expectStr = '''
    Expecting Call: fun({0}, 1, p1='1')
'''.format(repr(c))
        self.assertEqual(expectStr, str(e))
Example #11
0
 def test_fail_if_not_call_mocked_function(self):
     self.mock.mock_function(round).with_param('123').and_return(10)
     self.assertEqual('round', round.__name__)
     with self.assertRaises(mockPlugin().UnexpectedCallError) as cm:
         self.mock.tearDown()
     expect = mockPlugin().mockRecord(round, '123')
     self._check_unexpectedCall_exception_content(cm.exception, expect, None)
     self.assertEqual(3.0, round(3.3))
Example #12
0
    def test_invalid_call_(self):
        expect = mockPlugin().mockRecord(myfun, 'happy', p1=600, p2='good afternoon', p3=self.c)
        real = mockPlugin().mockRecord(round, 123, p='bad', test=self.c)
        e = mockPlugin().UnexpectedCallError(expect, real)
        expectStr = '''
    Expecting Call: myfun('happy', p1=600, p2='good afternoon', p3={0})
    But Actual Is:  round(123, p='bad', test={1})
'''.format(repr(self.c),repr(self.c))
        self.assertEqual(expectStr, str(e))
Example #13
0
 def test_two_record_not_equal_if_func_name_different(self):
     record_1 = mockPlugin().mockRecord(myfun)
     record_2 = mockPlugin().mockRecord(round)
     self.assertNotEqual(record_1, record_2)
Example #14
0
 def test_two_record_equal(self):
     record_1 = mockPlugin().mockRecord(myfun, 1, p1=1, p2=2)
     record_2 = mockPlugin().mockRecord(myfun, 1, p2=2, p1=1)
     self.assertEqual(record_1, record_2)
Example #15
0
 def test_instance_record_equal_to_class_record(self):
     c = myclass()
     record_1 = mockPlugin().mockRecord(c.fun, 1, p2=2, p1=1)
     record_2 = mockPlugin().mockRecord(myclass.fun, 1, p1=1, p2=2)
     self.assertEqual(record_1, record_2)
Example #16
0
 def test_class_record_equal_to_special_function(self):
     record_1 = mockPlugin().mockRecord(myclass.myfun, 1, p2=2, p1=1)
     c = myclass()
     record_2 = mockPlugin().mockRecord(myfun, c, 1, p1=1, p2=2)
     self.assertEqual(record_1, record_2)
Example #17
0
 def test_general_function_record_not_equal_to_class_function(self):
     record_1 = mockPlugin().mockRecord(myfun, 1)
     record_2 = mockPlugin().mockRecord(myclass.myfun)
     self.assertNotEqual(record_1, record_2)
Example #18
0
 def test_two_record_not_equal_if_instance_different(self):
     c = myclass()
     c_ = myclass()
     record_1 = mockPlugin().mockRecord(c.fun)
     record_2 = mockPlugin().mockRecord(c_.fun)
     self.assertNotEqual(record_1, record_2)
Example #19
0
 def tearDown(self):
     try:
         self.mock.tearDown()
     except mockPlugin().UnexpectedCallError:
         #accessed private member only for test
         self.assertEqual([],self.mock._mockRecordList)
Example #20
0
 def test_two_record_not_equal_if_key_param_different(self):
     record_1 = mockPlugin().mockRecord(myfun)
     record_2 = mockPlugin().mockRecord(myfun, p1=1)
     self.assertNotEqual(record_1, record_2)
Example #21
0
 def test_two_record_not_equal_if_both_arg_karg_different(self):
     record_1 = mockPlugin().mockRecord(myfun,1)
     record_2 = mockPlugin().mockRecord(myfun, p1=1)
     self.assertNotEqual(record_1, record_2)
Example #22
0
 def setUp(self):
     self.mock = mockPlugin()
     self.target = myclass()
     self.mock.setUp(self.target)
Example #23
0
 def test_two_record_not_equal_if_class_type_different(self):
     c = myclass()
     c2 = myclass2()
     record_1 = mockPlugin().mockRecord(c.fun)
     record_2 = mockPlugin().mockRecord(c2.fun)
     self.assertNotEqual(record_1, record_2)
Example #24
0
 def test_mock_is_a_singerton(self):
     mock=mockPlugin()
     self.assertEqual(mock, self.mock)
Example #25
0
        self.org_stdout = sys.stdout
        sys.stdout = StringIO()
        target.check_print_result = self.check_print_result

    def tearDown(self):
        try:
            assert_equal("", sys.stdout.getvalue())
        finally:
            sys.stdout = self.org_stdout

    def check_print_result(self, expectedString):
        assert_equal(expectedString, sys.stdout.getvalue())
        sys.stdout = StringIO()


_PLUGINLIST = [printPlugin(), stubMockPlugin.stubPlugin(), stubMockPlugin.mockPlugin()]


class myTestCase(unittest.TestCase):
    def setUp(self):
        for plugin in _PLUGINLIST:
            plugin.setUp(self)

        self.my_setup()

    def tearDown(self):
        for plugin in _PLUGINLIST:
            plugin.tearDown()

        self.my_teardown()