From a54e69396f78c116e538f83c99e9d470d8bfbeb3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 11 Jan 2025 16:20:57 +0200 Subject: [PATCH] Spell "With" instead of "with". --- Doc/library/unittest.rst | 24 +-- Doc/whatsnew/3.14.rst | 8 +- Lib/test/test_gdb/test_misc.py | 6 +- .../resources/test_functional.py | 4 +- Lib/test/test_typing.py | 110 ++++++------- Lib/test/test_unittest/test_case.py | 148 +++++++++--------- Lib/test/test_unittest/test_loader.py | 2 +- Lib/test/test_unittest/test_program.py | 8 +- Lib/test/test_unittest/test_result.py | 2 +- Lib/test/test_venv.py | 6 +- Lib/unittest/case.py | 8 +- ...5-01-10-15-06-45.gh-issue-71339.EKnpzw.rst | 8 +- 12 files changed, 167 insertions(+), 167 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index f1f3f887de81ef..d885f8b576de0f 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1224,17 +1224,17 @@ Test cases | ` | elements in the same number, | | | | regardless of their order. | | +---------------------------------------+--------------------------------+--------------+ - | :meth:`assertStartswith(a, b) | ``a.startswith(b)`` | 3.14 | - | ` | | | + | :meth:`assertStartsWith(a, b) | ``a.startswith(b)`` | 3.14 | + | ` | | | +---------------------------------------+--------------------------------+--------------+ - | :meth:`assertNotStartswith(a, b) | ``not a.startswith(b)`` | 3.14 | - | ` | | | + | :meth:`assertNotStartsWith(a, b) | ``not a.startswith(b)`` | 3.14 | + | ` | | | +---------------------------------------+--------------------------------+--------------+ - | :meth:`assertEndswith(a, b) | ``a.endswith(b)`` | 3.14 | - | ` | | | + | :meth:`assertEndsWith(a, b) | ``a.endswith(b)`` | 3.14 | + | ` | | | +---------------------------------------+--------------------------------+--------------+ - | :meth:`assertNotEndswith(a, b) | ``not a.endswith(b)`` | 3.14 | - | ` | | | + | :meth:`assertNotEndsWith(a, b) | ``not a.endswith(b)`` | 3.14 | + | ` | | | +---------------------------------------+--------------------------------+--------------+ | :meth:`assertHasAttr(a, b) | ``hastattr(a, b)`` | 3.14 | | ` | | | @@ -1310,8 +1310,8 @@ Test cases .. versionadded:: 3.2 - .. method:: assertStartswith(s, prefix, msg=None) - .. method:: assertNotStartswith(s, prefix, msg=None) + .. method:: assertStartsWith(s, prefix, msg=None) + .. method:: assertNotStartsWith(s, prefix, msg=None) Test that the unicode or byte string *s* starts (or does not start) with a *prefix*. @@ -1319,8 +1319,8 @@ Test cases .. versionadded:: next - .. method:: assertEndswith(s, suffix, msg=None) - .. method:: assertNotEndswith(s, suffix, msg=None) + .. method:: assertEndsWith(s, suffix, msg=None) + .. method:: assertNotEndsWith(s, suffix, msg=None) Test that the unicode or byte string *s* ends (or does not end) with a *suffix*. diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 5f2f8f63c916cc..29f520ed05c030 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -679,10 +679,10 @@ unittest - :meth:`~unittest.TestCase.assertIsSubclass` and :meth:`~unittest.TestCase.assertNotIsSubclass` check whether the object is a subclass of a particular class, or of one of a tuple of classes. - - :meth:`~unittest.TestCase.assertStartswith`, - :meth:`~unittest.TestCase.assertNotStartswith`, - :meth:`~unittest.TestCase.assertEndswith` and - :meth:`~unittest.TestCase.assertNotEndswith` check whether the unicode + - :meth:`~unittest.TestCase.assertStartsWith`, + :meth:`~unittest.TestCase.assertNotStartsWith`, + :meth:`~unittest.TestCase.assertEndsWith` and + :meth:`~unittest.TestCase.assertNotEndsWith` check whether the unicode or byte string starts or ends with particular string(s). (Contributed by Serhiy Storchaka in :gh:`71339`.) diff --git a/Lib/test/test_gdb/test_misc.py b/Lib/test/test_gdb/test_misc.py index a66ab8d574b747..1047f4867c1d03 100644 --- a/Lib/test/test_gdb/test_misc.py +++ b/Lib/test/test_gdb/test_misc.py @@ -28,7 +28,7 @@ def gdb_has_frame_select(): "Python was compiled with optimizations") class PyListTests(DebuggerTests): def assertListing(self, expected, actual): - self.assertEndswith(actual, expected) + self.assertEndsWith(actual, expected) def test_basic_command(self): 'Verify that the "py-list" command works' @@ -103,7 +103,7 @@ def test_down_at_bottom(self): 'Verify handling of "py-down" at the bottom of the stack' bt = self.get_stack_trace(script=SAMPLE_SCRIPT, cmds_after_breakpoint=['py-down']) - self.assertEndswith(bt, + self.assertEndsWith(bt, 'Unable to find a newer python frame\n') @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") @@ -111,7 +111,7 @@ def test_up_at_top(self): 'Verify handling of "py-up" at the top of the stack' bt = self.get_stack_trace(script=SAMPLE_SCRIPT, cmds_after_breakpoint=['py-up'] * 5) - self.assertEndswith(bt, + self.assertEndsWith(bt, 'Unable to find an older python frame\n') @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") diff --git a/Lib/test/test_importlib/resources/test_functional.py b/Lib/test/test_importlib/resources/test_functional.py index 8070fce20bb3c9..e8d25fa4d9faf0 100644 --- a/Lib/test/test_importlib/resources/test_functional.py +++ b/Lib/test/test_importlib/resources/test_functional.py @@ -83,7 +83,7 @@ def test_read_text(self): ), '\x00\x01\x02\x03', ) - self.assertEndswith( # ignore the BOM + self.assertEndsWith( # ignore the BOM resources.read_text( self.anchor01, 'utf-16.file', @@ -135,7 +135,7 @@ def test_open_text(self): 'utf-16.file', errors='backslashreplace', ) as f: - self.assertEndswith( # ignore the BOM + self.assertEndsWith( # ignore the BOM f.read(), 'Hello, UTF-16 world!\n'.encode('utf-16-le').decode( errors='backslashreplace', diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 931ce8ed09fc29..c98e6f820e8cf7 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1426,31 +1426,31 @@ def test_variadic_class_repr_is_correct(self): class A(Generic[*Ts]): pass class B(Generic[Unpack[Ts]]): pass - self.assertEndswith(repr(A[()]), 'A[()]') - self.assertEndswith(repr(B[()]), 'B[()]') - self.assertEndswith(repr(A[float]), 'A[float]') - self.assertEndswith(repr(B[float]), 'B[float]') - self.assertEndswith(repr(A[float, str]), 'A[float, str]') - self.assertEndswith(repr(B[float, str]), 'B[float, str]') - - self.assertEndswith(repr(A[*tuple[int, ...]]), + self.assertEndsWith(repr(A[()]), 'A[()]') + self.assertEndsWith(repr(B[()]), 'B[()]') + self.assertEndsWith(repr(A[float]), 'A[float]') + self.assertEndsWith(repr(B[float]), 'B[float]') + self.assertEndsWith(repr(A[float, str]), 'A[float, str]') + self.assertEndsWith(repr(B[float, str]), 'B[float, str]') + + self.assertEndsWith(repr(A[*tuple[int, ...]]), 'A[*tuple[int, ...]]') - self.assertEndswith(repr(B[Unpack[Tuple[int, ...]]]), + self.assertEndsWith(repr(B[Unpack[Tuple[int, ...]]]), 'B[typing.Unpack[typing.Tuple[int, ...]]]') - self.assertEndswith(repr(A[float, *tuple[int, ...]]), + self.assertEndsWith(repr(A[float, *tuple[int, ...]]), 'A[float, *tuple[int, ...]]') - self.assertEndswith(repr(A[float, Unpack[Tuple[int, ...]]]), + self.assertEndsWith(repr(A[float, Unpack[Tuple[int, ...]]]), 'A[float, typing.Unpack[typing.Tuple[int, ...]]]') - self.assertEndswith(repr(A[*tuple[int, ...], str]), + self.assertEndsWith(repr(A[*tuple[int, ...], str]), 'A[*tuple[int, ...], str]') - self.assertEndswith(repr(B[Unpack[Tuple[int, ...]], str]), + self.assertEndsWith(repr(B[Unpack[Tuple[int, ...]], str]), 'B[typing.Unpack[typing.Tuple[int, ...]], str]') - self.assertEndswith(repr(A[float, *tuple[int, ...], str]), + self.assertEndsWith(repr(A[float, *tuple[int, ...], str]), 'A[float, *tuple[int, ...], str]') - self.assertEndswith(repr(B[float, Unpack[Tuple[int, ...]], str]), + self.assertEndsWith(repr(B[float, Unpack[Tuple[int, ...]], str]), 'B[float, typing.Unpack[typing.Tuple[int, ...]], str]') def test_variadic_class_alias_repr_is_correct(self): @@ -1458,64 +1458,64 @@ def test_variadic_class_alias_repr_is_correct(self): class A(Generic[Unpack[Ts]]): pass B = A[*Ts] - self.assertEndswith(repr(B), 'A[typing.Unpack[Ts]]') - self.assertEndswith(repr(B[()]), 'A[()]') - self.assertEndswith(repr(B[float]), 'A[float]') - self.assertEndswith(repr(B[float, str]), 'A[float, str]') + self.assertEndsWith(repr(B), 'A[typing.Unpack[Ts]]') + self.assertEndsWith(repr(B[()]), 'A[()]') + self.assertEndsWith(repr(B[float]), 'A[float]') + self.assertEndsWith(repr(B[float, str]), 'A[float, str]') C = A[Unpack[Ts]] - self.assertEndswith(repr(C), 'A[typing.Unpack[Ts]]') - self.assertEndswith(repr(C[()]), 'A[()]') - self.assertEndswith(repr(C[float]), 'A[float]') - self.assertEndswith(repr(C[float, str]), 'A[float, str]') + self.assertEndsWith(repr(C), 'A[typing.Unpack[Ts]]') + self.assertEndsWith(repr(C[()]), 'A[()]') + self.assertEndsWith(repr(C[float]), 'A[float]') + self.assertEndsWith(repr(C[float, str]), 'A[float, str]') D = A[*Ts, int] - self.assertEndswith(repr(D), 'A[typing.Unpack[Ts], int]') - self.assertEndswith(repr(D[()]), 'A[int]') - self.assertEndswith(repr(D[float]), 'A[float, int]') - self.assertEndswith(repr(D[float, str]), 'A[float, str, int]') + self.assertEndsWith(repr(D), 'A[typing.Unpack[Ts], int]') + self.assertEndsWith(repr(D[()]), 'A[int]') + self.assertEndsWith(repr(D[float]), 'A[float, int]') + self.assertEndsWith(repr(D[float, str]), 'A[float, str, int]') E = A[Unpack[Ts], int] - self.assertEndswith(repr(E), 'A[typing.Unpack[Ts], int]') - self.assertEndswith(repr(E[()]), 'A[int]') - self.assertEndswith(repr(E[float]), 'A[float, int]') - self.assertEndswith(repr(E[float, str]), 'A[float, str, int]') + self.assertEndsWith(repr(E), 'A[typing.Unpack[Ts], int]') + self.assertEndsWith(repr(E[()]), 'A[int]') + self.assertEndsWith(repr(E[float]), 'A[float, int]') + self.assertEndsWith(repr(E[float, str]), 'A[float, str, int]') F = A[int, *Ts] - self.assertEndswith(repr(F), 'A[int, typing.Unpack[Ts]]') - self.assertEndswith(repr(F[()]), 'A[int]') - self.assertEndswith(repr(F[float]), 'A[int, float]') - self.assertEndswith(repr(F[float, str]), 'A[int, float, str]') + self.assertEndsWith(repr(F), 'A[int, typing.Unpack[Ts]]') + self.assertEndsWith(repr(F[()]), 'A[int]') + self.assertEndsWith(repr(F[float]), 'A[int, float]') + self.assertEndsWith(repr(F[float, str]), 'A[int, float, str]') G = A[int, Unpack[Ts]] - self.assertEndswith(repr(G), 'A[int, typing.Unpack[Ts]]') - self.assertEndswith(repr(G[()]), 'A[int]') - self.assertEndswith(repr(G[float]), 'A[int, float]') - self.assertEndswith(repr(G[float, str]), 'A[int, float, str]') + self.assertEndsWith(repr(G), 'A[int, typing.Unpack[Ts]]') + self.assertEndsWith(repr(G[()]), 'A[int]') + self.assertEndsWith(repr(G[float]), 'A[int, float]') + self.assertEndsWith(repr(G[float, str]), 'A[int, float, str]') H = A[int, *Ts, str] - self.assertEndswith(repr(H), 'A[int, typing.Unpack[Ts], str]') - self.assertEndswith(repr(H[()]), 'A[int, str]') - self.assertEndswith(repr(H[float]), 'A[int, float, str]') - self.assertEndswith(repr(H[float, str]), 'A[int, float, str, str]') + self.assertEndsWith(repr(H), 'A[int, typing.Unpack[Ts], str]') + self.assertEndsWith(repr(H[()]), 'A[int, str]') + self.assertEndsWith(repr(H[float]), 'A[int, float, str]') + self.assertEndsWith(repr(H[float, str]), 'A[int, float, str, str]') I = A[int, Unpack[Ts], str] - self.assertEndswith(repr(I), 'A[int, typing.Unpack[Ts], str]') - self.assertEndswith(repr(I[()]), 'A[int, str]') - self.assertEndswith(repr(I[float]), 'A[int, float, str]') - self.assertEndswith(repr(I[float, str]), 'A[int, float, str, str]') + self.assertEndsWith(repr(I), 'A[int, typing.Unpack[Ts], str]') + self.assertEndsWith(repr(I[()]), 'A[int, str]') + self.assertEndsWith(repr(I[float]), 'A[int, float, str]') + self.assertEndsWith(repr(I[float, str]), 'A[int, float, str, str]') J = A[*Ts, *tuple[str, ...]] - self.assertEndswith(repr(J), 'A[typing.Unpack[Ts], *tuple[str, ...]]') - self.assertEndswith(repr(J[()]), 'A[*tuple[str, ...]]') - self.assertEndswith(repr(J[float]), 'A[float, *tuple[str, ...]]') - self.assertEndswith(repr(J[float, str]), 'A[float, str, *tuple[str, ...]]') + self.assertEndsWith(repr(J), 'A[typing.Unpack[Ts], *tuple[str, ...]]') + self.assertEndsWith(repr(J[()]), 'A[*tuple[str, ...]]') + self.assertEndsWith(repr(J[float]), 'A[float, *tuple[str, ...]]') + self.assertEndsWith(repr(J[float, str]), 'A[float, str, *tuple[str, ...]]') K = A[Unpack[Ts], Unpack[Tuple[str, ...]]] - self.assertEndswith(repr(K), 'A[typing.Unpack[Ts], typing.Unpack[typing.Tuple[str, ...]]]') - self.assertEndswith(repr(K[()]), 'A[typing.Unpack[typing.Tuple[str, ...]]]') - self.assertEndswith(repr(K[float]), 'A[float, typing.Unpack[typing.Tuple[str, ...]]]') - self.assertEndswith(repr(K[float, str]), 'A[float, str, typing.Unpack[typing.Tuple[str, ...]]]') + self.assertEndsWith(repr(K), 'A[typing.Unpack[Ts], typing.Unpack[typing.Tuple[str, ...]]]') + self.assertEndsWith(repr(K[()]), 'A[typing.Unpack[typing.Tuple[str, ...]]]') + self.assertEndsWith(repr(K[float]), 'A[float, typing.Unpack[typing.Tuple[str, ...]]]') + self.assertEndsWith(repr(K[float, str]), 'A[float, str, typing.Unpack[typing.Tuple[str, ...]]]') def test_cannot_subclass(self): with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'TypeVarTuple'): diff --git a/Lib/test/test_unittest/test_case.py b/Lib/test/test_unittest/test_case.py index 3f440f276b768c..5693679191c337 100644 --- a/Lib/test/test_unittest/test_case.py +++ b/Lib/test/test_unittest/test_case.py @@ -90,7 +90,7 @@ class Test(unittest.TestCase): def runTest(self): raise MyException() def test(self): pass - self.assertEndswith(Test().id(), '.Test.runTest') + self.assertEndsWith(Test().id(), '.Test.runTest') # test that TestCase can be instantiated with no args # primarily for use at the interactive interpreter @@ -111,7 +111,7 @@ class Test(unittest.TestCase): def runTest(self): raise MyException() def test(self): pass - self.assertEndswith(Test('test').id(), '.Test.test') + self.assertEndsWith(Test('test').id(), '.Test.test') # "class TestCase([methodName])" # ... @@ -1971,183 +1971,183 @@ def testAssertNoLogsYieldsNone(self): self.assertIsNone(value) def testAssertStartswith(self): - self.assertStartswith('ababahalamaha', 'ababa') - self.assertStartswith('ababahalamaha', ('x', 'ababa', 'y')) - self.assertStartswith(UserString('ababahalamaha'), 'ababa') - self.assertStartswith(UserString('ababahalamaha'), ('x', 'ababa', 'y')) - self.assertStartswith(bytearray(b'ababahalamaha'), b'ababa') - self.assertStartswith(bytearray(b'ababahalamaha'), (b'x', b'ababa', b'y')) - self.assertStartswith(b'ababahalamaha', bytearray(b'ababa')) - self.assertStartswith(b'ababahalamaha', + self.assertStartsWith('ababahalamaha', 'ababa') + self.assertStartsWith('ababahalamaha', ('x', 'ababa', 'y')) + self.assertStartsWith(UserString('ababahalamaha'), 'ababa') + self.assertStartsWith(UserString('ababahalamaha'), ('x', 'ababa', 'y')) + self.assertStartsWith(bytearray(b'ababahalamaha'), b'ababa') + self.assertStartsWith(bytearray(b'ababahalamaha'), (b'x', b'ababa', b'y')) + self.assertStartsWith(b'ababahalamaha', bytearray(b'ababa')) + self.assertStartsWith(b'ababahalamaha', (bytearray(b'x'), bytearray(b'ababa'), bytearray(b'y'))) with self.assertRaises(self.failureException) as cm: - self.assertStartswith('ababahalamaha', 'amaha') + self.assertStartsWith('ababahalamaha', 'amaha') self.assertEqual(str(cm.exception), "'ababahalamaha' doesn't start with 'amaha'") with self.assertRaises(self.failureException) as cm: - self.assertStartswith('ababahalamaha', ('x', 'y')) + self.assertStartsWith('ababahalamaha', ('x', 'y')) self.assertEqual(str(cm.exception), "'ababahalamaha' doesn't start with any of ('x', 'y')") with self.assertRaises(self.failureException) as cm: - self.assertStartswith(b'ababahalamaha', 'ababa') + self.assertStartsWith(b'ababahalamaha', 'ababa') self.assertEqual(str(cm.exception), 'Expected str, not bytes') with self.assertRaises(self.failureException) as cm: - self.assertStartswith(b'ababahalamaha', ('amaha', 'ababa')) + self.assertStartsWith(b'ababahalamaha', ('amaha', 'ababa')) self.assertEqual(str(cm.exception), 'Expected str, not bytes') with self.assertRaises(self.failureException) as cm: - self.assertStartswith([], 'ababa') + self.assertStartsWith([], 'ababa') self.assertEqual(str(cm.exception), 'Expected str, not list') with self.assertRaises(self.failureException) as cm: - self.assertStartswith('ababahalamaha', b'ababa') + self.assertStartsWith('ababahalamaha', b'ababa') self.assertEqual(str(cm.exception), 'Expected bytes, not str') with self.assertRaises(self.failureException) as cm: - self.assertStartswith('ababahalamaha', (b'amaha', b'ababa')) + self.assertStartsWith('ababahalamaha', (b'amaha', b'ababa')) self.assertEqual(str(cm.exception), 'Expected bytes, not str') with self.assertRaises(TypeError): - self.assertStartswith('ababahalamaha', ord('a')) + self.assertStartsWith('ababahalamaha', ord('a')) with self.assertRaises(self.failureException) as cm: - self.assertStartswith('ababahalamaha', 'amaha', 'abracadabra') + self.assertStartsWith('ababahalamaha', 'amaha', 'abracadabra') self.assertIn('ababahalamaha', str(cm.exception)) with self.assertRaises(self.failureException) as cm: - self.assertStartswith('ababahalamaha', 'amaha', msg='abracadabra') + self.assertStartsWith('ababahalamaha', 'amaha', msg='abracadabra') self.assertIn('ababahalamaha', str(cm.exception)) def testAssertNotStartswith(self): - self.assertNotStartswith('ababahalamaha', 'amaha') - self.assertNotStartswith('ababahalamaha', ('x', 'amaha', 'y')) - self.assertNotStartswith(UserString('ababahalamaha'), 'amaha') - self.assertNotStartswith(UserString('ababahalamaha'), ('x', 'amaha', 'y')) - self.assertNotStartswith(bytearray(b'ababahalamaha'), b'amaha') - self.assertNotStartswith(bytearray(b'ababahalamaha'), (b'x', b'amaha', b'y')) - self.assertNotStartswith(b'ababahalamaha', bytearray(b'amaha')) - self.assertNotStartswith(b'ababahalamaha', + self.assertNotStartsWith('ababahalamaha', 'amaha') + self.assertNotStartsWith('ababahalamaha', ('x', 'amaha', 'y')) + self.assertNotStartsWith(UserString('ababahalamaha'), 'amaha') + self.assertNotStartsWith(UserString('ababahalamaha'), ('x', 'amaha', 'y')) + self.assertNotStartsWith(bytearray(b'ababahalamaha'), b'amaha') + self.assertNotStartsWith(bytearray(b'ababahalamaha'), (b'x', b'amaha', b'y')) + self.assertNotStartsWith(b'ababahalamaha', bytearray(b'amaha')) + self.assertNotStartsWith(b'ababahalamaha', (bytearray(b'x'), bytearray(b'amaha'), bytearray(b'y'))) with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith('ababahalamaha', 'ababa') + self.assertNotStartsWith('ababahalamaha', 'ababa') self.assertEqual(str(cm.exception), "'ababahalamaha' starts with 'ababa'") with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith('ababahalamaha', ('x', 'ababa', 'y')) + self.assertNotStartsWith('ababahalamaha', ('x', 'ababa', 'y')) self.assertEqual(str(cm.exception), "'ababahalamaha' starts with 'ababa'") with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith(b'ababahalamaha', 'ababa') + self.assertNotStartsWith(b'ababahalamaha', 'ababa') self.assertEqual(str(cm.exception), 'Expected str, not bytes') with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith(b'ababahalamaha', ('amaha', 'ababa')) + self.assertNotStartsWith(b'ababahalamaha', ('amaha', 'ababa')) self.assertEqual(str(cm.exception), 'Expected str, not bytes') with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith([], 'ababa') + self.assertNotStartsWith([], 'ababa') self.assertEqual(str(cm.exception), 'Expected str, not list') with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith('ababahalamaha', b'ababa') + self.assertNotStartsWith('ababahalamaha', b'ababa') self.assertEqual(str(cm.exception), 'Expected bytes, not str') with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith('ababahalamaha', (b'amaha', b'ababa')) + self.assertNotStartsWith('ababahalamaha', (b'amaha', b'ababa')) self.assertEqual(str(cm.exception), 'Expected bytes, not str') with self.assertRaises(TypeError): - self.assertNotStartswith('ababahalamaha', ord('a')) + self.assertNotStartsWith('ababahalamaha', ord('a')) with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith('ababahalamaha', 'ababa', 'abracadabra') + self.assertNotStartsWith('ababahalamaha', 'ababa', 'abracadabra') self.assertIn('ababahalamaha', str(cm.exception)) with self.assertRaises(self.failureException) as cm: - self.assertNotStartswith('ababahalamaha', 'ababa', msg='abracadabra') + self.assertNotStartsWith('ababahalamaha', 'ababa', msg='abracadabra') self.assertIn('ababahalamaha', str(cm.exception)) def testAssertEndswith(self): - self.assertEndswith('ababahalamaha', 'amaha') - self.assertEndswith('ababahalamaha', ('x', 'amaha', 'y')) - self.assertEndswith(UserString('ababahalamaha'), 'amaha') - self.assertEndswith(UserString('ababahalamaha'), ('x', 'amaha', 'y')) - self.assertEndswith(bytearray(b'ababahalamaha'), b'amaha') - self.assertEndswith(bytearray(b'ababahalamaha'), (b'x', b'amaha', b'y')) - self.assertEndswith(b'ababahalamaha', bytearray(b'amaha')) - self.assertEndswith(b'ababahalamaha', + self.assertEndsWith('ababahalamaha', 'amaha') + self.assertEndsWith('ababahalamaha', ('x', 'amaha', 'y')) + self.assertEndsWith(UserString('ababahalamaha'), 'amaha') + self.assertEndsWith(UserString('ababahalamaha'), ('x', 'amaha', 'y')) + self.assertEndsWith(bytearray(b'ababahalamaha'), b'amaha') + self.assertEndsWith(bytearray(b'ababahalamaha'), (b'x', b'amaha', b'y')) + self.assertEndsWith(b'ababahalamaha', bytearray(b'amaha')) + self.assertEndsWith(b'ababahalamaha', (bytearray(b'x'), bytearray(b'amaha'), bytearray(b'y'))) with self.assertRaises(self.failureException) as cm: - self.assertEndswith('ababahalamaha', 'ababa') + self.assertEndsWith('ababahalamaha', 'ababa') self.assertEqual(str(cm.exception), "'ababahalamaha' doesn't end with 'ababa'") with self.assertRaises(self.failureException) as cm: - self.assertEndswith('ababahalamaha', ('x', 'y')) + self.assertEndsWith('ababahalamaha', ('x', 'y')) self.assertEqual(str(cm.exception), "'ababahalamaha' doesn't end with any of ('x', 'y')") with self.assertRaises(self.failureException) as cm: - self.assertEndswith(b'ababahalamaha', 'amaha') + self.assertEndsWith(b'ababahalamaha', 'amaha') self.assertEqual(str(cm.exception), 'Expected str, not bytes') with self.assertRaises(self.failureException) as cm: - self.assertEndswith(b'ababahalamaha', ('ababa', 'amaha')) + self.assertEndsWith(b'ababahalamaha', ('ababa', 'amaha')) self.assertEqual(str(cm.exception), 'Expected str, not bytes') with self.assertRaises(self.failureException) as cm: - self.assertEndswith([], 'amaha') + self.assertEndsWith([], 'amaha') self.assertEqual(str(cm.exception), 'Expected str, not list') with self.assertRaises(self.failureException) as cm: - self.assertEndswith('ababahalamaha', b'amaha') + self.assertEndsWith('ababahalamaha', b'amaha') self.assertEqual(str(cm.exception), 'Expected bytes, not str') with self.assertRaises(self.failureException) as cm: - self.assertEndswith('ababahalamaha', (b'ababa', b'amaha')) + self.assertEndsWith('ababahalamaha', (b'ababa', b'amaha')) self.assertEqual(str(cm.exception), 'Expected bytes, not str') with self.assertRaises(TypeError): - self.assertEndswith('ababahalamaha', ord('a')) + self.assertEndsWith('ababahalamaha', ord('a')) with self.assertRaises(self.failureException) as cm: - self.assertEndswith('ababahalamaha', 'ababa', 'abracadabra') + self.assertEndsWith('ababahalamaha', 'ababa', 'abracadabra') self.assertIn('ababahalamaha', str(cm.exception)) with self.assertRaises(self.failureException) as cm: - self.assertEndswith('ababahalamaha', 'ababa', msg='abracadabra') + self.assertEndsWith('ababahalamaha', 'ababa', msg='abracadabra') self.assertIn('ababahalamaha', str(cm.exception)) def testAssertNotEndswith(self): - self.assertNotEndswith('ababahalamaha', 'ababa') - self.assertNotEndswith('ababahalamaha', ('x', 'ababa', 'y')) - self.assertNotEndswith(UserString('ababahalamaha'), 'ababa') - self.assertNotEndswith(UserString('ababahalamaha'), ('x', 'ababa', 'y')) - self.assertNotEndswith(bytearray(b'ababahalamaha'), b'ababa') - self.assertNotEndswith(bytearray(b'ababahalamaha'), (b'x', b'ababa', b'y')) - self.assertNotEndswith(b'ababahalamaha', bytearray(b'ababa')) - self.assertNotEndswith(b'ababahalamaha', + self.assertNotEndsWith('ababahalamaha', 'ababa') + self.assertNotEndsWith('ababahalamaha', ('x', 'ababa', 'y')) + self.assertNotEndsWith(UserString('ababahalamaha'), 'ababa') + self.assertNotEndsWith(UserString('ababahalamaha'), ('x', 'ababa', 'y')) + self.assertNotEndsWith(bytearray(b'ababahalamaha'), b'ababa') + self.assertNotEndsWith(bytearray(b'ababahalamaha'), (b'x', b'ababa', b'y')) + self.assertNotEndsWith(b'ababahalamaha', bytearray(b'ababa')) + self.assertNotEndsWith(b'ababahalamaha', (bytearray(b'x'), bytearray(b'ababa'), bytearray(b'y'))) with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith('ababahalamaha', 'amaha') + self.assertNotEndsWith('ababahalamaha', 'amaha') self.assertEqual(str(cm.exception), "'ababahalamaha' ends with 'amaha'") with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith('ababahalamaha', ('x', 'amaha', 'y')) + self.assertNotEndsWith('ababahalamaha', ('x', 'amaha', 'y')) self.assertEqual(str(cm.exception), "'ababahalamaha' ends with 'amaha'") with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith(b'ababahalamaha', 'amaha') + self.assertNotEndsWith(b'ababahalamaha', 'amaha') self.assertEqual(str(cm.exception), 'Expected str, not bytes') with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith(b'ababahalamaha', ('ababa', 'amaha')) + self.assertNotEndsWith(b'ababahalamaha', ('ababa', 'amaha')) self.assertEqual(str(cm.exception), 'Expected str, not bytes') with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith([], 'amaha') + self.assertNotEndsWith([], 'amaha') self.assertEqual(str(cm.exception), 'Expected str, not list') with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith('ababahalamaha', b'amaha') + self.assertNotEndsWith('ababahalamaha', b'amaha') self.assertEqual(str(cm.exception), 'Expected bytes, not str') with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith('ababahalamaha', (b'ababa', b'amaha')) + self.assertNotEndsWith('ababahalamaha', (b'ababa', b'amaha')) self.assertEqual(str(cm.exception), 'Expected bytes, not str') with self.assertRaises(TypeError): - self.assertNotEndswith('ababahalamaha', ord('a')) + self.assertNotEndsWith('ababahalamaha', ord('a')) with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith('ababahalamaha', 'amaha', 'abracadabra') + self.assertNotEndsWith('ababahalamaha', 'amaha', 'abracadabra') self.assertIn('ababahalamaha', str(cm.exception)) with self.assertRaises(self.failureException) as cm: - self.assertNotEndswith('ababahalamaha', 'amaha', msg='abracadabra') + self.assertNotEndsWith('ababahalamaha', 'amaha', msg='abracadabra') self.assertIn('ababahalamaha', str(cm.exception)) def testDeprecatedFailMethods(self): diff --git a/Lib/test/test_unittest/test_loader.py b/Lib/test/test_unittest/test_loader.py index 3b0b72fdd275ac..cdff6d1a20c8df 100644 --- a/Lib/test/test_unittest/test_loader.py +++ b/Lib/test/test_unittest/test_loader.py @@ -76,7 +76,7 @@ def runTest(self): loader = unittest.TestLoader() # This has to be false for the test to succeed - self.assertNotStartswith('runTest', loader.testMethodPrefix) + self.assertNotStartsWith('runTest', loader.testMethodPrefix) suite = loader.loadTestsFromTestCase(Foo) self.assertIsInstance(suite, loader.suiteClass) diff --git a/Lib/test/test_unittest/test_program.py b/Lib/test/test_unittest/test_program.py index 93463ccbfb18b2..58d0cef9708c95 100644 --- a/Lib/test/test_unittest/test_program.py +++ b/Lib/test/test_unittest/test_program.py @@ -135,7 +135,7 @@ def test_NonExit(self): self.assertIn('\nUNEXPECTED SUCCESS: testUnexpectedSuccess ', out) expected = ('\n\nFAILED (failures=1, errors=1, skipped=1, ' 'expected failures=1, unexpected successes=1)\n') - self.assertEndswith(out, expected) + self.assertEndsWith(out, expected) @force_not_colorized def test_Exit(self): @@ -153,7 +153,7 @@ def test_Exit(self): self.assertIn('\nUNEXPECTED SUCCESS: testUnexpectedSuccess ', out) expected = ('\n\nFAILED (failures=1, errors=1, skipped=1, ' 'expected failures=1, unexpected successes=1)\n') - self.assertEndswith(out, expected) + self.assertEndsWith(out, expected) @force_not_colorized def test_ExitAsDefault(self): @@ -169,7 +169,7 @@ def test_ExitAsDefault(self): self.assertIn('\nUNEXPECTED SUCCESS: testUnexpectedSuccess ', out) expected = ('\n\nFAILED (failures=1, errors=1, skipped=1, ' 'expected failures=1, unexpected successes=1)\n') - self.assertEndswith(out, expected) + self.assertEndsWith(out, expected) @force_not_colorized def test_ExitSkippedSuite(self): @@ -182,7 +182,7 @@ def test_ExitSkippedSuite(self): self.assertEqual(cm.exception.code, 0) out = stream.getvalue() expected = '\n\nOK (skipped=1)\n' - self.assertEndswith(out, expected) + self.assertEndsWith(out, expected) @force_not_colorized def test_ExitEmptySuite(self): diff --git a/Lib/test/test_unittest/test_result.py b/Lib/test/test_unittest/test_result.py index 904349ae710fa9..460c09f20e46e2 100644 --- a/Lib/test/test_unittest/test_result.py +++ b/Lib/test/test_unittest/test_result.py @@ -460,7 +460,7 @@ def test(result): self.assertTrue(result.failfast) result = runner.run(test) stream.flush() - self.assertEndswith(stream.getvalue(), '\n\nOK\n') + self.assertEndsWith(stream.getvalue(), '\n\nOK\n') class Test_TextTestResult(unittest.TestCase): diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 19115b0d08f87b..6e23097deaf221 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -513,7 +513,7 @@ def test_special_chars_bash(self): out, err = check_output([bash, test_script]) lines = out.splitlines() self.assertTrue(env_name.encode() in lines[0]) - self.assertEndswith(lines[1], env_name.encode()) + self.assertEndsWith(lines[1], env_name.encode()) # gh-124651: test quoted strings @unittest.skipIf(os.name == 'nt', 'contains invalid characters on Windows') @@ -539,7 +539,7 @@ def test_special_chars_csh(self): out, err = check_output([csh, test_script]) lines = out.splitlines() self.assertTrue(env_name.encode() in lines[0]) - self.assertEndswith(lines[1], env_name.encode()) + self.assertEndsWith(lines[1], env_name.encode()) # gh-124651: test quoted strings on Windows @unittest.skipUnless(os.name == 'nt', 'only relevant on Windows') @@ -563,7 +563,7 @@ def test_special_chars_windows(self): out, err = check_output([test_batch]) lines = out.splitlines() self.assertTrue(env_name.encode() in lines[0]) - self.assertEndswith(lines[1], env_name.encode()) + self.assertEndsWith(lines[1], env_name.encode()) @unittest.skipUnless(os.name == 'nt', 'only relevant on Windows') def test_unicode_in_batch_file(self): diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 3df95d47429d40..dfc7830b920b14 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -1466,7 +1466,7 @@ def _tail_type_check(self, s, tails, msg): self.fail(self._formatMessage(msg, 'Expected bytes, not %s' % (type(s).__name__,))) - def assertStartswith(self, s, prefix, msg=None): + def assertStartsWith(self, s, prefix, msg=None): try: r = s.startswith(prefix) except (AttributeError, TypeError): @@ -1482,7 +1482,7 @@ def assertStartswith(self, s, prefix, msg=None): self.fail(self._formatMessage(msg, "%s doesn't start with %s" % (a, b))) - def assertNotStartswith(self, s, prefix, msg=None): + def assertNotStartsWith(self, s, prefix, msg=None): try: r = s.startswith(prefix) except (AttributeError, TypeError): @@ -1499,7 +1499,7 @@ def assertNotStartswith(self, s, prefix, msg=None): self.fail(self._formatMessage(msg, "%s starts with %s" % (a, b))) - def assertEndswith(self, s, suffix, msg=None): + def assertEndsWith(self, s, suffix, msg=None): try: r = s.endswith(suffix) except (AttributeError, TypeError): @@ -1515,7 +1515,7 @@ def assertEndswith(self, s, suffix, msg=None): self.fail(self._formatMessage(msg, "%s doesn't end with %s" % (a, b))) - def assertNotEndswith(self, s, suffix, msg=None): + def assertNotEndsWith(self, s, suffix, msg=None): try: r = s.endswith(suffix) except (AttributeError, TypeError): diff --git a/Misc/NEWS.d/next/Library/2025-01-10-15-06-45.gh-issue-71339.EKnpzw.rst b/Misc/NEWS.d/next/Library/2025-01-10-15-06-45.gh-issue-71339.EKnpzw.rst index 1d10e4a4dfe3bc..5f33a30bd5eae1 100644 --- a/Misc/NEWS.d/next/Library/2025-01-10-15-06-45.gh-issue-71339.EKnpzw.rst +++ b/Misc/NEWS.d/next/Library/2025-01-10-15-06-45.gh-issue-71339.EKnpzw.rst @@ -3,7 +3,7 @@ Add new assertion methods for :mod:`unittest`: :meth:`~unittest.TestCase.assertNotHasAttr`, :meth:`~unittest.TestCase.assertIsSubclass`, :meth:`~unittest.TestCase.assertNotIsSubclass` -:meth:`~unittest.TestCase.assertStartswith`, -:meth:`~unittest.TestCase.assertNotStartswith`, -:meth:`~unittest.TestCase.assertEndswith` and -:meth:`~unittest.TestCase.assertNotEndswith`. +:meth:`~unittest.TestCase.assertStartsWith`, +:meth:`~unittest.TestCase.assertNotStartsWith`, +:meth:`~unittest.TestCase.assertEndsWith` and +:meth:`~unittest.TestCase.assertNotEndsWith`.