示例#1
0
    def test_mock_ordered(self):
        m = Mock()
        m.ordered_exec('first', toReturn='first result')
        m.ordered_exec('second', toReturn='second result')

        self.assertEqual('first result', m.exec('first'))
        self.assertEqual('second result', m.exec('second'))
示例#2
0
    def test_mock_ordered(self):
        m = Mock()
        m.ordered_exec('first', toReturn='first result')
        m.ordered_exec('second', toReturn='second result')

        self.assertEqual('first result', m.exec('first'))
        self.assertEqual('second result', m.exec('second'))
示例#3
0
    def test_mock_ordered_called_too_many_times(self):
        m = Mock()
        m.ordered_exec('first', toReturn='first result')

        self.assertEqual('first result', m.exec('first'))
        try:
            m.exec('should not be called')
        except AssertionError as e:
            message = e.args[0]
            self.assertEqual('Not expected more calls of exec. The method was called with:\n'
            +'''\targs=('should not be called',)\n\tkwargs={}''', message)
示例#4
0
    def test_mock_ordered_with_wrong_order(self):
        m = Mock()
        m.ordered_exec('first', toReturn='first result')
        m.ordered_exec('second', toReturn='second result')

        try:
            m.exec('second')
        except AssertionError as e:
            message = e.args[0]
            self.assertRegex(message, re.compile('''Expected call of exec with:\n\targs=\\('first',\\)\n\tkwargs={}\n'''
                                                 +'''but found:\n\targs=\\('second',\\)\n\tkwargs={}\n.*'''))
示例#5
0
    def test_mock_ordered_called_too_many_times(self):
        m = Mock()
        m.ordered_exec('first', toReturn='first result')

        self.assertEqual('first result', m.exec('first'))
        try:
            m.exec('should not be called')
        except AssertionError as e:
            message = e.args[0]
            self.assertEqual(
                'Not expected more calls of exec. The method was called with:\n'
                + '''\targs=('should not be called',)\n\tkwargs={}''', message)
示例#6
0
    def test_mock_ordered_with_wrong_order(self):
        m = Mock()
        m.ordered_exec('first', toReturn='first result')
        m.ordered_exec('second', toReturn='second result')

        try:
            m.exec('second')
        except AssertionError as e:
            message = e.args[0]
            self.assertRegex(
                message,
                re.compile(
                    '''Expected call of exec with:\n\targs=\\('first',\\)\n\tkwargs={}\n'''
                    +
                    '''but found:\n\targs=\\('second',\\)\n\tkwargs={}\n.*'''))