def run_suite(self, class_): core._teardown() suite = unittest.makeSuite(class_) result = unittest.TestResult() suite.run(result) core._setup() return result
def failing_mock_expectation(slf): expect(mock()).foo # emulate a refresh try: core._teardown() finally: core._setup()
def failing_mock_expectation(slf): mocktest.mock().is_expected # emulate a refresh try: core._teardown() finally: core._setup()
def test_reality_formatting(self): core._teardown() try: with MockTransaction: m = mock('meth') expect(m).meth.once() m.meth(1,2,3) m.meth(foo='bar') m.meth() m.meth(1, foo=2) except AssertionError, e: line_agnostic_repr = [ re.sub('\.py:[0-9 ]{3} ', '.py:LINE ', line) for line in str(e).split('\n')] expected_lines = [ 'Mock "meth" did not match expectations:', ' expected exactly 1 calls', ' received 4 calls with arguments:', ' 1: (1, 2, 3) // mocktest_test.py:LINE :: m.meth(1,2,3)', " 2: (foo='bar') // mocktest_test.py:LINE :: m.meth(foo='bar')", ' 3: () // mocktest_test.py:LINE :: m.meth()', ' 4: (1, foo=2) // mocktest_test.py:LINE :: m.meth(1, foo=2)'] for got, expected in zip(line_agnostic_repr, expected_lines): self.assertEqual(got, expected)
def failing_mock_expectation(slf): expect(mock()).foo # emulate a refresh try: core._teardown() finally: core._setup()
def test_reality_formatting(self): core._teardown() try: with MockTransaction: m = mock('meth') expect(m).meth.once() m.meth(1, 2, 3) m.meth(foo='bar') m.meth() m.meth(1, foo=2) except AssertionError as e: line_agnostic_repr = [ re.sub('\.py:[0-9 ]{3} ', '.py:LINE ', line) for line in str(e).split('\n') ] expected_lines = [ 'Mock "meth" did not match expectations:', ' expected exactly 1 calls', ' received 4 calls with arguments:', ' 1: (1, 2, 3) // mocktest_test.py:LINE :: m.meth(1,2,3)', " 2: (foo='bar') // mocktest_test.py:LINE :: m.meth(foo='bar')", ' 3: () // mocktest_test.py:LINE :: m.meth()', ' 4: (1, foo=2) // mocktest_test.py:LINE :: m.meth(1, foo=2)' ] for got, expected in zip(line_agnostic_repr, expected_lines): self.assertEqual(got, expected) finally: core._setup()
def run_suite(self, class_): core._teardown() suite = unittest.makeSuite(class_) result = unittest.TestResult() suite.run(result) core._setup() return result
def test_invalid_usage_after_teardown(self): core._teardown() e = None try: mock() except Exception, e_: e = e_
def test_is_not_expected(self): wrapper = mock() mock_ = wrapper.raw expect(mock_.a).once() wrapper.child('b').is_not_expected mock_.a() core._teardown() core._setup()
def test_invalid_usage_after_teardown(self): core._teardown() try: e = None try: m = mock() expect(m).foo().never() except Exception, e_: print repr(e_) e = e_ self.assertFalse(e is None, "no exception was raised") self.assertEqual(str(e), "Mock transaction has not been started. Make sure you are inheriting from mocktest.TestCase") self.assertEqual(e.__class__, AssertionError)
def test_invalid_usage_after_teardown(self): core._teardown() try: e = None try: m = mock() expect(m).foo().never() except Exception as e_: print(repr(e_)) e = e_ self.assertFalse(e is None, "no exception was raised") self.assertEqual( str(e), "Mock transaction has not been started. Make sure you are inheriting from mocktest.TestCase" ) self.assertEqual(e.__class__, AssertionError) finally: core._setup()
def tearDown(self): core._teardown()
def tearDown(self): print "all expectations is %r" % (core.MockWrapper._all_expectations,) core._teardown()
def tearDown(self): core._teardown()
def downup(self): core._teardown() core._setup()