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()
Beispiel #3
0
 def failing_mock_expectation(slf):
     expect(mock()).foo
     # emulate a refresh
     try:
         core._teardown()
     finally:
         core._setup()
	def setUp(self):
		core._setup()
		self.output = []
		def write(s):
			print "appending: %s" % s
			self.output.append(s)
		modify(sys).stderr.write = write
Beispiel #5
0
		def failing_mock_expectation(slf):
			mocktest.mock().is_expected
			# emulate a refresh
			try:
				core._teardown()
			finally:
				core._setup()
Beispiel #6
0
 def run_suite(self, class_):
     core._teardown()
     suite = unittest.makeSuite(class_)
     result = unittest.TestResult()
     suite.run(result)
     core._setup()
     return result
Beispiel #7
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()
Beispiel #8
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()
Beispiel #9
0
    def setUp(self):
        core._setup()
        self.output = []

        def write(s):
            print("appending: %s" % s)
            self.output.append(s)

        modify(sys).stderr.write = write
Beispiel #10
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()
Beispiel #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()
Beispiel #12
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()
	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)
		finally:
			core._setup()
		
	def test_expectation_errors_should_be_failures(self):
		class myTest(mocktest.TestCase):
			def test_a(self):
				foo = mock()
				expect(foo).blah.once()
		results = self.run_suite(myTest)
		self.assertEqual(1, results.testsRun)
		assert len(results.errors) == 0, results.errors
		self.assertEqual(1, len(results.failures))
		self.assertEqual(0, len(results.errors))

	def make_error(self, *args, **kwargs):
		print "runtime error is being raised..."
		raise SomeError(*args, **kwargs)
Beispiel #14
0
	def setUp(self):
		core._setup()
		self.stderr = mock().named('stderr')
		sys.stderr = self.stderr.raw
		self.output = mock(sys.stderr.write)
		print "all expectations is %r" % (core.MockWrapper._all_expectations,)
Beispiel #15
0
	def downup(self):
		core._teardown()
		core._setup()