def test_setNameExceptions(self): """ Test for twistedchecker.core.runner.Runner.setNameExceptions. """ pathTestFiles = createTestFilesForFindingExceptions(self.mktemp()) self.clearOutputStream() runner = Runner() runner.setOutput(self.outputStream) # Set the reporter to C{twistedchecker.reporters.test.TestReporter}. runner.setReporter(TestReporter()) # Limit messages. runner.linter.disable_noerror_messages() runner.linter.enable("C0103") workingDir = os.getcwd() os.chdir(os.path.dirname(pathTestFiles)) moduleName = os.path.basename(pathTestFiles) exitResult = self.assertRaises(SystemExit, runner.run, [moduleName]) os.chdir(workingDir) predictResult = "11:C0103\n14:C0103\n15:C0103\n" outputResult = self.outputStream.getvalue() self.assertEqual(outputResult, predictResult) self.assertEqual(16, exitResult.code)
def test_setNameExceptions(self): """ Test for twistedchecker.core.runner.Runner.setNameExceptions. """ pathTestFiles = createTestFilesForFindingExceptions(self.mktemp()) self.clearOutputStream() runner = Runner() runner.setOutput(self.outputStream) # Set the reporter to C{twistedchecker.reporters.test.TestReporter}. runner.setReporter(TestReporter()) # Limit messages. runner.linter.disable_noerror_messages() # Enable invalid function names. runner.linter.enable("C0103") # Enable invalid method names. runner.linter.enable("C9302") workingDir = os.getcwd() os.chdir(os.path.dirname(pathTestFiles)) moduleName = os.path.basename(pathTestFiles) exitResult = self.assertRaises(SystemExit, runner.run, [moduleName]) os.chdir(workingDir) predictResult = "7:C9302\n11:C0103\n14:C0103\n15:C9302\n" outputResult = self.outputStream.getvalue() self.assertEqual(outputResult, predictResult) self.assertEqual(16, exitResult.code)
def _runTest(testCase, testFilePath): """ Run a functional test. @param testCase: The test case on which to call assertions. @type testCase: L{unittest.TestCase} @param testFilePath: The path to the module to test. @type testFilePath: L{str} """ pathResultFile = testFilePath.replace(".py", ".result") moduleName = filenameToModuleName(testFilePath) outputStream = NativeStringIO() runner = Runner() runner.allowOptions = False runner.setOutput(outputStream) runner.setReporter(TestReporter()) limits = _parseLimitMessages(testFilePath) if limits is not None: action, messages = limits _setLinterLimits(runner.linter, action, messages) exitCode = None try: runner.run([moduleName]) except SystemExit as error: exitCode = error.code # Check the results with open(pathResultFile) as f: expectedResult = sorted(f.read().strip().splitlines()) outputResult = sorted(outputStream.getvalue().strip().splitlines()) try: testCase.assertEqual(expectedResult, outputResult) except unittest.FailTest: testCase.fail(_formatResults(moduleName, expectedResult, outputResult)) if not expectedResult: testCase.assertEqual(0, exitCode) else: testCase.assertNotEqual(0, exitCode)
def _runTest(testCase, testFilePath): """ Run a functional test. @param testCase: The test case on which to call assertions. @type testCase: L{unittest.TestCase} @param testFilePath: The path to the module to test. @type testFilePath: L{str} """ pathResultFile = testFilePath.replace(".py", ".result") moduleName = filenameToModuleName(testFilePath) outputStream = io.BytesIO() runner = Runner() runner.allowOptions = False runner.setOutput(outputStream) runner.setReporter(TestReporter()) limits = _parseLimitMessages(testFilePath) if limits is not None: action, messages = limits _setLinterLimits(runner.linter, action, messages) _enablePEP8Checker(runner.linter) exitCode = None try: runner.run([moduleName]) except SystemExit as error: exitCode = error.code # Check the results expectedResult = open(pathResultFile).read().strip() outputResult = outputStream.getvalue().strip() try: testCase.assertEqual(expectedResult, outputResult) except unittest.FailTest: testCase.fail(_formatResults(moduleName, expectedResult, outputResult)) if not expectedResult: testCase.assertEqual(0, exitCode) else: testCase.assertNotEqual(0, exitCode)