Exemplo n.º 1
0
 def failing_mock_expectation(slf):
     expect(mock()).foo
     # emulate a refresh
     try:
         core._teardown()
     finally:
         core._setup()
Exemplo n.º 2
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)
Exemplo n.º 3
0
		def failing_mock_expectation(slf):
			expect(mock()).foo
			# emulate a refresh
			try:
				core._teardown()
			finally:
				core._setup()
Exemplo n.º 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 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()
Exemplo n.º 5
0
    def test_should_ignore_with_description(self):
        callback = mock()
        expect(callback).__call__.never()

        @ignore('not done yet')
        def test_failure(self):
            callback('a')

        self.assert_(self.run_method(test_failure).wasSuccessful())
Exemplo n.º 6
0
    def test_ignore(self):
        callback = mock()
        expect(callback).__call__.never()

        @ignore
        def test_failure(self):
            callback('a')

        self.assert_(self.run_method(test_failure).wasSuccessful())
Exemplo n.º 7
0
	def test_should_ignore_with_description(self):
		callback = mock()
		expect(callback).__call__.never()
			
		@ignore('not done yet')
		def test_failure(self):
			callback('a')
		
		self.assert_(self.run_method(test_failure).wasSuccessful())
Exemplo n.º 8
0
	def test_ignore(self):
		callback = mock()
		expect(callback).__call__.never()
			
		@ignore
		def test_failure(self):
			callback('a')
		
		self.assert_(self.run_method(test_failure).wasSuccessful())
Exemplo n.º 9
0
	def test_should_do_expectations(self):
		try:
			with MockTransaction:
				f = mock()
				expect(f).foo.once()
				f.foo('a')
				f.foo()
			raise RuntimeError("should not reach here!")
		except AssertionError, e:
			assert re.compile('Mock "foo" .*expected exactly 1 calls.* received 2 calls.*', re.DOTALL).match(str(e)), str(e)
Exemplo n.º 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()
Exemplo n.º 11
0
    def test_runner(self):
        from pyqcy.properties import Property

        with MockTransaction:
            when(sys).exit.then_return(None)
            assert main(__name__, exit=True) == len([
                obj for obj in globals().itervalues()
                if isinstance(obj, Property)
            ])

            # we have one failing property so expect a failure
            expect(sys).exit.where(lambda code: code != 0).once()
Exemplo n.º 12
0
 def test_should_do_expectations(self):
     try:
         with MockTransaction:
             f = mock()
             expect(f).foo.once()
             f.foo('a')
             f.foo()
         raise RuntimeError("should not reach here!")
     except AssertionError as e:
         assert re.compile(
             'Mock "foo" .*expected exactly 1 calls.* received 2 calls.*',
             re.DOTALL).match(str(e)), str(e)
Exemplo n.º 13
0
	def test_expect_should_work_on_a_mock_or_wrapper(self):
		wrapper = mock()
		mock_ = wrapper.raw
		
		expect(mock_.a).once()
		wrapper.expects('b').once()
		wrapper.child('c').is_expected.once()

		self.assertTrue(len(core.MockWrapper._all_expectations) == 3)
		
		mock_.a()
		mock_.b()
		mock_.c()
Exemplo n.º 14
0
    def test_expect_should_work_on_a_mock_or_wrapper(self):
        wrapper = mock_wrapper()
        mock = wrapper.mock

        expect(mock.a).once()
        wrapper.expects("b").once()
        wrapper.child("c").is_expected.once()

        self.assertTrue(len(mocktest.mockwrapper.MockWrapper._all_expectations) == 3)

        mock.a()
        mock.b()
        mock.c()
Exemplo n.º 15
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)
Exemplo n.º 16
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()
Exemplo n.º 17
0
			def test_one(self):
				expect(foo).split('a')
Exemplo n.º 18
0
		def mock_failure(slf):
			expect(mock()).foo().at_least.once()
Exemplo n.º 19
0
			def test_a(self):
				foo = mock()
				expect(foo).blah.once()
Exemplo n.º 20
0
 def test_one(self):
     expect(foo).split('a')
Exemplo n.º 21
0
 def test_a(self):
     foo = mock()
     expect(foo).blah.once()
Exemplo n.º 22
0
 def mock_failure(slf):
     expect(mock()).foo().at_least.once()