Skip to content

Commit

Permalink
Replace force_not_colorized with force_not_colorized_test_class
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 12, 2024
1 parent cdf4989 commit 29b9e98
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
8 changes: 2 additions & 6 deletions Lib/test/test_unittest/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from test import support
import unittest
import test.test_unittest
from test.support import force_not_colorized
from test.support import force_not_colorized_test_class
from test.test_unittest.test_result import BufferedWriter


@force_not_colorized_test_class
class Test_TestProgram(unittest.TestCase):

def test_discovery_from_dotted_path(self):
Expand Down Expand Up @@ -121,7 +122,6 @@ def run(self, test):
self.assertEqual(['test.test_unittest', 'test.test_unittest2'],
program.testNames)

@force_not_colorized
def test_NonExit(self):
stream = BufferedWriter()
program = unittest.main(exit=False,
Expand All @@ -137,7 +137,6 @@ def test_NonExit(self):
'expected failures=1, unexpected successes=1)\n')
self.assertTrue(out.endswith(expected))

@force_not_colorized
def test_Exit(self):
stream = BufferedWriter()
with self.assertRaises(SystemExit) as cm:
Expand All @@ -155,7 +154,6 @@ def test_Exit(self):
'expected failures=1, unexpected successes=1)\n')
self.assertTrue(out.endswith(expected))

@force_not_colorized
def test_ExitAsDefault(self):
stream = BufferedWriter()
with self.assertRaises(SystemExit):
Expand All @@ -171,7 +169,6 @@ def test_ExitAsDefault(self):
'expected failures=1, unexpected successes=1)\n')
self.assertTrue(out.endswith(expected))

@force_not_colorized
def test_ExitSkippedSuite(self):
stream = BufferedWriter()
with self.assertRaises(SystemExit) as cm:
Expand All @@ -184,7 +181,6 @@ def test_ExitSkippedSuite(self):
expected = '\n\nOK (skipped=1)\n'
self.assertTrue(out.endswith(expected))

@force_not_colorized
def test_ExitEmptySuite(self):
stream = BufferedWriter()
with self.assertRaises(SystemExit) as cm:
Expand Down
16 changes: 2 additions & 14 deletions Lib/test/test_unittest/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import unittest
from test.support import (
captured_stdout,
force_not_colorized,
force_not_colorized_test_class,
warnings_helper,
)
Expand Down Expand Up @@ -37,6 +36,7 @@ def bad_cleanup2():
raise ValueError('bad cleanup2')


@force_not_colorized_test_class
class Test_TestResult(unittest.TestCase):
# Note: there are not separate tests for TestResult.wasSuccessful(),
# TestResult.errors, TestResult.failures, TestResult.testsRun or
Expand Down Expand Up @@ -208,7 +208,6 @@ def test_1(self):
self.assertIs(test_case, test)
self.assertIsInstance(formatted_exc, str)

@force_not_colorized
def test_addFailure_filter_traceback_frames(self):
class Foo(unittest.TestCase):
def test_1(self):
Expand All @@ -235,7 +234,6 @@ def get_exc_info():
self.assertEqual(len(dropped), 1)
self.assertIn("raise self.failureException(msg)", dropped[0])

@force_not_colorized
def test_addFailure_filter_traceback_frames_context(self):
class Foo(unittest.TestCase):
def test_1(self):
Expand Down Expand Up @@ -265,7 +263,6 @@ def get_exc_info():
self.assertEqual(len(dropped), 1)
self.assertIn("raise self.failureException(msg)", dropped[0])

@force_not_colorized
def test_addFailure_filter_traceback_frames_chained_exception_self_loop(self):
class Foo(unittest.TestCase):
def test_1(self):
Expand All @@ -291,7 +288,6 @@ def get_exc_info():
formatted_exc = result.failures[0][1]
self.assertEqual(formatted_exc.count("Exception: Loop\n"), 1)

