示例#1
0
	def run_suite(self, class_):
		core._teardown()
		suite = unittest.makeSuite(class_)
		result = unittest.TestResult()
		suite.run(result)
		core._setup()
		return result
示例#2
0
		def failing_mock_expectation(slf):
			expect(mock()).foo
			# emulate a refresh
			try:
				core._teardown()
			finally:
				core._setup()
示例#3
0
		def failing_mock_expectation(slf):
			mocktest.mock().is_expected
			# emulate a refresh
			try:
				core._teardown()
			finally:
				core._setup()
示例#4
0
	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)
示例#5
0
 def failing_mock_expectation(slf):
     expect(mock()).foo
     # emulate a refresh
     try:
         core._teardown()
     finally:
         core._setup()
示例#6
0
    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()
示例#7
0
 def run_suite(self, class_):
     core._teardown()
     suite = unittest.makeSuite(class_)
     result = unittest.TestResult()
     suite.run(result)
     core._setup()
     return result
示例#8
0
	def test_invalid_usage_after_teardown(self):
		core._teardown()
		
		e = None
		try:
			mock()
		except Exception, e_:
			e = e_
示例#9
0
	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()
示例#10
0
	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)
示例#11
0
    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()
示例#12
0
	def tearDown(self):
		core._teardown()
示例#13
0
	def tearDown(self):
		print "all expectations is %r" % (core.MockWrapper._all_expectations,)
		core._teardown()
示例#14
0
 def tearDown(self):
     core._teardown()
示例#15
0
	def downup(self):
		core._teardown()
		core._setup()