コード例 #1
0
    def test_should_hijack_setup_and_teardown(self):
        lines = []

        def capture(line):
            lines.append(line)

        backup_setup = core._setup
        backup_teardown = core._teardown

        try:
            when(core)._setup.then_call(lambda: capture("_setup"))
            when(core)._teardown.then_call(lambda: capture("_teardown"))

            class Foo(mocktest.TestCase):
                def setUp(self):
                    capture("setup")

                def tearDown(self):
                    capture("teardown")

                def test_main_is_called(self):
                    capture("main")

            suite = unittest.makeSuite(Foo)
            result = unittest.TestResult()
            suite.run(result)

            self.assertTrue(result.wasSuccessful())
            self.assertEqual(
                lines, ['_setup', 'setup', 'main', '_teardown', 'teardown'])

        finally:
            core._setup = backup_setup
            core._teardown = backup_teardown
コード例 #2
0
	def test_should_hijack_setup_and_teardown(self):
		lines = []
		def capture(line):
			lines.append(line)
		backup_setup = core._setup
		backup_teardown = core._teardown
		
		try:
			when(core)._setup.then_call(lambda: capture("_setup"))
			when(core)._teardown.then_call(lambda: capture("_teardown"))
			
			class Foo(mocktest.TestCase):
				def setUp(self):
					capture("setup")
				def tearDown(self):
					capture("teardown")
				def test_main_is_called(self):
					capture("main")

			suite = unittest.makeSuite(Foo)
			result = unittest.TestResult()
			suite.run(result)

			self.assertTrue(result.wasSuccessful())
			self.assertEqual(lines, ['_setup', 'setup', 'main', '_teardown', 'teardown'])
		
		finally:
			core._setup = backup_setup
			core._teardown = backup_teardown
コード例 #3
0
ファイル: test_runner.py プロジェクト: Xion/pyqcy
    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()