@force_not_colorized
def test_addFailure_filter_traceback_frames_chained_exception_cycle(self):
class Foo(unittest.TestCase):
def test_1(self):
Expand Down Expand Up @@ -453,7 +449,6 @@ def testFailFast(self):
result.addUnexpectedSuccess(None)
self.assertTrue(result.shouldStop)

@force_not_colorized
def testFailFastSetByRunner(self):
stream = BufferedWriter()
runner = unittest.TextTestRunner(stream=stream, failfast=True)
Expand All @@ -465,6 +460,7 @@ def test(result):
self.assertTrue(stream.getvalue().endswith('\n\nOK\n'))


@force_not_colorized_test_class
class Test_TextTestResult(unittest.TestCase):
maxDiff = None

Expand Down Expand Up @@ -627,7 +623,6 @@ def _run_test(self, test_name, verbosity, tearDownError=None):
test.run(result)
return stream.getvalue()

@force_not_colorized
def testDotsOutput(self):
self.assertEqual(self._run_test('testSuccess', 1), '.')
self.assertEqual(self._run_test('testSkip', 1), 's')
Expand All @@ -636,7 +631,6 @@ def testDotsOutput(self):
self.assertEqual(self._run_test('testExpectedFailure', 1), 'x')
self.assertEqual(self._run_test('testUnexpectedSuccess', 1), 'u')

@force_not_colorized
def testLongOutput(self):
classname = f'{__name__}.{self.Test.__qualname__}'
self.assertEqual(self._run_test('testSuccess', 2),
Expand All @@ -652,21 +646,17 @@ def testLongOutput(self):
self.assertEqual(self._run_test('testUnexpectedSuccess', 2),
f'testUnexpectedSuccess ({classname}.testUnexpectedSuccess) ... unexpected success\n')

@force_not_colorized
def testDotsOutputSubTestSuccess(self):
self.assertEqual(self._run_test('testSubTestSuccess', 1), '.')

@force_not_colorized
def testLongOutputSubTestSuccess(self):
classname = f'{__name__}.{self.Test.__qualname__}'
self.assertEqual(self._run_test('testSubTestSuccess', 2),
f'testSubTestSuccess ({classname}.testSubTestSuccess) ... ok\n')

@force_not_colorized
def testDotsOutputSubTestMixed(self):
self.assertEqual(self._run_test('testSubTestMixed', 1), 'sFE')

@force_not_colorized
def testLongOutputSubTestMixed(self):
classname = f'{__name__}.{self.Test.__qualname__}'
self.assertEqual(self._run_test('testSubTestMixed', 2),
Expand All @@ -675,7 +665,6 @@ def testLongOutputSubTestMixed(self):
f' testSubTestMixed ({classname}.testSubTestMixed) [fail] (c=3) ... FAIL\n'
f' testSubTestMixed ({classname}.testSubTestMixed) [error] (d=4) ... ERROR\n')

@force_not_colorized
def testDotsOutputTearDownFail(self):
out = self._run_test('testSuccess', 1, AssertionError('fail'))
self.assertEqual(out, 'F')
Expand All @@ -686,7 +675,6 @@ def testDotsOutputTearDownFail(self):
out = self._run_test('testSkip', 1, AssertionError('fail'))
self.assertEqual(out, 'sF')

@force_not_colorized
def testLongOutputTearDownFail(self):
classname = f'{__name__}.{self.Test.__qualname__}'
out = self._run_test('testSuccess', 2, AssertionError('fail'))
Expand Down
22 changes: 6 additions & 16 deletions Lib/test/test_unittest/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import io
import os
import sys
import pickle
import subprocess
from test import support
from test.support import force_not_colorized

import sys
import unittest
from unittest.case import _Outcome

from test import support
from test.support import force_not_colorized, force_not_colorized_test_class
from test.test_unittest.support import (
BufferedWriter,
LoggingResult,
ResultWithNoStartTestRunStopTestRun,
)
from unittest.case import _Outcome


def resultFactory(*_):
Expand Down Expand Up @@ -251,6 +249,7 @@ def testNothing(self):
self.assertEqual(test._cleanups, [])


@force_not_colorized_test_class
class TestClassCleanup(unittest.TestCase):
def test_addClassCleanUp(self):
class TestableTest(unittest.TestCase):
Expand Down Expand Up @@ -418,7 +417,6 @@ def cleanup2():
self.assertIsInstance(e2[1], CustomError)
self.assertEqual(str(e2[1]), 'cleanup1')

@force_not_colorized
def test_with_errors_addCleanUp(self):
ordering = []
class TestableTest(unittest.TestCase):
Expand All @@ -442,7 +440,6 @@ def tearDownClass(cls):
['setUpClass', 'setUp', 'cleanup_exc',
'tearDownClass', 'cleanup_good'])

