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'))
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)
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.*'''))
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)
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.*'''))