@force_not_colorized
def test_run_with_errors_addClassCleanUp(self):
ordering = []
class TestableTest(unittest.TestCase):
Expand All @@ -466,7 +463,6 @@ def tearDownClass(cls):
['setUpClass', 'setUp', 'test', 'cleanup_good',
'tearDownClass', 'cleanup_exc'])

@force_not_colorized
def test_with_errors_in_addClassCleanup_and_setUps(self):
ordering = []
class_blow_up = False
Expand Down Expand Up @@ -519,7 +515,6 @@ def tearDownClass(cls):
['setUpClass', 'setUp', 'tearDownClass',
'cleanup_exc'])

@force_not_colorized
def test_with_errors_in_tearDownClass(self):
ordering = []
class TestableTest(unittest.TestCase):
Expand Down Expand Up @@ -596,7 +591,6 @@ def test(self):
'inner setup', 'inner test', 'inner cleanup',
'end outer test', 'outer cleanup'])

@force_not_colorized
def test_run_empty_suite_error_message(self):
class EmptyTest(unittest.TestCase):
pass
Expand All @@ -608,6 +602,7 @@ class EmptyTest(unittest.TestCase):
self.assertIn("\nNO TESTS RAN\n", runner.stream.getvalue())


@force_not_colorized_test_class
class TestModuleCleanUp(unittest.TestCase):
def test_add_and_do_ModuleCleanup(self):
module_cleanups = []
Expand Down Expand Up @@ -670,7 +665,6 @@ class Module(object):
self.assertEqual(cleanups,
[((1, 2), {'function': 'hello'})])

@force_not_colorized
def test_run_module_cleanUp(self):
blowUp = True
ordering = []
Expand Down Expand Up @@ -810,7 +804,6 @@ def tearDownClass(cls):
'tearDownClass', 'cleanup_good'])
self.assertEqual(unittest.case._module_cleanups, [])

@force_not_colorized
def test_run_module_cleanUp_when_teardown_exception(self):
ordering = []
class Module(object):
Expand Down Expand Up @@ -972,7 +965,6 @@ def testNothing(self):
self.assertEqual(cleanups,
[((1, 2), {'function': 3, 'self': 4})])

@force_not_colorized
def test_with_errors_in_addClassCleanup(self):
ordering = []

Expand Down Expand Up @@ -1006,7 +998,6 @@ def tearDownClass(cls):
['setUpModule', 'setUpClass', 'test', 'tearDownClass',
'cleanup_exc', 'tearDownModule', 'cleanup_good'])

@force_not_colorized
def test_with_errors_in_addCleanup(self):
ordering = []
class Module(object):
Expand Down Expand Up @@ -1037,7 +1028,6 @@ def tearDown(self):
['setUpModule', 'setUp', 'test', 'tearDown',
'cleanup_exc', 'tearDownModule', 'cleanup_good'])

@force_not_colorized
def test_with_errors_in_addModuleCleanup_and_setUps(self):
ordering = []
module_blow_up = False
Expand Down

0 comments on commit 29b9e98

Please sign in to comment.