mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	[3.14] gh-71339: Use new assertion methods in tests (GH-129046) (GH-134498)
(cherry picked from commit 2602d8ae98)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									d5f7e80d44
								
							
						
					
					
						commit
						db98e0bb12
					
				
					 117 changed files with 407 additions and 445 deletions
				
			
		|  | @ -11,7 +11,7 @@ def check_structseq(self, obj_type): | ||||||
|         # ob_refcnt |         # ob_refcnt | ||||||
|         self.assertGreaterEqual(sys.getrefcount(obj_type), 1) |         self.assertGreaterEqual(sys.getrefcount(obj_type), 1) | ||||||
|         # tp_base |         # tp_base | ||||||
|         self.assertTrue(issubclass(obj_type, tuple)) |         self.assertIsSubclass(obj_type, tuple) | ||||||
|         # tp_bases |         # tp_bases | ||||||
|         self.assertEqual(obj_type.__bases__, (tuple,)) |         self.assertEqual(obj_type.__bases__, (tuple,)) | ||||||
|         # tp_dict |         # tp_dict | ||||||
|  |  | ||||||
|  | @ -183,7 +183,7 @@ class NotEnough(tzinfo): | ||||||
|             def __init__(self, offset, name): |             def __init__(self, offset, name): | ||||||
|                 self.__offset = offset |                 self.__offset = offset | ||||||
|                 self.__name = name |                 self.__name = name | ||||||
|         self.assertTrue(issubclass(NotEnough, tzinfo)) |         self.assertIsSubclass(NotEnough, tzinfo) | ||||||
|         ne = NotEnough(3, "NotByALongShot") |         ne = NotEnough(3, "NotByALongShot") | ||||||
|         self.assertIsInstance(ne, tzinfo) |         self.assertIsInstance(ne, tzinfo) | ||||||
| 
 | 
 | ||||||
|  | @ -232,7 +232,7 @@ def test_pickling_subclass(self): | ||||||
|                 self.assertIs(type(derived), otype) |                 self.assertIs(type(derived), otype) | ||||||
|                 self.assertEqual(derived.utcoffset(None), offset) |                 self.assertEqual(derived.utcoffset(None), offset) | ||||||
|                 self.assertEqual(derived.tzname(None), oname) |                 self.assertEqual(derived.tzname(None), oname) | ||||||
|                 self.assertFalse(hasattr(derived, 'spam')) |                 self.assertNotHasAttr(derived, 'spam') | ||||||
| 
 | 
 | ||||||
|     def test_issue23600(self): |     def test_issue23600(self): | ||||||
|         DSTDIFF = DSTOFFSET = timedelta(hours=1) |         DSTDIFF = DSTOFFSET = timedelta(hours=1) | ||||||
|  | @ -813,7 +813,7 @@ def test_roundtrip(self): | ||||||
| 
 | 
 | ||||||
|             # Verify td -> string -> td identity. |             # Verify td -> string -> td identity. | ||||||
|             s = repr(td) |             s = repr(td) | ||||||
|             self.assertTrue(s.startswith('datetime.')) |             self.assertStartsWith(s, 'datetime.') | ||||||
|             s = s[9:] |             s = s[9:] | ||||||
|             td2 = eval(s) |             td2 = eval(s) | ||||||
|             self.assertEqual(td, td2) |             self.assertEqual(td, td2) | ||||||
|  | @ -1231,7 +1231,7 @@ def test_roundtrip(self): | ||||||
|                    self.theclass.today()): |                    self.theclass.today()): | ||||||
|             # Verify dt -> string -> date identity. |             # Verify dt -> string -> date identity. | ||||||
|             s = repr(dt) |             s = repr(dt) | ||||||
|             self.assertTrue(s.startswith('datetime.')) |             self.assertStartsWith(s, 'datetime.') | ||||||
|             s = s[9:] |             s = s[9:] | ||||||
|             dt2 = eval(s) |             dt2 = eval(s) | ||||||
|             self.assertEqual(dt, dt2) |             self.assertEqual(dt, dt2) | ||||||
|  | @ -2218,7 +2218,7 @@ def test_roundtrip(self): | ||||||
|                    self.theclass.now()): |                    self.theclass.now()): | ||||||
|             # Verify dt -> string -> datetime identity. |             # Verify dt -> string -> datetime identity. | ||||||
|             s = repr(dt) |             s = repr(dt) | ||||||
|             self.assertTrue(s.startswith('datetime.')) |             self.assertStartsWith(s, 'datetime.') | ||||||
|             s = s[9:] |             s = s[9:] | ||||||
|             dt2 = eval(s) |             dt2 = eval(s) | ||||||
|             self.assertEqual(dt, dt2) |             self.assertEqual(dt, dt2) | ||||||
|  | @ -3672,7 +3672,7 @@ def test_roundtrip(self): | ||||||
| 
 | 
 | ||||||
|         # Verify t -> string -> time identity. |         # Verify t -> string -> time identity. | ||||||
|         s = repr(t) |         s = repr(t) | ||||||
|         self.assertTrue(s.startswith('datetime.')) |         self.assertStartsWith(s, 'datetime.') | ||||||
|         s = s[9:] |         s = s[9:] | ||||||
|         t2 = eval(s) |         t2 = eval(s) | ||||||
|         self.assertEqual(t, t2) |         self.assertEqual(t, t2) | ||||||
|  |  | ||||||
|  | @ -70,8 +70,8 @@ def test_read(self): | ||||||
|         if not d: self.fail("Full mapping must compare to True") |         if not d: self.fail("Full mapping must compare to True") | ||||||
|         # keys(), items(), iterkeys() ... |         # keys(), items(), iterkeys() ... | ||||||
|         def check_iterandlist(iter, lst, ref): |         def check_iterandlist(iter, lst, ref): | ||||||
|             self.assertTrue(hasattr(iter, '__next__')) |             self.assertHasAttr(iter, '__next__') | ||||||
|             self.assertTrue(hasattr(iter, '__iter__')) |             self.assertHasAttr(iter, '__iter__') | ||||||
|             x = list(iter) |             x = list(iter) | ||||||
|             self.assertTrue(set(x)==set(lst)==set(ref)) |             self.assertTrue(set(x)==set(lst)==set(ref)) | ||||||
|         check_iterandlist(iter(d.keys()), list(d.keys()), |         check_iterandlist(iter(d.keys()), list(d.keys()), | ||||||
|  |  | ||||||
|  | @ -3068,7 +3068,7 @@ def test_proto(self): | ||||||
|             pickled = self.dumps(None, proto) |             pickled = self.dumps(None, proto) | ||||||
|             if proto >= 2: |             if proto >= 2: | ||||||
|                 proto_header = pickle.PROTO + bytes([proto]) |                 proto_header = pickle.PROTO + bytes([proto]) | ||||||
|                 self.assertTrue(pickled.startswith(proto_header)) |                 self.assertStartsWith(pickled, proto_header) | ||||||
|             else: |             else: | ||||||
|                 self.assertEqual(count_opcode(pickle.PROTO, pickled), 0) |                 self.assertEqual(count_opcode(pickle.PROTO, pickled), 0) | ||||||
| 
 | 
 | ||||||
|  | @ -5007,7 +5007,7 @@ def test_default_dispatch_table(self): | ||||||
|         p = self.pickler_class(f, 0) |         p = self.pickler_class(f, 0) | ||||||
|         with self.assertRaises(AttributeError): |         with self.assertRaises(AttributeError): | ||||||
|             p.dispatch_table |             p.dispatch_table | ||||||
|         self.assertFalse(hasattr(p, 'dispatch_table')) |         self.assertNotHasAttr(p, 'dispatch_table') | ||||||
| 
 | 
 | ||||||
|     def test_class_dispatch_table(self): |     def test_class_dispatch_table(self): | ||||||
|         # A dispatch_table attribute can be specified class-wide |         # A dispatch_table attribute can be specified class-wide | ||||||
|  |  | ||||||
|  | @ -23,8 +23,7 @@ def check_syntax_warning(testcase, statement, errtext='', | ||||||
|     testcase.assertEqual(len(warns), 1, warns) |     testcase.assertEqual(len(warns), 1, warns) | ||||||
| 
 | 
 | ||||||
|     warn, = warns |     warn, = warns | ||||||
|     testcase.assertTrue(issubclass(warn.category, SyntaxWarning), |     testcase.assertIsSubclass(warn.category, SyntaxWarning) | ||||||
|                         warn.category) |  | ||||||
|     if errtext: |     if errtext: | ||||||
|         testcase.assertRegex(str(warn.message), errtext) |         testcase.assertRegex(str(warn.message), errtext) | ||||||
|     testcase.assertEqual(warn.filename, '<testcase>') |     testcase.assertEqual(warn.filename, '<testcase>') | ||||||
|  |  | ||||||
|  | @ -66,8 +66,8 @@ def test__find_build_tool(self): | ||||||
|                             'cc not found - check xcode-select') |                             'cc not found - check xcode-select') | ||||||
| 
 | 
 | ||||||
|     def test__get_system_version(self): |     def test__get_system_version(self): | ||||||
|         self.assertTrue(platform.mac_ver()[0].startswith( |         self.assertStartsWith(platform.mac_ver()[0], | ||||||
|                                     _osx_support._get_system_version())) |                               _osx_support._get_system_version()) | ||||||
| 
 | 
 | ||||||
|     def test__remove_original_values(self): |     def test__remove_original_values(self): | ||||||
|         config_vars = { |         config_vars = { | ||||||
|  |  | ||||||
|  | @ -24,11 +24,11 @@ def not_implemented(*args, **kwargs): | ||||||
| 
 | 
 | ||||||
| class TestNumbers(unittest.TestCase): | class TestNumbers(unittest.TestCase): | ||||||
|     def test_int(self): |     def test_int(self): | ||||||
|         self.assertTrue(issubclass(int, Integral)) |         self.assertIsSubclass(int, Integral) | ||||||
|         self.assertTrue(issubclass(int, Rational)) |         self.assertIsSubclass(int, Rational) | ||||||
|         self.assertTrue(issubclass(int, Real)) |         self.assertIsSubclass(int, Real) | ||||||
|         self.assertTrue(issubclass(int, Complex)) |         self.assertIsSubclass(int, Complex) | ||||||
|         self.assertTrue(issubclass(int, Number)) |         self.assertIsSubclass(int, Number) | ||||||
| 
 | 
 | ||||||
|         self.assertEqual(7, int(7).real) |         self.assertEqual(7, int(7).real) | ||||||
|         self.assertEqual(0, int(7).imag) |         self.assertEqual(0, int(7).imag) | ||||||
|  | @ -38,11 +38,11 @@ def test_int(self): | ||||||
|         self.assertEqual(1, int(7).denominator) |         self.assertEqual(1, int(7).denominator) | ||||||
| 
 | 
 | ||||||
|     def test_float(self): |     def test_float(self): | ||||||
|         self.assertFalse(issubclass(float, Integral)) |         self.assertNotIsSubclass(float, Integral) | ||||||
|         self.assertFalse(issubclass(float, Rational)) |         self.assertNotIsSubclass(float, Rational) | ||||||
|         self.assertTrue(issubclass(float, Real)) |         self.assertIsSubclass(float, Real) | ||||||
|         self.assertTrue(issubclass(float, Complex)) |         self.assertIsSubclass(float, Complex) | ||||||
|         self.assertTrue(issubclass(float, Number)) |         self.assertIsSubclass(float, Number) | ||||||
| 
 | 
 | ||||||
|         self.assertEqual(7.3, float(7.3).real) |         self.assertEqual(7.3, float(7.3).real) | ||||||
|         self.assertEqual(0, float(7.3).imag) |         self.assertEqual(0, float(7.3).imag) | ||||||
|  | @ -50,11 +50,11 @@ def test_float(self): | ||||||
|         self.assertEqual(-7.3, float(-7.3).conjugate()) |         self.assertEqual(-7.3, float(-7.3).conjugate()) | ||||||
| 
 | 
 | ||||||
|     def test_complex(self): |     def test_complex(self): | ||||||
|         self.assertFalse(issubclass(complex, Integral)) |         self.assertNotIsSubclass(complex, Integral) | ||||||
|         self.assertFalse(issubclass(complex, Rational)) |         self.assertNotIsSubclass(complex, Rational) | ||||||
|         self.assertFalse(issubclass(complex, Real)) |         self.assertNotIsSubclass(complex, Real) | ||||||
|         self.assertTrue(issubclass(complex, Complex)) |         self.assertIsSubclass(complex, Complex) | ||||||
|         self.assertTrue(issubclass(complex, Number)) |         self.assertIsSubclass(complex, Number) | ||||||
| 
 | 
 | ||||||
|         c1, c2 = complex(3, 2), complex(4,1) |         c1, c2 = complex(3, 2), complex(4,1) | ||||||
|         # XXX: This is not ideal, but see the comment in math_trunc(). |         # XXX: This is not ideal, but see the comment in math_trunc(). | ||||||
|  |  | ||||||
|  | @ -6805,7 +6805,7 @@ class TestImportStar(TestCase): | ||||||
| 
 | 
 | ||||||
|     def test(self): |     def test(self): | ||||||
|         for name in argparse.__all__: |         for name in argparse.__all__: | ||||||
|             self.assertTrue(hasattr(argparse, name)) |             self.assertHasAttr(argparse, name) | ||||||
| 
 | 
 | ||||||
|     def test_all_exports_everything_but_modules(self): |     def test_all_exports_everything_but_modules(self): | ||||||
|         items = [ |         items = [ | ||||||
|  |  | ||||||
|  | @ -275,12 +275,12 @@ def test_alias(self): | ||||||
|         self.assertEqual(alias.end_col_offset, 17) |         self.assertEqual(alias.end_col_offset, 17) | ||||||
| 
 | 
 | ||||||
|     def test_base_classes(self): |     def test_base_classes(self): | ||||||
|         self.assertTrue(issubclass(ast.For, ast.stmt)) |         self.assertIsSubclass(ast.For, ast.stmt) | ||||||
|         self.assertTrue(issubclass(ast.Name, ast.expr)) |         self.assertIsSubclass(ast.Name, ast.expr) | ||||||
|         self.assertTrue(issubclass(ast.stmt, ast.AST)) |         self.assertIsSubclass(ast.stmt, ast.AST) | ||||||
|         self.assertTrue(issubclass(ast.expr, ast.AST)) |         self.assertIsSubclass(ast.expr, ast.AST) | ||||||
|         self.assertTrue(issubclass(ast.comprehension, ast.AST)) |         self.assertIsSubclass(ast.comprehension, ast.AST) | ||||||
|         self.assertTrue(issubclass(ast.Gt, ast.AST)) |         self.assertIsSubclass(ast.Gt, ast.AST) | ||||||
| 
 | 
 | ||||||
|     def test_field_attr_existence(self): |     def test_field_attr_existence(self): | ||||||
|         for name, item in ast.__dict__.items(): |         for name, item in ast.__dict__.items(): | ||||||
|  | @ -1101,7 +1101,7 @@ def test_copy_with_parents(self): | ||||||
|     def test_replace_interface(self): |     def test_replace_interface(self): | ||||||
|         for klass in self.iter_ast_classes(): |         for klass in self.iter_ast_classes(): | ||||||
|             with self.subTest(klass=klass): |             with self.subTest(klass=klass): | ||||||
|                 self.assertTrue(hasattr(klass, '__replace__')) |                 self.assertHasAttr(klass, '__replace__') | ||||||
| 
 | 
 | ||||||
|             fields = set(klass._fields) |             fields = set(klass._fields) | ||||||
|             with self.subTest(klass=klass, fields=fields): |             with self.subTest(klass=klass, fields=fields): | ||||||
|  | @ -1330,7 +1330,7 @@ def test_replace_reject_known_custom_instance_fields_commits(self): | ||||||
|         context = node.ctx |         context = node.ctx | ||||||
| 
 | 
 | ||||||
|         # explicit rejection of known instance fields |         # explicit rejection of known instance fields | ||||||
|         self.assertTrue(hasattr(node, 'extra')) |         self.assertHasAttr(node, 'extra') | ||||||
|         msg = "Name.__replace__ got an unexpected keyword argument 'extra'." |         msg = "Name.__replace__ got an unexpected keyword argument 'extra'." | ||||||
|         with self.assertRaisesRegex(TypeError, re.escape(msg)): |         with self.assertRaisesRegex(TypeError, re.escape(msg)): | ||||||
|             copy.replace(node, extra=1) |             copy.replace(node, extra=1) | ||||||
|  | @ -3071,7 +3071,7 @@ def test_FunctionDef(self): | ||||||
|         with self.assertWarnsRegex(DeprecationWarning, |         with self.assertWarnsRegex(DeprecationWarning, | ||||||
|                                    r"FunctionDef\.__init__ missing 1 required positional argument: 'name'"): |                                    r"FunctionDef\.__init__ missing 1 required positional argument: 'name'"): | ||||||
|             node = ast.FunctionDef(args=args) |             node = ast.FunctionDef(args=args) | ||||||
|         self.assertFalse(hasattr(node, "name")) |         self.assertNotHasAttr(node, "name") | ||||||
|         self.assertEqual(node.decorator_list, []) |         self.assertEqual(node.decorator_list, []) | ||||||
|         node = ast.FunctionDef(name='foo', args=args) |         node = ast.FunctionDef(name='foo', args=args) | ||||||
|         self.assertEqual(node.name, 'foo') |         self.assertEqual(node.name, 'foo') | ||||||
|  |  | ||||||
|  | @ -134,7 +134,7 @@ def test_socket(self): | ||||||
|         self.assertEqual(events[0][0], "socket.gethostname") |         self.assertEqual(events[0][0], "socket.gethostname") | ||||||
|         self.assertEqual(events[1][0], "socket.__new__") |         self.assertEqual(events[1][0], "socket.__new__") | ||||||
|         self.assertEqual(events[2][0], "socket.bind") |         self.assertEqual(events[2][0], "socket.bind") | ||||||
|         self.assertTrue(events[2][2].endswith("('127.0.0.1', 8080)")) |         self.assertEndsWith(events[2][2], "('127.0.0.1', 8080)") | ||||||
| 
 | 
 | ||||||
|     def test_gc(self): |     def test_gc(self): | ||||||
|         returncode, events, stderr = self.run_python("test_gc") |         returncode, events, stderr = self.run_python("test_gc") | ||||||
|  |  | ||||||
|  | @ -812,7 +812,7 @@ def test_decode_nonascii_str(self): | ||||||
|             self.assertRaises(ValueError, f, 'with non-ascii \xcb') |             self.assertRaises(ValueError, f, 'with non-ascii \xcb') | ||||||
| 
 | 
 | ||||||
|     def test_ErrorHeritage(self): |     def test_ErrorHeritage(self): | ||||||
|         self.assertTrue(issubclass(binascii.Error, ValueError)) |         self.assertIsSubclass(binascii.Error, ValueError) | ||||||
| 
 | 
 | ||||||
|     def test_RFC4648_test_cases(self): |     def test_RFC4648_test_cases(self): | ||||||
|         # test cases from RFC 4648 section 10 |         # test cases from RFC 4648 section 10 | ||||||
|  |  | ||||||
|  | @ -10,13 +10,11 @@ class ExceptionClassTests(unittest.TestCase): | ||||||
|     inheritance hierarchy)""" |     inheritance hierarchy)""" | ||||||
| 
 | 
 | ||||||
|     def test_builtins_new_style(self): |     def test_builtins_new_style(self): | ||||||
|         self.assertTrue(issubclass(Exception, object)) |         self.assertIsSubclass(Exception, object) | ||||||
| 
 | 
 | ||||||
|     def verify_instance_interface(self, ins): |     def verify_instance_interface(self, ins): | ||||||
|         for attr in ("args", "__str__", "__repr__"): |         for attr in ("args", "__str__", "__repr__"): | ||||||
|             self.assertTrue(hasattr(ins, attr), |             self.assertHasAttr(ins, attr) | ||||||
|                     "%s missing %s attribute" % |  | ||||||
|                         (ins.__class__.__name__, attr)) |  | ||||||
| 
 | 
 | ||||||
|     def test_inheritance(self): |     def test_inheritance(self): | ||||||
|         # Make sure the inheritance hierarchy matches the documentation |         # Make sure the inheritance hierarchy matches the documentation | ||||||
|  | @ -65,7 +63,7 @@ def test_inheritance(self): | ||||||
|                 elif last_depth > depth: |                 elif last_depth > depth: | ||||||
|                     while superclasses[-1][0] >= depth: |                     while superclasses[-1][0] >= depth: | ||||||
|                         superclasses.pop() |                         superclasses.pop() | ||||||
|                 self.assertTrue(issubclass(exc, superclasses[-1][1]), |                 self.assertIsSubclass(exc, superclasses[-1][1], | ||||||
|                 "%s is not a subclass of %s" % (exc.__name__, |                 "%s is not a subclass of %s" % (exc.__name__, | ||||||
|                     superclasses[-1][1].__name__)) |                     superclasses[-1][1].__name__)) | ||||||
|                 try:  # Some exceptions require arguments; just skip them |                 try:  # Some exceptions require arguments; just skip them | ||||||
|  |  | ||||||
|  | @ -38,13 +38,13 @@ def assertConversion(self, original, converted, restored, **kwargs): | ||||||
| 
 | 
 | ||||||
|     def test_exceptions(self): |     def test_exceptions(self): | ||||||
|         # Check module exceptions |         # Check module exceptions | ||||||
|         self.assertTrue(issubclass(binascii.Error, Exception)) |         self.assertIsSubclass(binascii.Error, Exception) | ||||||
|         self.assertTrue(issubclass(binascii.Incomplete, Exception)) |         self.assertIsSubclass(binascii.Incomplete, Exception) | ||||||
| 
 | 
 | ||||||
|     def test_functions(self): |     def test_functions(self): | ||||||
|         # Check presence of all functions |         # Check presence of all functions | ||||||
|         for name in all_functions: |         for name in all_functions: | ||||||
|             self.assertTrue(hasattr(getattr(binascii, name), '__call__')) |             self.assertHasAttr(getattr(binascii, name), '__call__') | ||||||
|             self.assertRaises(TypeError, getattr(binascii, name)) |             self.assertRaises(TypeError, getattr(binascii, name)) | ||||||
| 
 | 
 | ||||||
|     def test_returned_value(self): |     def test_returned_value(self): | ||||||
|  |  | ||||||
|  | @ -383,7 +383,7 @@ def test_comparison_orders(self): | ||||||
|         self.assertEqual(op_sequence(le, B, C), ['C.__ge__', 'B.__le__']) |         self.assertEqual(op_sequence(le, B, C), ['C.__ge__', 'B.__le__']) | ||||||
|         self.assertEqual(op_sequence(le, C, B), ['C.__le__', 'B.__ge__']) |         self.assertEqual(op_sequence(le, C, B), ['C.__le__', 'B.__ge__']) | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(issubclass(V, B)) |         self.assertIsSubclass(V, B) | ||||||
|         self.assertEqual(op_sequence(eq, B, V), ['B.__eq__', 'V.__eq__']) |         self.assertEqual(op_sequence(eq, B, V), ['B.__eq__', 'V.__eq__']) | ||||||
|         self.assertEqual(op_sequence(le, B, V), ['B.__le__', 'V.__ge__']) |         self.assertEqual(op_sequence(le, B, V), ['B.__le__', 'V.__ge__']) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2879,11 +2879,11 @@ def test_memoryview_tolist(self): | ||||||
|     def test_memoryview_repr(self): |     def test_memoryview_repr(self): | ||||||
|         m = memoryview(bytearray(9)) |         m = memoryview(bytearray(9)) | ||||||
|         r = m.__repr__() |         r = m.__repr__() | ||||||
|         self.assertTrue(r.startswith("<memory")) |         self.assertStartsWith(r, "<memory") | ||||||
| 
 | 
 | ||||||
|         m.release() |         m.release() | ||||||
|         r = m.__repr__() |         r = m.__repr__() | ||||||
|         self.assertTrue(r.startswith("<released")) |         self.assertStartsWith(r, "<released") | ||||||
| 
 | 
 | ||||||
|     def test_memoryview_sequence(self): |     def test_memoryview_sequence(self): | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -393,7 +393,7 @@ def test_chr(self): | ||||||
|         self.assertRaises(ValueError, chr, -2**1000) |         self.assertRaises(ValueError, chr, -2**1000) | ||||||
| 
 | 
 | ||||||
|     def test_cmp(self): |     def test_cmp(self): | ||||||
|         self.assertTrue(not hasattr(builtins, "cmp")) |         self.assertNotHasAttr(builtins, "cmp") | ||||||
| 
 | 
 | ||||||
|     def test_compile(self): |     def test_compile(self): | ||||||
|         compile('print(1)\n', '', 'exec') |         compile('print(1)\n', '', 'exec') | ||||||
|  | @ -2304,7 +2304,7 @@ def __format__(self, format_spec): | ||||||
|         # tests for object.__format__ really belong elsewhere, but |         # tests for object.__format__ really belong elsewhere, but | ||||||
|         #  there's no good place to put them |         #  there's no good place to put them | ||||||
|         x = object().__format__('') |         x = object().__format__('') | ||||||
|         self.assertTrue(x.startswith('<object object at')) |         self.assertStartsWith(x, '<object object at') | ||||||
| 
 | 
 | ||||||
|         # first argument to object.__format__ must be string |         # first argument to object.__format__ must be string | ||||||
|         self.assertRaises(TypeError, object().__format__, 3) |         self.assertRaises(TypeError, object().__format__, 3) | ||||||
|  |  | ||||||
|  | @ -1974,9 +1974,9 @@ def test_compare_bytes_to_bytearray(self): | ||||||
|     @test.support.requires_docstrings |     @test.support.requires_docstrings | ||||||
|     def test_doc(self): |     def test_doc(self): | ||||||
|         self.assertIsNotNone(bytearray.__doc__) |         self.assertIsNotNone(bytearray.__doc__) | ||||||
|         self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__) |         self.assertStartsWith(bytearray.__doc__, "bytearray(") | ||||||
|         self.assertIsNotNone(bytes.__doc__) |         self.assertIsNotNone(bytes.__doc__) | ||||||
|         self.assertTrue(bytes.__doc__.startswith("bytes("), bytes.__doc__) |         self.assertStartsWith(bytes.__doc__, "bytes(") | ||||||
| 
 | 
 | ||||||
|     def test_from_bytearray(self): |     def test_from_bytearray(self): | ||||||
|         sample = bytes(b"Hello world\n\x80\x81\xfe\xff") |         sample = bytes(b"Hello world\n\x80\x81\xfe\xff") | ||||||
|  | @ -2107,7 +2107,7 @@ class BytesAsStringTest(FixedStringTest, unittest.TestCase): | ||||||
| class SubclassTest: | class SubclassTest: | ||||||
| 
 | 
 | ||||||
|     def test_basic(self): |     def test_basic(self): | ||||||
|         self.assertTrue(issubclass(self.type2test, self.basetype)) |         self.assertIsSubclass(self.type2test, self.basetype) | ||||||
|         self.assertIsInstance(self.type2test(), self.basetype) |         self.assertIsInstance(self.type2test(), self.basetype) | ||||||
| 
 | 
 | ||||||
|         a, b = b"abcd", b"efgh" |         a, b = b"abcd", b"efgh" | ||||||
|  | @ -2155,7 +2155,7 @@ def test_pickle(self): | ||||||
|             self.assertEqual(a.z, b.z) |             self.assertEqual(a.z, b.z) | ||||||
|             self.assertEqual(type(a), type(b)) |             self.assertEqual(type(a), type(b)) | ||||||
|             self.assertEqual(type(a.z), type(b.z)) |             self.assertEqual(type(a.z), type(b.z)) | ||||||
|             self.assertFalse(hasattr(b, 'y')) |             self.assertNotHasAttr(b, 'y') | ||||||
| 
 | 
 | ||||||
|     def test_copy(self): |     def test_copy(self): | ||||||
|         a = self.type2test(b"abcd") |         a = self.type2test(b"abcd") | ||||||
|  | @ -2169,7 +2169,7 @@ def test_copy(self): | ||||||
|             self.assertEqual(a.z, b.z) |             self.assertEqual(a.z, b.z) | ||||||
|             self.assertEqual(type(a), type(b)) |             self.assertEqual(type(a), type(b)) | ||||||
|             self.assertEqual(type(a.z), type(b.z)) |             self.assertEqual(type(a.z), type(b.z)) | ||||||
|             self.assertFalse(hasattr(b, 'y')) |             self.assertNotHasAttr(b, 'y') | ||||||
| 
 | 
 | ||||||
|     def test_fromhex(self): |     def test_fromhex(self): | ||||||
|         b = self.type2test.fromhex('1a2B30') |         b = self.type2test.fromhex('1a2B30') | ||||||
|  |  | ||||||
|  | @ -184,7 +184,7 @@ def testPeek(self): | ||||||
|         with BZ2File(self.filename) as bz2f: |         with BZ2File(self.filename) as bz2f: | ||||||
|             pdata = bz2f.peek() |             pdata = bz2f.peek() | ||||||
|             self.assertNotEqual(len(pdata), 0) |             self.assertNotEqual(len(pdata), 0) | ||||||
|             self.assertTrue(self.TEXT.startswith(pdata)) |             self.assertStartsWith(self.TEXT, pdata) | ||||||
|             self.assertEqual(bz2f.read(), self.TEXT) |             self.assertEqual(bz2f.read(), self.TEXT) | ||||||
| 
 | 
 | ||||||
|     def testReadInto(self): |     def testReadInto(self): | ||||||
|  | @ -768,7 +768,7 @@ def testPeekBytesIO(self): | ||||||
|             with BZ2File(bio) as bz2f: |             with BZ2File(bio) as bz2f: | ||||||
|                 pdata = bz2f.peek() |                 pdata = bz2f.peek() | ||||||
|                 self.assertNotEqual(len(pdata), 0) |                 self.assertNotEqual(len(pdata), 0) | ||||||
|                 self.assertTrue(self.TEXT.startswith(pdata)) |                 self.assertStartsWith(self.TEXT, pdata) | ||||||
|                 self.assertEqual(bz2f.read(), self.TEXT) |                 self.assertEqual(bz2f.read(), self.TEXT) | ||||||
| 
 | 
 | ||||||
|     def testWriteBytesIO(self): |     def testWriteBytesIO(self): | ||||||
|  |  | ||||||
|  | @ -1098,7 +1098,7 @@ def test_option_type(self): | ||||||
|             output = run('--type', 'text', '2004') |             output = run('--type', 'text', '2004') | ||||||
|             self.assertEqual(output, conv(result_2004_text)) |             self.assertEqual(output, conv(result_2004_text)) | ||||||
|             output = run('--type', 'html', '2004') |             output = run('--type', 'html', '2004') | ||||||
|             self.assertEqual(output[:6], b'<?xml ') |             self.assertStartsWith(output, b'<?xml ') | ||||||
|             self.assertIn(b'<title>Calendar for 2004</title>', output) |             self.assertIn(b'<title>Calendar for 2004</title>', output) | ||||||
| 
 | 
 | ||||||
|     def test_html_output_current_year(self): |     def test_html_output_current_year(self): | ||||||
|  |  | ||||||
|  | @ -695,8 +695,8 @@ class DerivedType(SuperType): | ||||||
|         UnaffectedType2 = _testcapi.make_vectorcall_class(SuperType) |         UnaffectedType2 = _testcapi.make_vectorcall_class(SuperType) | ||||||
| 
 | 
 | ||||||
|         # Aside: Quickly check that the C helper actually made derived types |         # Aside: Quickly check that the C helper actually made derived types | ||||||
|         self.assertTrue(issubclass(UnaffectedType1, DerivedType)) |         self.assertIsSubclass(UnaffectedType1, DerivedType) | ||||||
|         self.assertTrue(issubclass(UnaffectedType2, SuperType)) |         self.assertIsSubclass(UnaffectedType2, SuperType) | ||||||
| 
 | 
 | ||||||
|         # Initial state: tp_call |         # Initial state: tp_call | ||||||
|         self.assertEqual(instance(), "tp_call") |         self.assertEqual(instance(), "tp_call") | ||||||
|  |  | ||||||
|  | @ -238,11 +238,11 @@ def test_directive_output_print(self): | ||||||
|         # The generated output will differ for every run, but we can check that |         # The generated output will differ for every run, but we can check that | ||||||
|         # it starts with the clinic block, we check that it contains all the |         # it starts with the clinic block, we check that it contains all the | ||||||
|         # expected fields, and we check that it contains the checksum line. |         # expected fields, and we check that it contains the checksum line. | ||||||
|         self.assertTrue(out.startswith(dedent(""" |         self.assertStartsWith(out, dedent(""" | ||||||
|             /*[clinic input] |             /*[clinic input] | ||||||
|             output print 'I told you once.' |             output print 'I told you once.' | ||||||
|             [clinic start generated code]*/ |             [clinic start generated code]*/ | ||||||
|         """))) |         """)) | ||||||
|         fields = { |         fields = { | ||||||
|             "cpp_endif", |             "cpp_endif", | ||||||
|             "cpp_if", |             "cpp_if", | ||||||
|  | @ -259,9 +259,7 @@ def test_directive_output_print(self): | ||||||
|             with self.subTest(field=field): |             with self.subTest(field=field): | ||||||
|                 self.assertIn(field, out) |                 self.assertIn(field, out) | ||||||
|         last_line = out.rstrip().split("\n")[-1] |         last_line = out.rstrip().split("\n")[-1] | ||||||
|         self.assertTrue( |         self.assertStartsWith(last_line, "/*[clinic end generated code: output=") | ||||||
|             last_line.startswith("/*[clinic end generated code: output=") |  | ||||||
|         ) |  | ||||||
| 
 | 
 | ||||||
|     def test_directive_wrong_arg_number(self): |     def test_directive_wrong_arg_number(self): | ||||||
|         raw = dedent(""" |         raw = dedent(""" | ||||||
|  | @ -2705,8 +2703,7 @@ def test_cli_force(self): | ||||||
|             # Note, we cannot check the entire fail msg, because the path to |             # Note, we cannot check the entire fail msg, because the path to | ||||||
|             # the tmp file will change for every run. |             # the tmp file will change for every run. | ||||||
|             _, err = self.expect_failure(fn) |             _, err = self.expect_failure(fn) | ||||||
|             self.assertTrue(err.endswith(fail_msg), |             self.assertEndsWith(err, fail_msg) | ||||||
|                             f"{err!r} does not end with {fail_msg!r}") |  | ||||||
|             # Then, force regeneration; success expected. |             # Then, force regeneration; success expected. | ||||||
|             out = self.expect_success("-f", fn) |             out = self.expect_success("-f", fn) | ||||||
|             self.assertEqual(out, "") |             self.assertEqual(out, "") | ||||||
|  | @ -2717,8 +2714,7 @@ def test_cli_force(self): | ||||||
|             ) |             ) | ||||||
|             with open(fn, encoding='utf-8') as f: |             with open(fn, encoding='utf-8') as f: | ||||||
|                 generated = f.read() |                 generated = f.read() | ||||||
|             self.assertTrue(generated.endswith(checksum), |             self.assertEndsWith(generated, checksum) | ||||||
|                             (generated, checksum)) |  | ||||||
| 
 | 
 | ||||||
|     def test_cli_make(self): |     def test_cli_make(self): | ||||||
|         c_code = dedent(""" |         c_code = dedent(""" | ||||||
|  | @ -2867,8 +2863,8 @@ def test_cli_converters(self): | ||||||
|         # param may change (it's a set, thus unordered). So, let's compare the |         # param may change (it's a set, thus unordered). So, let's compare the | ||||||
|         # start and end of the expected output, and then assert that the |         # start and end of the expected output, and then assert that the | ||||||
|         # converters appear lined up in alphabetical order. |         # converters appear lined up in alphabetical order. | ||||||
|         self.assertTrue(out.startswith(prelude), out) |         self.assertStartsWith(out, prelude) | ||||||
|         self.assertTrue(out.endswith(finale), out) |         self.assertEndsWith(out, finale) | ||||||
| 
 | 
 | ||||||
|         out = out.removeprefix(prelude) |         out = out.removeprefix(prelude) | ||||||
|         out = out.removesuffix(finale) |         out = out.removesuffix(finale) | ||||||
|  | @ -2876,10 +2872,7 @@ def test_cli_converters(self): | ||||||
|         for converter, line in zip(expected_converters, lines): |         for converter, line in zip(expected_converters, lines): | ||||||
|             line = line.lstrip() |             line = line.lstrip() | ||||||
|             with self.subTest(converter=converter): |             with self.subTest(converter=converter): | ||||||
|                 self.assertTrue( |                 self.assertStartsWith(line, converter) | ||||||
|                     line.startswith(converter), |  | ||||||
|                     f"expected converter {converter!r}, got {line!r}" |  | ||||||
|                 ) |  | ||||||
| 
 | 
 | ||||||
|     def test_cli_fail_converters_and_filename(self): |     def test_cli_fail_converters_and_filename(self): | ||||||
|         _, err = self.expect_failure("--converters", "test.c") |         _, err = self.expect_failure("--converters", "test.c") | ||||||
|  |  | ||||||
|  | @ -39,7 +39,8 @@ def test_directories(self): | ||||||
| 
 | 
 | ||||||
|     def verify_valid_flag(self, cmd_line): |     def verify_valid_flag(self, cmd_line): | ||||||
|         rc, out, err = assert_python_ok(cmd_line) |         rc, out, err = assert_python_ok(cmd_line) | ||||||
|         self.assertTrue(out == b'' or out.endswith(b'\n')) |         if out != b'': | ||||||
|  |             self.assertEndsWith(out, b'\n') | ||||||
|         self.assertNotIn(b'Traceback', out) |         self.assertNotIn(b'Traceback', out) | ||||||
|         self.assertNotIn(b'Traceback', err) |         self.assertNotIn(b'Traceback', err) | ||||||
|         return out |         return out | ||||||
|  | @ -89,8 +90,8 @@ def test_version(self): | ||||||
|         version = ('Python %d.%d' % sys.version_info[:2]).encode("ascii") |         version = ('Python %d.%d' % sys.version_info[:2]).encode("ascii") | ||||||
|         for switch in '-V', '--version', '-VV': |         for switch in '-V', '--version', '-VV': | ||||||
|             rc, out, err = assert_python_ok(switch) |             rc, out, err = assert_python_ok(switch) | ||||||
|             self.assertFalse(err.startswith(version)) |             self.assertNotStartsWith(err, version) | ||||||
|             self.assertTrue(out.startswith(version)) |             self.assertStartsWith(out, version) | ||||||
| 
 | 
 | ||||||
|     def test_verbose(self): |     def test_verbose(self): | ||||||
|         # -v causes imports to write to stderr.  If the write to |         # -v causes imports to write to stderr.  If the write to | ||||||
|  | @ -380,7 +381,7 @@ def test_unbuffered_input(self): | ||||||
|         p.stdin.flush() |         p.stdin.flush() | ||||||
|         data, rc = _kill_python_and_exit_code(p) |         data, rc = _kill_python_and_exit_code(p) | ||||||
|         self.assertEqual(rc, 0) |         self.assertEqual(rc, 0) | ||||||
|         self.assertTrue(data.startswith(b'x'), data) |         self.assertStartsWith(data, b'x') | ||||||
| 
 | 
 | ||||||
|     def test_large_PYTHONPATH(self): |     def test_large_PYTHONPATH(self): | ||||||
|         path1 = "ABCDE" * 100 |         path1 = "ABCDE" * 100 | ||||||
|  | @ -1039,7 +1040,7 @@ def test_parsing_error(self): | ||||||
|                               stderr=subprocess.PIPE, |                               stderr=subprocess.PIPE, | ||||||
|                               text=True) |                               text=True) | ||||||
|         err_msg = "Unknown option: --unknown-option\nusage: " |         err_msg = "Unknown option: --unknown-option\nusage: " | ||||||
|         self.assertTrue(proc.stderr.startswith(err_msg), proc.stderr) |         self.assertStartsWith(proc.stderr, err_msg) | ||||||
|         self.assertNotEqual(proc.returncode, 0) |         self.assertNotEqual(proc.returncode, 0) | ||||||
| 
 | 
 | ||||||
|     def test_int_max_str_digits(self): |     def test_int_max_str_digits(self): | ||||||
|  |  | ||||||
|  | @ -553,9 +553,9 @@ def test_pep_409_verbiage(self): | ||||||
|             exitcode, stdout, stderr = assert_python_failure(script_name) |             exitcode, stdout, stderr = assert_python_failure(script_name) | ||||||
|             text = stderr.decode('ascii').split('\n') |             text = stderr.decode('ascii').split('\n') | ||||||
|             self.assertEqual(len(text), 5) |             self.assertEqual(len(text), 5) | ||||||
|             self.assertTrue(text[0].startswith('Traceback')) |             self.assertStartsWith(text[0], 'Traceback') | ||||||
|             self.assertTrue(text[1].startswith('  File ')) |             self.assertStartsWith(text[1], '  File ') | ||||||
|             self.assertTrue(text[3].startswith('NameError')) |             self.assertStartsWith(text[3], 'NameError') | ||||||
| 
 | 
 | ||||||
|     def test_non_ascii(self): |     def test_non_ascii(self): | ||||||
|         # Apple platforms deny the creation of a file with an invalid UTF-8 name. |         # Apple platforms deny the creation of a file with an invalid UTF-8 name. | ||||||
|  | @ -708,9 +708,8 @@ def test_syntaxerror_does_not_crash(self): | ||||||
|             exitcode, stdout, stderr = assert_python_failure(script_name) |             exitcode, stdout, stderr = assert_python_failure(script_name) | ||||||
|             text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read() |             text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read() | ||||||
|             # It used to crash in https://github.com/python/cpython/issues/111132 |             # It used to crash in https://github.com/python/cpython/issues/111132 | ||||||
|             self.assertTrue(text.endswith( |             self.assertEndsWith(text, | ||||||
|                 'SyntaxError: nonlocal declaration not allowed at module level\n', |                 'SyntaxError: nonlocal declaration not allowed at module level\n') | ||||||
|             ), text) |  | ||||||
| 
 | 
 | ||||||
|     def test_consistent_sys_path_for_direct_execution(self): |     def test_consistent_sys_path_for_direct_execution(self): | ||||||
|         # This test case ensures that the following all give the same |         # This test case ensures that the following all give the same | ||||||
|  |  | ||||||
|  | @ -133,7 +133,7 @@ def test_unicode_error(self): | ||||||
|         output = ''.join(''.join(call[1]) for call in self.stderr.method_calls) |         output = ''.join(''.join(call[1]) for call in self.stderr.method_calls) | ||||||
|         output = output[output.index('(InteractiveConsole)'):] |         output = output[output.index('(InteractiveConsole)'):] | ||||||
|         output = output[output.index('\n') + 1:] |         output = output[output.index('\n') + 1:] | ||||||
|         self.assertTrue(output.startswith('UnicodeEncodeError: '), output) |         self.assertStartsWith(output, 'UnicodeEncodeError: ') | ||||||
|         self.assertIs(self.sysmod.last_type, UnicodeEncodeError) |         self.assertIs(self.sysmod.last_type, UnicodeEncodeError) | ||||||
|         self.assertIs(type(self.sysmod.last_value), UnicodeEncodeError) |         self.assertIs(type(self.sysmod.last_value), UnicodeEncodeError) | ||||||
|         self.assertIsNone(self.sysmod.last_traceback) |         self.assertIsNone(self.sysmod.last_traceback) | ||||||
|  |  | ||||||
|  | @ -3802,7 +3802,7 @@ def check_decode_strings(self, errors): | ||||||
|                     with self.assertRaises(RuntimeError) as cm: |                     with self.assertRaises(RuntimeError) as cm: | ||||||
|                         self.decode(encoded, errors) |                         self.decode(encoded, errors) | ||||||
|                     errmsg = str(cm.exception) |                     errmsg = str(cm.exception) | ||||||
|                     self.assertTrue(errmsg.startswith("decode error: "), errmsg) |                     self.assertStartsWith(errmsg, "decode error: ") | ||||||
|                 else: |                 else: | ||||||
|                     decoded = self.decode(encoded, errors) |                     decoded = self.decode(encoded, errors) | ||||||
|                     self.assertEqual(decoded, expected) |                     self.assertEqual(decoded, expected) | ||||||
|  |  | ||||||
|  | @ -316,7 +316,7 @@ def _test_ddir_only(self, *, ddir, parallel=True): | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(mods) |         self.assertTrue(mods) | ||||||
|         for mod in mods: |         for mod in mods: | ||||||
|             self.assertTrue(mod.startswith(self.directory), mod) |             self.assertStartsWith(mod, self.directory) | ||||||
|             modcode = importlib.util.cache_from_source(mod) |             modcode = importlib.util.cache_from_source(mod) | ||||||
|             modpath = mod[len(self.directory+os.sep):] |             modpath = mod[len(self.directory+os.sep):] | ||||||
|             _, _, err = script_helper.assert_python_failure(modcode) |             _, _, err = script_helper.assert_python_failure(modcode) | ||||||
|  |  | ||||||
|  | @ -146,4 +146,4 @@ def test_exception_table(self): | ||||||
|                                          L1 to L2 -> L2 [0] |                                          L1 to L2 -> L2 [0] | ||||||
|                                          L2 to L3 -> L3 [1] lasti |                                          L2 to L3 -> L3 [1] lasti | ||||||
|                                     """) |                                     """) | ||||||
|         self.assertTrue(output.getvalue().endswith(exc_table)) |         self.assertEndsWith(output.getvalue(), exc_table) | ||||||
|  |  | ||||||
|  | @ -48,23 +48,23 @@ def __enter__(self): | ||||||
|             def __exit__(self, exc_type, exc_value, traceback): |             def __exit__(self, exc_type, exc_value, traceback): | ||||||
|                 return None |                 return None | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(issubclass(ManagerFromScratch, AbstractContextManager)) |         self.assertIsSubclass(ManagerFromScratch, AbstractContextManager) | ||||||
| 
 | 
 | ||||||
|         class DefaultEnter(AbstractContextManager): |         class DefaultEnter(AbstractContextManager): | ||||||
|             def __exit__(self, *args): |             def __exit__(self, *args): | ||||||
|                 super().__exit__(*args) |                 super().__exit__(*args) | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(issubclass(DefaultEnter, AbstractContextManager)) |         self.assertIsSubclass(DefaultEnter, AbstractContextManager) | ||||||
| 
 | 
 | ||||||
|         class NoEnter(ManagerFromScratch): |         class NoEnter(ManagerFromScratch): | ||||||
|             __enter__ = None |             __enter__ = None | ||||||
| 
 | 
 | ||||||
|         self.assertFalse(issubclass(NoEnter, AbstractContextManager)) |         self.assertNotIsSubclass(NoEnter, AbstractContextManager) | ||||||
| 
 | 
 | ||||||
|         class NoExit(ManagerFromScratch): |         class NoExit(ManagerFromScratch): | ||||||
|             __exit__ = None |             __exit__ = None | ||||||
| 
 | 
 | ||||||
|         self.assertFalse(issubclass(NoExit, AbstractContextManager)) |         self.assertNotIsSubclass(NoExit, AbstractContextManager) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ContextManagerTestCase(unittest.TestCase): | class ContextManagerTestCase(unittest.TestCase): | ||||||
|  |  | ||||||
|  | @ -77,23 +77,23 @@ async def __aenter__(self): | ||||||
|             async def __aexit__(self, exc_type, exc_value, traceback): |             async def __aexit__(self, exc_type, exc_value, traceback): | ||||||
|                 return None |                 return None | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(issubclass(ManagerFromScratch, AbstractAsyncContextManager)) |         self.assertIsSubclass(ManagerFromScratch, AbstractAsyncContextManager) | ||||||
| 
 | 
 | ||||||
|         class DefaultEnter(AbstractAsyncContextManager): |         class DefaultEnter(AbstractAsyncContextManager): | ||||||
|             async def __aexit__(self, *args): |             async def __aexit__(self, *args): | ||||||
|                 await super().__aexit__(*args) |                 await super().__aexit__(*args) | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(issubclass(DefaultEnter, AbstractAsyncContextManager)) |         self.assertIsSubclass(DefaultEnter, AbstractAsyncContextManager) | ||||||
| 
 | 
 | ||||||
|         class NoneAenter(ManagerFromScratch): |         class NoneAenter(ManagerFromScratch): | ||||||
|             __aenter__ = None |             __aenter__ = None | ||||||
| 
 | 
 | ||||||
|         self.assertFalse(issubclass(NoneAenter, AbstractAsyncContextManager)) |         self.assertNotIsSubclass(NoneAenter, AbstractAsyncContextManager) | ||||||
| 
 | 
 | ||||||
|         class NoneAexit(ManagerFromScratch): |         class NoneAexit(ManagerFromScratch): | ||||||
|             __aexit__ = None |             __aexit__ = None | ||||||
| 
 | 
 | ||||||
|         self.assertFalse(issubclass(NoneAexit, AbstractAsyncContextManager)) |         self.assertNotIsSubclass(NoneAexit, AbstractAsyncContextManager) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class AsyncContextManagerTestCase(unittest.TestCase): | class AsyncContextManagerTestCase(unittest.TestCase): | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ class TestCopy(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def test_exceptions(self): |     def test_exceptions(self): | ||||||
|         self.assertIs(copy.Error, copy.error) |         self.assertIs(copy.Error, copy.error) | ||||||
|         self.assertTrue(issubclass(copy.Error, Exception)) |         self.assertIsSubclass(copy.Error, Exception) | ||||||
| 
 | 
 | ||||||
|     # The copy() method |     # The copy() method | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -527,7 +527,7 @@ class CoroutineTest(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def test_gen_1(self): |     def test_gen_1(self): | ||||||
|         def gen(): yield |         def gen(): yield | ||||||
|         self.assertFalse(hasattr(gen, '__await__')) |         self.assertNotHasAttr(gen, '__await__') | ||||||
| 
 | 
 | ||||||
|     def test_func_1(self): |     def test_func_1(self): | ||||||
|         async def foo(): |         async def foo(): | ||||||
|  |  | ||||||
|  | @ -1257,7 +1257,7 @@ class TestAscii(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def test_controlnames(self): |     def test_controlnames(self): | ||||||
|         for name in curses.ascii.controlnames: |         for name in curses.ascii.controlnames: | ||||||
|             self.assertTrue(hasattr(curses.ascii, name), name) |             self.assertHasAttr(curses.ascii, name) | ||||||
| 
 | 
 | ||||||
|     def test_ctypes(self): |     def test_ctypes(self): | ||||||
|         def check(func, expected): |         def check(func, expected): | ||||||
|  |  | ||||||
|  | @ -120,7 +120,7 @@ class Some: pass | ||||||
|         for param in inspect.signature(dataclass).parameters: |         for param in inspect.signature(dataclass).parameters: | ||||||
|             if param == 'cls': |             if param == 'cls': | ||||||
|                 continue |                 continue | ||||||
|             self.assertTrue(hasattr(Some.__dataclass_params__, param), msg=param) |             self.assertHasAttr(Some.__dataclass_params__, param) | ||||||
| 
 | 
 | ||||||
|     def test_named_init_params(self): |     def test_named_init_params(self): | ||||||
|         @dataclass |         @dataclass | ||||||
|  | @ -671,7 +671,7 @@ class C: | ||||||
| 
 | 
 | ||||||
|         self.assertEqual(the_fields[0].name, 'x') |         self.assertEqual(the_fields[0].name, 'x') | ||||||
|         self.assertEqual(the_fields[0].type, int) |         self.assertEqual(the_fields[0].type, int) | ||||||
|         self.assertFalse(hasattr(C, 'x')) |         self.assertNotHasAttr(C, 'x') | ||||||
|         self.assertTrue (the_fields[0].init) |         self.assertTrue (the_fields[0].init) | ||||||
|         self.assertTrue (the_fields[0].repr) |         self.assertTrue (the_fields[0].repr) | ||||||
|         self.assertEqual(the_fields[1].name, 'y') |         self.assertEqual(the_fields[1].name, 'y') | ||||||
|  | @ -681,7 +681,7 @@ class C: | ||||||
|         self.assertTrue (the_fields[1].repr) |         self.assertTrue (the_fields[1].repr) | ||||||
|         self.assertEqual(the_fields[2].name, 'z') |         self.assertEqual(the_fields[2].name, 'z') | ||||||
|         self.assertEqual(the_fields[2].type, str) |         self.assertEqual(the_fields[2].type, str) | ||||||
|         self.assertFalse(hasattr(C, 'z')) |         self.assertNotHasAttr(C, 'z') | ||||||
|         self.assertTrue (the_fields[2].init) |         self.assertTrue (the_fields[2].init) | ||||||
|         self.assertFalse(the_fields[2].repr) |         self.assertFalse(the_fields[2].repr) | ||||||
| 
 | 
 | ||||||
|  | @ -732,8 +732,8 @@ class C: | ||||||
|             z: object = default |             z: object = default | ||||||
|             t: int = field(default=100) |             t: int = field(default=100) | ||||||
| 
 | 
 | ||||||
|         self.assertFalse(hasattr(C, 'x')) |         self.assertNotHasAttr(C, 'x') | ||||||
|         self.assertFalse(hasattr(C, 'y')) |         self.assertNotHasAttr(C, 'y') | ||||||
|         self.assertIs   (C.z, default) |         self.assertIs   (C.z, default) | ||||||
|         self.assertEqual(C.t, 100) |         self.assertEqual(C.t, 100) | ||||||
| 
 | 
 | ||||||
|  | @ -2912,10 +2912,10 @@ class C: | ||||||
|             pass |             pass | ||||||
| 
 | 
 | ||||||
|         c = C() |         c = C() | ||||||
|         self.assertFalse(hasattr(c, 'i')) |         self.assertNotHasAttr(c, 'i') | ||||||
|         with self.assertRaises(FrozenInstanceError): |         with self.assertRaises(FrozenInstanceError): | ||||||
|             c.i = 5 |             c.i = 5 | ||||||
|         self.assertFalse(hasattr(c, 'i')) |         self.assertNotHasAttr(c, 'i') | ||||||
|         with self.assertRaises(FrozenInstanceError): |         with self.assertRaises(FrozenInstanceError): | ||||||
|             del c.i |             del c.i | ||||||
| 
 | 
 | ||||||
|  | @ -3144,7 +3144,7 @@ class S(D): | ||||||
|             del s.y |             del s.y | ||||||
|         self.assertEqual(s.y, 10) |         self.assertEqual(s.y, 10) | ||||||
|         del s.cached |         del s.cached | ||||||
|         self.assertFalse(hasattr(s, 'cached')) |         self.assertNotHasAttr(s, 'cached') | ||||||
|         with self.assertRaises(AttributeError) as cm: |         with self.assertRaises(AttributeError) as cm: | ||||||
|             del s.cached |             del s.cached | ||||||
|         self.assertNotIsInstance(cm.exception, FrozenInstanceError) |         self.assertNotIsInstance(cm.exception, FrozenInstanceError) | ||||||
|  | @ -3158,12 +3158,12 @@ class S(D): | ||||||
|             pass |             pass | ||||||
| 
 | 
 | ||||||
|         s = S() |         s = S() | ||||||
|         self.assertFalse(hasattr(s, 'x')) |         self.assertNotHasAttr(s, 'x') | ||||||
|         s.x = 5 |         s.x = 5 | ||||||
|         self.assertEqual(s.x, 5) |         self.assertEqual(s.x, 5) | ||||||
| 
 | 
 | ||||||
|         del s.x |         del s.x | ||||||
|         self.assertFalse(hasattr(s, 'x')) |         self.assertNotHasAttr(s, 'x') | ||||||
|         with self.assertRaises(AttributeError) as cm: |         with self.assertRaises(AttributeError) as cm: | ||||||
|             del s.x |             del s.x | ||||||
|         self.assertNotIsInstance(cm.exception, FrozenInstanceError) |         self.assertNotIsInstance(cm.exception, FrozenInstanceError) | ||||||
|  | @ -3393,8 +3393,8 @@ class A: | ||||||
|         B = dataclass(A, slots=True) |         B = dataclass(A, slots=True) | ||||||
|         self.assertIsNot(A, B) |         self.assertIsNot(A, B) | ||||||
| 
 | 
 | ||||||
|         self.assertFalse(hasattr(A, "__slots__")) |         self.assertNotHasAttr(A, "__slots__") | ||||||
|         self.assertTrue(hasattr(B, "__slots__")) |         self.assertHasAttr(B, "__slots__") | ||||||
| 
 | 
 | ||||||
|     # Can't be local to test_frozen_pickle. |     # Can't be local to test_frozen_pickle. | ||||||
|     @dataclass(frozen=True, slots=True) |     @dataclass(frozen=True, slots=True) | ||||||
|  |  | ||||||
|  | @ -66,7 +66,7 @@ def keys_helper(self, f): | ||||||
|         return keys |         return keys | ||||||
| 
 | 
 | ||||||
|     def test_error(self): |     def test_error(self): | ||||||
|         self.assertTrue(issubclass(self.module.error, OSError)) |         self.assertIsSubclass(self.module.error, OSError) | ||||||
| 
 | 
 | ||||||
|     def test_anydbm_not_existing(self): |     def test_anydbm_not_existing(self): | ||||||
|         self.assertRaises(dbm.error, dbm.open, _fname) |         self.assertRaises(dbm.error, dbm.open, _fname) | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ def test_uri_substitutions(self): | ||||||
|         ) |         ) | ||||||
|         for path, normalized in dataset: |         for path, normalized in dataset: | ||||||
|             with self.subTest(path=path, normalized=normalized): |             with self.subTest(path=path, normalized=normalized): | ||||||
|                 self.assertTrue(_normalize_uri(path).endswith(normalized)) |                 self.assertEndsWith(_normalize_uri(path), normalized) | ||||||
| 
 | 
 | ||||||
|     @unittest.skipUnless(sys.platform == "win32", "requires Windows") |     @unittest.skipUnless(sys.platform == "win32", "requires Windows") | ||||||
|     def test_uri_windows(self): |     def test_uri_windows(self): | ||||||
|  | @ -55,7 +55,7 @@ def test_uri_windows(self): | ||||||
|             with self.subTest(path=path, normalized=normalized): |             with self.subTest(path=path, normalized=normalized): | ||||||
|                 if not Path(path).is_absolute(): |                 if not Path(path).is_absolute(): | ||||||
|                     self.skipTest(f"skipping relative path: {path!r}") |                     self.skipTest(f"skipping relative path: {path!r}") | ||||||
|                 self.assertTrue(_normalize_uri(path).endswith(normalized)) |                 self.assertEndsWith(_normalize_uri(path), normalized) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ReadOnly(_SQLiteDbmTests): | class ReadOnly(_SQLiteDbmTests): | ||||||
|  |  | ||||||
|  | @ -838,7 +838,7 @@ def test_copy_pickle(self): | ||||||
|                     self.assertEqual(list(d), list(e)) |                     self.assertEqual(list(d), list(e)) | ||||||
|                     self.assertEqual(e.x, d.x) |                     self.assertEqual(e.x, d.x) | ||||||
|                     self.assertEqual(e.z, d.z) |                     self.assertEqual(e.z, d.z) | ||||||
|                     self.assertFalse(hasattr(e, 'y')) |                     self.assertNotHasAttr(e, 'y') | ||||||
| 
 | 
 | ||||||
|     def test_pickle_recursive(self): |     def test_pickle_recursive(self): | ||||||
|         for proto in range(pickle.HIGHEST_PROTOCOL + 1): |         for proto in range(pickle.HIGHEST_PROTOCOL + 1): | ||||||
|  |  | ||||||
|  | @ -409,7 +409,7 @@ class ClassPropertiesAndMethods(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def test_python_dicts(self): |     def test_python_dicts(self): | ||||||
|         # Testing Python subclass of dict... |         # Testing Python subclass of dict... | ||||||
|         self.assertTrue(issubclass(dict, dict)) |         self.assertIsSubclass(dict, dict) | ||||||
|         self.assertIsInstance({}, dict) |         self.assertIsInstance({}, dict) | ||||||
|         d = dict() |         d = dict() | ||||||
|         self.assertEqual(d, {}) |         self.assertEqual(d, {}) | ||||||
|  | @ -433,7 +433,7 @@ def setstate(self, state): | ||||||
|                 self.state = state |                 self.state = state | ||||||
|             def getstate(self): |             def getstate(self): | ||||||
|                 return self.state |                 return self.state | ||||||
|         self.assertTrue(issubclass(C, dict)) |         self.assertIsSubclass(C, dict) | ||||||
|         a1 = C(12) |         a1 = C(12) | ||||||
|         self.assertEqual(a1.state, 12) |         self.assertEqual(a1.state, 12) | ||||||
|         a2 = C(foo=1, bar=2) |         a2 = C(foo=1, bar=2) | ||||||
|  | @ -1048,15 +1048,15 @@ class SubType(types.ModuleType): | ||||||
| 
 | 
 | ||||||
|         m = types.ModuleType("m") |         m = types.ModuleType("m") | ||||||
|         self.assertTrue(m.__class__ is types.ModuleType) |         self.assertTrue(m.__class__ is types.ModuleType) | ||||||
|         self.assertFalse(hasattr(m, "a")) |         self.assertNotHasAttr(m, "a") | ||||||
| 
 | 
 | ||||||
|         m.__class__ = SubType |         m.__class__ = SubType | ||||||
|         self.assertTrue(m.__class__ is SubType) |         self.assertTrue(m.__class__ is SubType) | ||||||
|         self.assertTrue(hasattr(m, "a")) |         self.assertHasAttr(m, "a") | ||||||
| 
 | 
 | ||||||
|         m.__class__ = types.ModuleType |         m.__class__ = types.ModuleType | ||||||
|         self.assertTrue(m.__class__ is types.ModuleType) |         self.assertTrue(m.__class__ is types.ModuleType) | ||||||
|         self.assertFalse(hasattr(m, "a")) |         self.assertNotHasAttr(m, "a") | ||||||
| 
 | 
 | ||||||
|         # Make sure that builtin immutable objects don't support __class__ |         # Make sure that builtin immutable objects don't support __class__ | ||||||
|         # assignment, because the object instances may be interned. |         # assignment, because the object instances may be interned. | ||||||
|  | @ -1780,7 +1780,7 @@ class D(C): | ||||||
|         class E: # *not* subclassing from C |         class E: # *not* subclassing from C | ||||||
|             foo = C.foo |             foo = C.foo | ||||||
|         self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound |         self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound | ||||||
|         self.assertTrue(repr(C.foo.__get__(C())).startswith("<bound method ")) |         self.assertStartsWith(repr(C.foo.__get__(C())), "<bound method ") | ||||||
| 
 | 
 | ||||||
|     def test_compattr(self): |     def test_compattr(self): | ||||||
|         # Testing computed attributes... |         # Testing computed attributes... | ||||||
|  | @ -2058,7 +2058,7 @@ class D(C): | ||||||
|         class E(object): |         class E(object): | ||||||
|             foo = C.foo |             foo = C.foo | ||||||
|         self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound |         self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound | ||||||
|         self.assertTrue(repr(C.foo.__get__(C(1))).startswith("<bound method ")) |         self.assertStartsWith(repr(C.foo.__get__(C(1))), "<bound method ") | ||||||
| 
 | 
 | ||||||
|     @support.impl_detail("testing error message from implementation") |     @support.impl_detail("testing error message from implementation") | ||||||
|     def test_methods_in_c(self): |     def test_methods_in_c(self): | ||||||
|  | @ -5195,8 +5195,8 @@ def test_repr(self): | ||||||
|         # We can't blindly compare with the repr of another dict as ordering |         # We can't blindly compare with the repr of another dict as ordering | ||||||
|         # of keys and values is arbitrary and may differ. |         # of keys and values is arbitrary and may differ. | ||||||
|         r = repr(self.C.__dict__) |         r = repr(self.C.__dict__) | ||||||
|         self.assertTrue(r.startswith('mappingproxy('), r) |         self.assertStartsWith(r, 'mappingproxy(') | ||||||
|         self.assertTrue(r.endswith(')'), r) |         self.assertEndsWith(r, ')') | ||||||
|         for k, v in self.C.__dict__.items(): |         for k, v in self.C.__dict__.items(): | ||||||
|             self.assertIn('{!r}: {!r}'.format(k, v), r) |             self.assertIn('{!r}: {!r}'.format(k, v), r) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -787,8 +787,8 @@ def test_dictview_mixed_set_operations(self): | ||||||
| 
 | 
 | ||||||
|     def test_missing(self): |     def test_missing(self): | ||||||
|         # Make sure dict doesn't have a __missing__ method |         # Make sure dict doesn't have a __missing__ method | ||||||
|         self.assertFalse(hasattr(dict, "__missing__")) |         self.assertNotHasAttr(dict, "__missing__") | ||||||
|         self.assertFalse(hasattr({}, "__missing__")) |         self.assertNotHasAttr({}, "__missing__") | ||||||
|         # Test several cases: |         # Test several cases: | ||||||
|         # (D) subclass defines __missing__ method returning a value |         # (D) subclass defines __missing__ method returning a value | ||||||
|         # (E) subclass defines __missing__ method raising RuntimeError |         # (E) subclass defines __missing__ method raising RuntimeError | ||||||
|  |  | ||||||
|  | @ -104,8 +104,8 @@ def test_property_decorator_baseclass(self): | ||||||
|         self.assertEqual(base.spam, 10) |         self.assertEqual(base.spam, 10) | ||||||
|         self.assertEqual(base._spam, 10) |         self.assertEqual(base._spam, 10) | ||||||
|         delattr(base, "spam") |         delattr(base, "spam") | ||||||
|         self.assertTrue(not hasattr(base, "spam")) |         self.assertNotHasAttr(base, "spam") | ||||||
|         self.assertTrue(not hasattr(base, "_spam")) |         self.assertNotHasAttr(base, "_spam") | ||||||
|         base.spam = 20 |         base.spam = 20 | ||||||
|         self.assertEqual(base.spam, 20) |         self.assertEqual(base.spam, 20) | ||||||
|         self.assertEqual(base._spam, 20) |         self.assertEqual(base._spam, 20) | ||||||
|  |  | ||||||
|  | @ -434,9 +434,9 @@ class Season(self.enum_type): | ||||||
|             def spam(cls): |             def spam(cls): | ||||||
|                 pass |                 pass | ||||||
|         # |         # | ||||||
|         self.assertTrue(hasattr(Season, 'spam')) |         self.assertHasAttr(Season, 'spam') | ||||||
|         del Season.spam |         del Season.spam | ||||||
|         self.assertFalse(hasattr(Season, 'spam')) |         self.assertNotHasAttr(Season, 'spam') | ||||||
|         # |         # | ||||||
|         with self.assertRaises(AttributeError): |         with self.assertRaises(AttributeError): | ||||||
|             del Season.SPRING |             del Season.SPRING | ||||||
|  | @ -2652,12 +2652,12 @@ def __new__(cls, value, period): | ||||||
|             OneDay = day_1 |             OneDay = day_1 | ||||||
|             OneWeek = week_1 |             OneWeek = week_1 | ||||||
|             OneMonth = month_1 |             OneMonth = month_1 | ||||||
|         self.assertFalse(hasattr(Period, '_ignore_')) |         self.assertNotHasAttr(Period, '_ignore_') | ||||||
|         self.assertFalse(hasattr(Period, 'Period')) |         self.assertNotHasAttr(Period, 'Period') | ||||||
|         self.assertFalse(hasattr(Period, 'i')) |         self.assertNotHasAttr(Period, 'i') | ||||||
|         self.assertTrue(isinstance(Period.day_1, timedelta)) |         self.assertIsInstance(Period.day_1, timedelta) | ||||||
|         self.assertTrue(Period.month_1 is Period.day_30) |         self.assertIs(Period.month_1, Period.day_30) | ||||||
|         self.assertTrue(Period.week_4 is Period.day_28) |         self.assertIs(Period.week_4, Period.day_28) | ||||||
| 
 | 
 | ||||||
|     def test_nonhash_value(self): |     def test_nonhash_value(self): | ||||||
|         class AutoNumberInAList(Enum): |         class AutoNumberInAList(Enum): | ||||||
|  | @ -2877,7 +2877,7 @@ class ReformedColor(StrMixin, IntEnum, SomeEnum, AnotherEnum): | ||||||
|         self.assertEqual(str(ReformedColor.BLUE), 'blue') |         self.assertEqual(str(ReformedColor.BLUE), 'blue') | ||||||
|         self.assertEqual(ReformedColor.RED.behavior(), 'booyah') |         self.assertEqual(ReformedColor.RED.behavior(), 'booyah') | ||||||
|         self.assertEqual(ConfusedColor.RED.social(), "what's up?") |         self.assertEqual(ConfusedColor.RED.social(), "what's up?") | ||||||
|         self.assertTrue(issubclass(ReformedColor, int)) |         self.assertIsSubclass(ReformedColor, int) | ||||||
| 
 | 
 | ||||||
|     def test_multiple_inherited_mixin(self): |     def test_multiple_inherited_mixin(self): | ||||||
|         @unique |         @unique | ||||||
|  |  | ||||||
|  | @ -12,14 +12,12 @@ class ErrnoAttributeTests(unittest.TestCase): | ||||||
|     def test_for_improper_attributes(self): |     def test_for_improper_attributes(self): | ||||||
|         # No unexpected attributes should be on the module. |         # No unexpected attributes should be on the module. | ||||||
|         for error_code in std_c_errors: |         for error_code in std_c_errors: | ||||||
|             self.assertTrue(hasattr(errno, error_code), |             self.assertHasAttr(errno, error_code) | ||||||
|                             "errno is missing %s" % error_code) |  | ||||||
| 
 | 
 | ||||||
|     def test_using_errorcode(self): |     def test_using_errorcode(self): | ||||||
|         # Every key value in errno.errorcode should be on the module. |         # Every key value in errno.errorcode should be on the module. | ||||||
|         for value in errno.errorcode.values(): |         for value in errno.errorcode.values(): | ||||||
|             self.assertTrue(hasattr(errno, value), |             self.assertHasAttr(errno, value) | ||||||
|                             'no %s attr in errno' % value) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ErrorcodeTests(unittest.TestCase): | class ErrorcodeTests(unittest.TestCase): | ||||||
|  |  | ||||||
|  | @ -5,9 +5,9 @@ | ||||||
| 
 | 
 | ||||||
| class TestExceptionGroupTypeHierarchy(unittest.TestCase): | class TestExceptionGroupTypeHierarchy(unittest.TestCase): | ||||||
|     def test_exception_group_types(self): |     def test_exception_group_types(self): | ||||||
|         self.assertTrue(issubclass(ExceptionGroup, Exception)) |         self.assertIsSubclass(ExceptionGroup, Exception) | ||||||
|         self.assertTrue(issubclass(ExceptionGroup, BaseExceptionGroup)) |         self.assertIsSubclass(ExceptionGroup, BaseExceptionGroup) | ||||||
|         self.assertTrue(issubclass(BaseExceptionGroup, BaseException)) |         self.assertIsSubclass(BaseExceptionGroup, BaseException) | ||||||
| 
 | 
 | ||||||
|     def test_exception_is_not_generic_type(self): |     def test_exception_is_not_generic_type(self): | ||||||
|         with self.assertRaisesRegex(TypeError, 'Exception'): |         with self.assertRaisesRegex(TypeError, 'Exception'): | ||||||
|  | @ -812,8 +812,8 @@ def test_split_does_not_copy_non_sequence_notes(self): | ||||||
|         eg = ExceptionGroup("eg", [ValueError(1), TypeError(2)]) |         eg = ExceptionGroup("eg", [ValueError(1), TypeError(2)]) | ||||||
|         eg.__notes__ = 123 |         eg.__notes__ = 123 | ||||||
|         match, rest = eg.split(TypeError) |         match, rest = eg.split(TypeError) | ||||||
|         self.assertFalse(hasattr(match, '__notes__')) |         self.assertNotHasAttr(match, '__notes__') | ||||||
|         self.assertFalse(hasattr(rest, '__notes__')) |         self.assertNotHasAttr(rest, '__notes__') | ||||||
| 
 | 
 | ||||||
|     def test_drive_invalid_return_value(self): |     def test_drive_invalid_return_value(self): | ||||||
|         class MyEg(ExceptionGroup): |         class MyEg(ExceptionGroup): | ||||||
|  |  | ||||||
|  | @ -357,7 +357,7 @@ def test_capi1(): | ||||||
|             except TypeError as err: |             except TypeError as err: | ||||||
|                 co = err.__traceback__.tb_frame.f_code |                 co = err.__traceback__.tb_frame.f_code | ||||||
|                 self.assertEqual(co.co_name, "test_capi1") |                 self.assertEqual(co.co_name, "test_capi1") | ||||||
|                 self.assertTrue(co.co_filename.endswith('test_exceptions.py')) |                 self.assertEndsWith(co.co_filename, 'test_exceptions.py') | ||||||
|             else: |             else: | ||||||
|                 self.fail("Expected exception") |                 self.fail("Expected exception") | ||||||
| 
 | 
 | ||||||
|  | @ -369,7 +369,7 @@ def test_capi2(): | ||||||
|                 tb = err.__traceback__.tb_next |                 tb = err.__traceback__.tb_next | ||||||
|                 co = tb.tb_frame.f_code |                 co = tb.tb_frame.f_code | ||||||
|                 self.assertEqual(co.co_name, "__init__") |                 self.assertEqual(co.co_name, "__init__") | ||||||
|                 self.assertTrue(co.co_filename.endswith('test_exceptions.py')) |                 self.assertEndsWith(co.co_filename, 'test_exceptions.py') | ||||||
|                 co2 = tb.tb_frame.f_back.f_code |                 co2 = tb.tb_frame.f_back.f_code | ||||||
|                 self.assertEqual(co2.co_name, "test_capi2") |                 self.assertEqual(co2.co_name, "test_capi2") | ||||||
|             else: |             else: | ||||||
|  | @ -598,7 +598,7 @@ def test_invalid_setstate(self): | ||||||
|     def test_notes(self): |     def test_notes(self): | ||||||
|         for e in [BaseException(1), Exception(2), ValueError(3)]: |         for e in [BaseException(1), Exception(2), ValueError(3)]: | ||||||
|             with self.subTest(e=e): |             with self.subTest(e=e): | ||||||
|                 self.assertFalse(hasattr(e, '__notes__')) |                 self.assertNotHasAttr(e, '__notes__') | ||||||
|                 e.add_note("My Note") |                 e.add_note("My Note") | ||||||
|                 self.assertEqual(e.__notes__, ["My Note"]) |                 self.assertEqual(e.__notes__, ["My Note"]) | ||||||
| 
 | 
 | ||||||
|  | @ -610,7 +610,7 @@ def test_notes(self): | ||||||
|                 self.assertEqual(e.__notes__, ["My Note", "Your Note"]) |                 self.assertEqual(e.__notes__, ["My Note", "Your Note"]) | ||||||
| 
 | 
 | ||||||
|                 del e.__notes__ |                 del e.__notes__ | ||||||
|                 self.assertFalse(hasattr(e, '__notes__')) |                 self.assertNotHasAttr(e, '__notes__') | ||||||
| 
 | 
 | ||||||
|                 e.add_note("Our Note") |                 e.add_note("Our Note") | ||||||
|                 self.assertEqual(e.__notes__, ["Our Note"]) |                 self.assertEqual(e.__notes__, ["Our Note"]) | ||||||
|  | @ -1627,7 +1627,7 @@ def test_exception_with_doc(self): | ||||||
|         # test basic usage of PyErr_NewException |         # test basic usage of PyErr_NewException | ||||||
|         error1 = _testcapi.make_exception_with_doc("_testcapi.error1") |         error1 = _testcapi.make_exception_with_doc("_testcapi.error1") | ||||||
|         self.assertIs(type(error1), type) |         self.assertIs(type(error1), type) | ||||||
|         self.assertTrue(issubclass(error1, Exception)) |         self.assertIsSubclass(error1, Exception) | ||||||
|         self.assertIsNone(error1.__doc__) |         self.assertIsNone(error1.__doc__) | ||||||
| 
 | 
 | ||||||
|         # test with given docstring |         # test with given docstring | ||||||
|  | @ -1637,21 +1637,21 @@ def test_exception_with_doc(self): | ||||||
|         # test with explicit base (without docstring) |         # test with explicit base (without docstring) | ||||||
|         error3 = _testcapi.make_exception_with_doc("_testcapi.error3", |         error3 = _testcapi.make_exception_with_doc("_testcapi.error3", | ||||||
|                                                    base=error2) |                                                    base=error2) | ||||||
|         self.assertTrue(issubclass(error3, error2)) |         self.assertIsSubclass(error3, error2) | ||||||
| 
 | 
 | ||||||
|         # test with explicit base tuple |         # test with explicit base tuple | ||||||
|         class C(object): |         class C(object): | ||||||
|             pass |             pass | ||||||
|         error4 = _testcapi.make_exception_with_doc("_testcapi.error4", doc4, |         error4 = _testcapi.make_exception_with_doc("_testcapi.error4", doc4, | ||||||
|                                                    (error3, C)) |                                                    (error3, C)) | ||||||
|         self.assertTrue(issubclass(error4, error3)) |         self.assertIsSubclass(error4, error3) | ||||||
|         self.assertTrue(issubclass(error4, C)) |         self.assertIsSubclass(error4, C) | ||||||
|         self.assertEqual(error4.__doc__, doc4) |         self.assertEqual(error4.__doc__, doc4) | ||||||
| 
 | 
 | ||||||
|         # test with explicit dictionary |         # test with explicit dictionary | ||||||
|         error5 = _testcapi.make_exception_with_doc("_testcapi.error5", "", |         error5 = _testcapi.make_exception_with_doc("_testcapi.error5", "", | ||||||
|                                                    error4, {'a': 1}) |                                                    error4, {'a': 1}) | ||||||
|         self.assertTrue(issubclass(error5, error4)) |         self.assertIsSubclass(error5, error4) | ||||||
|         self.assertEqual(error5.a, 1) |         self.assertEqual(error5.a, 1) | ||||||
|         self.assertEqual(error5.__doc__, "") |         self.assertEqual(error5.__doc__, "") | ||||||
| 
 | 
 | ||||||
|  | @ -1744,7 +1744,7 @@ def test_unhandled(self): | ||||||
|                     self.assertIn("<exception str() failed>", report) |                     self.assertIn("<exception str() failed>", report) | ||||||
|                 else: |                 else: | ||||||
|                     self.assertIn("test message", report) |                     self.assertIn("test message", report) | ||||||
|                 self.assertTrue(report.endswith("\n")) |                 self.assertEndsWith(report, "\n") | ||||||
| 
 | 
 | ||||||
|     @cpython_only |     @cpython_only | ||||||
|     # Python built with Py_TRACE_REFS fail with a fatal error in |     # Python built with Py_TRACE_REFS fail with a fatal error in | ||||||
|  |  | ||||||
|  | @ -245,7 +245,7 @@ def test_detached_stdin_binary_mode(self): | ||||||
|         orig_stdin = sys.stdin |         orig_stdin = sys.stdin | ||||||
|         try: |         try: | ||||||
|             sys.stdin = BytesIO(b'spam, bacon, sausage, and spam') |             sys.stdin = BytesIO(b'spam, bacon, sausage, and spam') | ||||||
|             self.assertFalse(hasattr(sys.stdin, 'buffer')) |             self.assertNotHasAttr(sys.stdin, 'buffer') | ||||||
|             fi = FileInput(files=['-'], mode='rb') |             fi = FileInput(files=['-'], mode='rb') | ||||||
|             lines = list(fi) |             lines = list(fi) | ||||||
|             self.assertEqual(lines, [b'spam, bacon, sausage, and spam']) |             self.assertEqual(lines, [b'spam, bacon, sausage, and spam']) | ||||||
|  |  | ||||||
|  | @ -914,7 +914,7 @@ def __del__(self): | ||||||
|         gc.collect() |         gc.collect() | ||||||
|         self.assertEqual(len(Lazarus.resurrected_instances), 1) |         self.assertEqual(len(Lazarus.resurrected_instances), 1) | ||||||
|         instance = Lazarus.resurrected_instances.pop() |         instance = Lazarus.resurrected_instances.pop() | ||||||
|         self.assertTrue(hasattr(instance, "cargo")) |         self.assertHasAttr(instance, "cargo") | ||||||
|         self.assertEqual(id(instance.cargo), cargo_id) |         self.assertEqual(id(instance.cargo), cargo_id) | ||||||
| 
 | 
 | ||||||
|         gc.collect() |         gc.collect() | ||||||
|  |  | ||||||
|  | @ -236,13 +236,13 @@ class MyGeneric: | ||||||
|         self.assertEqual(repr(x2), 'tuple[*tuple[int, str]]') |         self.assertEqual(repr(x2), 'tuple[*tuple[int, str]]') | ||||||
|         x3 = tuple[*tuple[int, ...]] |         x3 = tuple[*tuple[int, ...]] | ||||||
|         self.assertEqual(repr(x3), 'tuple[*tuple[int, ...]]') |         self.assertEqual(repr(x3), 'tuple[*tuple[int, ...]]') | ||||||
|         self.assertTrue(repr(MyList[int]).endswith('.BaseTest.test_repr.<locals>.MyList[int]')) |         self.assertEndsWith(repr(MyList[int]), '.BaseTest.test_repr.<locals>.MyList[int]') | ||||||
|         self.assertEqual(repr(list[str]()), '[]')  # instances should keep their normal repr |         self.assertEqual(repr(list[str]()), '[]')  # instances should keep their normal repr | ||||||
| 
 | 
 | ||||||
|         # gh-105488 |         # gh-105488 | ||||||
|         self.assertTrue(repr(MyGeneric[int]).endswith('MyGeneric[int]')) |         self.assertEndsWith(repr(MyGeneric[int]), 'MyGeneric[int]') | ||||||
|         self.assertTrue(repr(MyGeneric[[]]).endswith('MyGeneric[[]]')) |         self.assertEndsWith(repr(MyGeneric[[]]), 'MyGeneric[[]]') | ||||||
|         self.assertTrue(repr(MyGeneric[[int, str]]).endswith('MyGeneric[[int, str]]')) |         self.assertEndsWith(repr(MyGeneric[[int, str]]), 'MyGeneric[[int, str]]') | ||||||
| 
 | 
 | ||||||
|     def test_exposed_type(self): |     def test_exposed_type(self): | ||||||
|         import types |         import types | ||||||
|  | @ -362,7 +362,7 @@ def test_isinstance(self): | ||||||
| 
 | 
 | ||||||
|     def test_issubclass(self): |     def test_issubclass(self): | ||||||
|         class L(list): ... |         class L(list): ... | ||||||
|         self.assertTrue(issubclass(L, list)) |         self.assertIsSubclass(L, list) | ||||||
|         with self.assertRaises(TypeError): |         with self.assertRaises(TypeError): | ||||||
|             issubclass(L, list[str]) |             issubclass(L, list[str]) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -92,8 +92,8 @@ def test_commonprefix(self): | ||||||
|         for s1 in testlist: |         for s1 in testlist: | ||||||
|             for s2 in testlist: |             for s2 in testlist: | ||||||
|                 p = commonprefix([s1, s2]) |                 p = commonprefix([s1, s2]) | ||||||
|                 self.assertTrue(s1.startswith(p)) |                 self.assertStartsWith(s1, p) | ||||||
|                 self.assertTrue(s2.startswith(p)) |                 self.assertStartsWith(s2, p) | ||||||
|                 if s1 != s2: |                 if s1 != s2: | ||||||
|                     n = len(p) |                     n = len(p) | ||||||
|                     self.assertNotEqual(s1[n:n+1], s2[n:n+1]) |                     self.assertNotEqual(s1[n:n+1], s2[n:n+1]) | ||||||
|  |  | ||||||
|  | @ -331,13 +331,13 @@ def test_mode(self): | ||||||
|     def test_1647484(self): |     def test_1647484(self): | ||||||
|         for mode in ('wb', 'rb'): |         for mode in ('wb', 'rb'): | ||||||
|             with gzip.GzipFile(self.filename, mode) as f: |             with gzip.GzipFile(self.filename, mode) as f: | ||||||
|                 self.assertTrue(hasattr(f, "name")) |                 self.assertHasAttr(f, "name") | ||||||
|                 self.assertEqual(f.name, self.filename) |                 self.assertEqual(f.name, self.filename) | ||||||
| 
 | 
 | ||||||
|     def test_paddedfile_getattr(self): |     def test_paddedfile_getattr(self): | ||||||
|         self.test_write() |         self.test_write() | ||||||
|         with gzip.GzipFile(self.filename, 'rb') as f: |         with gzip.GzipFile(self.filename, 'rb') as f: | ||||||
|             self.assertTrue(hasattr(f.fileobj, "name")) |             self.assertHasAttr(f.fileobj, "name") | ||||||
|             self.assertEqual(f.fileobj.name, self.filename) |             self.assertEqual(f.fileobj.name, self.filename) | ||||||
| 
 | 
 | ||||||
|     def test_mtime(self): |     def test_mtime(self): | ||||||
|  | @ -345,7 +345,7 @@ def test_mtime(self): | ||||||
|         with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite: |         with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite: | ||||||
|             fWrite.write(data1) |             fWrite.write(data1) | ||||||
|         with gzip.GzipFile(self.filename) as fRead: |         with gzip.GzipFile(self.filename) as fRead: | ||||||
|             self.assertTrue(hasattr(fRead, 'mtime')) |             self.assertHasAttr(fRead, 'mtime') | ||||||
|             self.assertIsNone(fRead.mtime) |             self.assertIsNone(fRead.mtime) | ||||||
|             dataRead = fRead.read() |             dataRead = fRead.read() | ||||||
|             self.assertEqual(dataRead, data1) |             self.assertEqual(dataRead, data1) | ||||||
|  | @ -460,7 +460,7 @@ def test_zero_padded_file(self): | ||||||
|             self.assertEqual(d, data1 * 50, "Incorrect data in file") |             self.assertEqual(d, data1 * 50, "Incorrect data in file") | ||||||
| 
 | 
 | ||||||
|     def test_gzip_BadGzipFile_exception(self): |     def test_gzip_BadGzipFile_exception(self): | ||||||
|         self.assertTrue(issubclass(gzip.BadGzipFile, OSError)) |         self.assertIsSubclass(gzip.BadGzipFile, OSError) | ||||||
| 
 | 
 | ||||||
|     def test_bad_gzip_file(self): |     def test_bad_gzip_file(self): | ||||||
|         with open(self.filename, 'wb') as file: |         with open(self.filename, 'wb') as file: | ||||||
|  |  | ||||||
|  | @ -152,8 +152,8 @@ def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm, **kwargs): | ||||||
|         if _hashlib: |         if _hashlib: | ||||||
|             # These algorithms should always be present when this module |             # These algorithms should always be present when this module | ||||||
|             # is compiled.  If not, something was compiled wrong. |             # is compiled.  If not, something was compiled wrong. | ||||||
|             self.assertTrue(hasattr(_hashlib, 'openssl_md5')) |             self.assertHasAttr(_hashlib, 'openssl_md5') | ||||||
|             self.assertTrue(hasattr(_hashlib, 'openssl_sha1')) |             self.assertHasAttr(_hashlib, 'openssl_sha1') | ||||||
|             for algorithm, constructors in self.constructors_to_test.items(): |             for algorithm, constructors in self.constructors_to_test.items(): | ||||||
|                 constructor = getattr(_hashlib, 'openssl_'+algorithm, None) |                 constructor = getattr(_hashlib, 'openssl_'+algorithm, None) | ||||||
|                 if constructor: |                 if constructor: | ||||||
|  |  | ||||||
|  | @ -786,12 +786,12 @@ def test_getfile(self): | ||||||
|     def test_getfile_builtin_module(self): |     def test_getfile_builtin_module(self): | ||||||
|         with self.assertRaises(TypeError) as e: |         with self.assertRaises(TypeError) as e: | ||||||
|             inspect.getfile(sys) |             inspect.getfile(sys) | ||||||
|         self.assertTrue(str(e.exception).startswith('<module')) |         self.assertStartsWith(str(e.exception), '<module') | ||||||
| 
 | 
 | ||||||
|     def test_getfile_builtin_class(self): |     def test_getfile_builtin_class(self): | ||||||
|         with self.assertRaises(TypeError) as e: |         with self.assertRaises(TypeError) as e: | ||||||
|             inspect.getfile(int) |             inspect.getfile(int) | ||||||
|         self.assertTrue(str(e.exception).startswith('<class')) |         self.assertStartsWith(str(e.exception), '<class') | ||||||
| 
 | 
 | ||||||
|     def test_getfile_builtin_function_or_method(self): |     def test_getfile_builtin_function_or_method(self): | ||||||
|         with self.assertRaises(TypeError) as e_abs: |         with self.assertRaises(TypeError) as e_abs: | ||||||
|  | @ -2949,7 +2949,7 @@ def test(po, /, pk, pkd=100, *args, ko, kod=10, **kwargs): | ||||||
|             pass |             pass | ||||||
| 
 | 
 | ||||||
|         sig = inspect.signature(test) |         sig = inspect.signature(test) | ||||||
|         self.assertTrue(repr(sig).startswith('<Signature')) |         self.assertStartsWith(repr(sig), '<Signature') | ||||||
|         self.assertTrue('(po, /, pk' in repr(sig)) |         self.assertTrue('(po, /, pk' in repr(sig)) | ||||||
| 
 | 
 | ||||||
|         # We need two functions, because it is impossible to represent |         # We need two functions, because it is impossible to represent | ||||||
|  | @ -2958,7 +2958,7 @@ def test2(pod=42, /): | ||||||
|             pass |             pass | ||||||
| 
 | 
 | ||||||
|         sig2 = inspect.signature(test2) |         sig2 = inspect.signature(test2) | ||||||
|         self.assertTrue(repr(sig2).startswith('<Signature')) |         self.assertStartsWith(repr(sig2), '<Signature') | ||||||
|         self.assertTrue('(pod=42, /)' in repr(sig2)) |         self.assertTrue('(pod=42, /)' in repr(sig2)) | ||||||
| 
 | 
 | ||||||
|         po = sig.parameters['po'] |         po = sig.parameters['po'] | ||||||
|  | @ -5102,7 +5102,7 @@ def test_signature_parameter_object(self): | ||||||
|         with self.assertRaisesRegex(ValueError, 'cannot have default values'): |         with self.assertRaisesRegex(ValueError, 'cannot have default values'): | ||||||
|             p.replace(kind=inspect.Parameter.VAR_POSITIONAL) |             p.replace(kind=inspect.Parameter.VAR_POSITIONAL) | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(repr(p).startswith('<Parameter')) |         self.assertStartsWith(repr(p), '<Parameter') | ||||||
|         self.assertTrue('"a=42"' in repr(p)) |         self.assertTrue('"a=42"' in repr(p)) | ||||||
| 
 | 
 | ||||||
|     def test_signature_parameter_hashable(self): |     def test_signature_parameter_hashable(self): | ||||||
|  |  | ||||||
|  | @ -836,7 +836,7 @@ def test_pylong_roundtrip(self): | ||||||
|             n = hibit | getrandbits(bits - 1) |             n = hibit | getrandbits(bits - 1) | ||||||
|             assert n.bit_length() == bits |             assert n.bit_length() == bits | ||||||
|             sn = str(n) |             sn = str(n) | ||||||
|             self.assertFalse(sn.startswith('0')) |             self.assertNotStartsWith(sn, '0') | ||||||
|             self.assertEqual(n, int(sn)) |             self.assertEqual(n, int(sn)) | ||||||
|             bits <<= 1 |             bits <<= 1 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -902,7 +902,7 @@ def test_types_have_dict(self): | ||||||
|             self.BytesIO() |             self.BytesIO() | ||||||
|         ) |         ) | ||||||
|         for obj in test: |         for obj in test: | ||||||
|             self.assertTrue(hasattr(obj, "__dict__")) |             self.assertHasAttr(obj, "__dict__") | ||||||
| 
 | 
 | ||||||
|     def test_opener(self): |     def test_opener(self): | ||||||
|         with self.open(os_helper.TESTFN, "w", encoding="utf-8") as f: |         with self.open(os_helper.TESTFN, "w", encoding="utf-8") as f: | ||||||
|  | @ -1117,7 +1117,7 @@ def test_class_hierarchy(self): | ||||||
|         def check_subs(types, base): |         def check_subs(types, base): | ||||||
|             for tp in types: |             for tp in types: | ||||||
|                 with self.subTest(tp=tp, base=base): |                 with self.subTest(tp=tp, base=base): | ||||||
|                     self.assertTrue(issubclass(tp, base)) |                     self.assertIsSubclass(tp, base) | ||||||
| 
 | 
 | ||||||
|         def recursive_check(d): |         def recursive_check(d): | ||||||
|             for k, v in d.items(): |             for k, v in d.items(): | ||||||
|  | @ -1870,7 +1870,7 @@ def test_write_overflow(self): | ||||||
|         flushed = b"".join(writer._write_stack) |         flushed = b"".join(writer._write_stack) | ||||||
|         # At least (total - 8) bytes were implicitly flushed, perhaps more |         # At least (total - 8) bytes were implicitly flushed, perhaps more | ||||||
|         # depending on the implementation. |         # depending on the implementation. | ||||||
|         self.assertTrue(flushed.startswith(contents[:-8]), flushed) |         self.assertStartsWith(flushed, contents[:-8]) | ||||||
| 
 | 
 | ||||||
|     def check_writes(self, intermediate_func): |     def check_writes(self, intermediate_func): | ||||||
|         # Lots of writes, test the flushed output is as expected. |         # Lots of writes, test the flushed output is as expected. | ||||||
|  | @ -1940,7 +1940,7 @@ def test_write_non_blocking(self): | ||||||
|         self.assertEqual(bufio.write(b"ABCDEFGHI"), 9) |         self.assertEqual(bufio.write(b"ABCDEFGHI"), 9) | ||||||
|         s = raw.pop_written() |         s = raw.pop_written() | ||||||
|         # Previously buffered bytes were flushed |         # Previously buffered bytes were flushed | ||||||
|         self.assertTrue(s.startswith(b"01234567A"), s) |         self.assertStartsWith(s, b"01234567A") | ||||||
| 
 | 
 | ||||||
|     def test_write_and_rewind(self): |     def test_write_and_rewind(self): | ||||||
|         raw = self.BytesIO() |         raw = self.BytesIO() | ||||||
|  | @ -2236,7 +2236,7 @@ def test_write(self): | ||||||
|     def test_peek(self): |     def test_peek(self): | ||||||
|         pair = self.tp(self.BytesIO(b"abcdef"), self.MockRawIO()) |         pair = self.tp(self.BytesIO(b"abcdef"), self.MockRawIO()) | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(pair.peek(3).startswith(b"abc")) |         self.assertStartsWith(pair.peek(3), b"abc") | ||||||
|         self.assertEqual(pair.read(3), b"abc") |         self.assertEqual(pair.read(3), b"abc") | ||||||
| 
 | 
 | ||||||
|     def test_readable(self): |     def test_readable(self): | ||||||
|  | @ -4618,10 +4618,8 @@ def test_check_encoding_warning(self): | ||||||
|         proc = assert_python_ok('-X', 'warn_default_encoding', '-c', code) |         proc = assert_python_ok('-X', 'warn_default_encoding', '-c', code) | ||||||
|         warnings = proc.err.splitlines() |         warnings = proc.err.splitlines() | ||||||
|         self.assertEqual(len(warnings), 2) |         self.assertEqual(len(warnings), 2) | ||||||
|         self.assertTrue( |         self.assertStartsWith(warnings[0], b"<string>:5: EncodingWarning: ") | ||||||
|             warnings[0].startswith(b"<string>:5: EncodingWarning: ")) |         self.assertStartsWith(warnings[1], b"<string>:8: EncodingWarning: ") | ||||||
|         self.assertTrue( |  | ||||||
|             warnings[1].startswith(b"<string>:8: EncodingWarning: ")) |  | ||||||
| 
 | 
 | ||||||
|     def test_text_encoding(self): |     def test_text_encoding(self): | ||||||
|         # PEP 597, bpo-47000. io.text_encoding() returns "locale" or "utf-8" |         # PEP 597, bpo-47000. io.text_encoding() returns "locale" or "utf-8" | ||||||
|  | @ -4834,7 +4832,7 @@ def on_alarm(*args): | ||||||
|                     os.read(r, len(data) * 100) |                     os.read(r, len(data) * 100) | ||||||
|             exc = cm.exception |             exc = cm.exception | ||||||
|             if isinstance(exc, RuntimeError): |             if isinstance(exc, RuntimeError): | ||||||
|                 self.assertTrue(str(exc).startswith("reentrant call"), str(exc)) |                 self.assertStartsWith(str(exc), "reentrant call") | ||||||
|         finally: |         finally: | ||||||
|             signal.alarm(0) |             signal.alarm(0) | ||||||
|             wio.close() |             wio.close() | ||||||
|  |  | ||||||
|  | @ -102,7 +102,7 @@ def test_not_serializable(self): | ||||||
|         with self.assertRaisesRegex(TypeError, |         with self.assertRaisesRegex(TypeError, | ||||||
|                 'Object of type module is not JSON serializable') as cm: |                 'Object of type module is not JSON serializable') as cm: | ||||||
|             self.dumps(sys) |             self.dumps(sys) | ||||||
|         self.assertFalse(hasattr(cm.exception, '__notes__')) |         self.assertNotHasAttr(cm.exception, '__notes__') | ||||||
| 
 | 
 | ||||||
|         with self.assertRaises(TypeError) as cm: |         with self.assertRaises(TypeError) as cm: | ||||||
|             self.dumps([1, [2, 3, sys]]) |             self.dumps([1, [2, 3, sys]]) | ||||||
|  |  | ||||||
|  | @ -160,7 +160,7 @@ def test_help_flag(self): | ||||||
|         rc, out, err = assert_python_ok('-m', self.module, '-h', |         rc, out, err = assert_python_ok('-m', self.module, '-h', | ||||||
|                                         PYTHON_COLORS='0') |                                         PYTHON_COLORS='0') | ||||||
|         self.assertEqual(rc, 0) |         self.assertEqual(rc, 0) | ||||||
|         self.assertTrue(out.startswith(b'usage: ')) |         self.assertStartsWith(out, b'usage: ') | ||||||
|         self.assertEqual(err, b'') |         self.assertEqual(err, b'') | ||||||
| 
 | 
 | ||||||
|     def test_sort_keys_flag(self): |     def test_sort_keys_flag(self): | ||||||
|  |  | ||||||
|  | @ -443,7 +443,7 @@ def test_search_major_3(self): | ||||||
|         except subprocess.CalledProcessError: |         except subprocess.CalledProcessError: | ||||||
|             raise unittest.SkipTest("requires at least one Python 3.x install") |             raise unittest.SkipTest("requires at least one Python 3.x install") | ||||||
|         self.assertEqual("PythonCore", data["env.company"]) |         self.assertEqual("PythonCore", data["env.company"]) | ||||||
|         self.assertTrue(data["env.tag"].startswith("3."), data["env.tag"]) |         self.assertStartsWith(data["env.tag"], "3.") | ||||||
| 
 | 
 | ||||||
|     def test_search_major_3_32(self): |     def test_search_major_3_32(self): | ||||||
|         try: |         try: | ||||||
|  | @ -453,8 +453,8 @@ def test_search_major_3_32(self): | ||||||
|                 raise unittest.SkipTest("requires at least one 32-bit Python 3.x install") |                 raise unittest.SkipTest("requires at least one 32-bit Python 3.x install") | ||||||
|             raise |             raise | ||||||
|         self.assertEqual("PythonCore", data["env.company"]) |         self.assertEqual("PythonCore", data["env.company"]) | ||||||
|         self.assertTrue(data["env.tag"].startswith("3."), data["env.tag"]) |         self.assertStartsWith(data["env.tag"], "3.") | ||||||
|         self.assertTrue(data["env.tag"].endswith("-32"), data["env.tag"]) |         self.assertEndsWith(data["env.tag"], "-32") | ||||||
| 
 | 
 | ||||||
|     def test_search_major_2(self): |     def test_search_major_2(self): | ||||||
|         try: |         try: | ||||||
|  | @ -463,7 +463,7 @@ def test_search_major_2(self): | ||||||
|             if not is_installed("2.7"): |             if not is_installed("2.7"): | ||||||
|                 raise unittest.SkipTest("requires at least one Python 2.x install") |                 raise unittest.SkipTest("requires at least one Python 2.x install") | ||||||
|         self.assertEqual("PythonCore", data["env.company"]) |         self.assertEqual("PythonCore", data["env.company"]) | ||||||
|         self.assertTrue(data["env.tag"].startswith("2."), data["env.tag"]) |         self.assertStartsWith(data["env.tag"], "2.") | ||||||
| 
 | 
 | ||||||
|     def test_py_default(self): |     def test_py_default(self): | ||||||
|         with self.py_ini(TEST_PY_DEFAULTS): |         with self.py_ini(TEST_PY_DEFAULTS): | ||||||
|  |  | ||||||
|  | @ -1025,12 +1025,12 @@ def test_peek(self): | ||||||
|         with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |         with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: | ||||||
|             result = f.peek() |             result = f.peek() | ||||||
|             self.assertGreater(len(result), 0) |             self.assertGreater(len(result), 0) | ||||||
|             self.assertTrue(INPUT.startswith(result)) |             self.assertStartsWith(INPUT, result) | ||||||
|             self.assertEqual(f.read(), INPUT) |             self.assertEqual(f.read(), INPUT) | ||||||
|         with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |         with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: | ||||||
|             result = f.peek(10) |             result = f.peek(10) | ||||||
|             self.assertGreater(len(result), 0) |             self.assertGreater(len(result), 0) | ||||||
|             self.assertTrue(INPUT.startswith(result)) |             self.assertStartsWith(INPUT, result) | ||||||
|             self.assertEqual(f.read(), INPUT) |             self.assertEqual(f.read(), INPUT) | ||||||
| 
 | 
 | ||||||
|     def test_peek_bad_args(self): |     def test_peek_bad_args(self): | ||||||
|  |  | ||||||
|  | @ -265,8 +265,8 @@ def test_iterator(self): | ||||||
|         memio = self.ioclass(buf * 10) |         memio = self.ioclass(buf * 10) | ||||||
| 
 | 
 | ||||||
|         self.assertEqual(iter(memio), memio) |         self.assertEqual(iter(memio), memio) | ||||||
|         self.assertTrue(hasattr(memio, '__iter__')) |         self.assertHasAttr(memio, '__iter__') | ||||||
|         self.assertTrue(hasattr(memio, '__next__')) |         self.assertHasAttr(memio, '__next__') | ||||||
|         i = 0 |         i = 0 | ||||||
|         for line in memio: |         for line in memio: | ||||||
|             self.assertEqual(line, buf) |             self.assertEqual(line, buf) | ||||||
|  |  | ||||||
|  | @ -147,7 +147,7 @@ def test_fromkeys(self): | ||||||
|     def test_abc(self): |     def test_abc(self): | ||||||
|         OrderedDict = self.OrderedDict |         OrderedDict = self.OrderedDict | ||||||
|         self.assertIsInstance(OrderedDict(), MutableMapping) |         self.assertIsInstance(OrderedDict(), MutableMapping) | ||||||
|         self.assertTrue(issubclass(OrderedDict, MutableMapping)) |         self.assertIsSubclass(OrderedDict, MutableMapping) | ||||||
| 
 | 
 | ||||||
|     def test_clear(self): |     def test_clear(self): | ||||||
|         OrderedDict = self.OrderedDict |         OrderedDict = self.OrderedDict | ||||||
|  | @ -314,14 +314,14 @@ def check(dup): | ||||||
|         check(dup) |         check(dup) | ||||||
|         self.assertIs(dup.x, od.x) |         self.assertIs(dup.x, od.x) | ||||||
|         self.assertIs(dup.z, od.z) |         self.assertIs(dup.z, od.z) | ||||||
|         self.assertFalse(hasattr(dup, 'y')) |         self.assertNotHasAttr(dup, 'y') | ||||||
|         dup = copy.deepcopy(od) |         dup = copy.deepcopy(od) | ||||||
|         check(dup) |         check(dup) | ||||||
|         self.assertEqual(dup.x, od.x) |         self.assertEqual(dup.x, od.x) | ||||||
|         self.assertIsNot(dup.x, od.x) |         self.assertIsNot(dup.x, od.x) | ||||||
|         self.assertEqual(dup.z, od.z) |         self.assertEqual(dup.z, od.z) | ||||||
|         self.assertIsNot(dup.z, od.z) |         self.assertIsNot(dup.z, od.z) | ||||||
|         self.assertFalse(hasattr(dup, 'y')) |         self.assertNotHasAttr(dup, 'y') | ||||||
|         # pickle directly pulls the module, so we have to fake it |         # pickle directly pulls the module, so we have to fake it | ||||||
|         with replaced_module('collections', self.module): |         with replaced_module('collections', self.module): | ||||||
|             for proto in range(pickle.HIGHEST_PROTOCOL + 1): |             for proto in range(pickle.HIGHEST_PROTOCOL + 1): | ||||||
|  | @ -330,7 +330,7 @@ def check(dup): | ||||||
|                     check(dup) |                     check(dup) | ||||||
|                     self.assertEqual(dup.x, od.x) |                     self.assertEqual(dup.x, od.x) | ||||||
|                     self.assertEqual(dup.z, od.z) |                     self.assertEqual(dup.z, od.z) | ||||||
|                     self.assertFalse(hasattr(dup, 'y')) |                     self.assertNotHasAttr(dup, 'y') | ||||||
|         check(eval(repr(od))) |         check(eval(repr(od))) | ||||||
|         update_test = OrderedDict() |         update_test = OrderedDict() | ||||||
|         update_test.update(od) |         update_test.update(od) | ||||||
|  |  | ||||||
|  | @ -818,7 +818,7 @@ def test_15261(self): | ||||||
|         self.assertEqual(ctx.exception.errno, errno.EBADF) |         self.assertEqual(ctx.exception.errno, errno.EBADF) | ||||||
| 
 | 
 | ||||||
|     def check_file_attributes(self, result): |     def check_file_attributes(self, result): | ||||||
|         self.assertTrue(hasattr(result, 'st_file_attributes')) |         self.assertHasAttr(result, 'st_file_attributes') | ||||||
|         self.assertTrue(isinstance(result.st_file_attributes, int)) |         self.assertTrue(isinstance(result.st_file_attributes, int)) | ||||||
|         self.assertTrue(0 <= result.st_file_attributes <= 0xFFFFFFFF) |         self.assertTrue(0 <= result.st_file_attributes <= 0xFFFFFFFF) | ||||||
| 
 | 
 | ||||||
|  | @ -2181,7 +2181,7 @@ def test_getrandom0(self): | ||||||
|         self.assertEqual(empty, b'') |         self.assertEqual(empty, b'') | ||||||
| 
 | 
 | ||||||
|     def test_getrandom_random(self): |     def test_getrandom_random(self): | ||||||
|         self.assertTrue(hasattr(os, 'GRND_RANDOM')) |         self.assertHasAttr(os, 'GRND_RANDOM') | ||||||
| 
 | 
 | ||||||
|         # Don't test os.getrandom(1, os.GRND_RANDOM) to not consume the rare |         # Don't test os.getrandom(1, os.GRND_RANDOM) to not consume the rare | ||||||
|         # resource /dev/random |         # resource /dev/random | ||||||
|  | @ -5431,8 +5431,8 @@ def test_fsencode_fsdecode(self): | ||||||
| 
 | 
 | ||||||
|     def test_pathlike(self): |     def test_pathlike(self): | ||||||
|         self.assertEqual('#feelthegil', self.fspath(FakePath('#feelthegil'))) |         self.assertEqual('#feelthegil', self.fspath(FakePath('#feelthegil'))) | ||||||
|         self.assertTrue(issubclass(FakePath, os.PathLike)) |         self.assertIsSubclass(FakePath, os.PathLike) | ||||||
|         self.assertTrue(isinstance(FakePath('x'), os.PathLike)) |         self.assertIsInstance(FakePath('x'), os.PathLike) | ||||||
| 
 | 
 | ||||||
|     def test_garbage_in_exception_out(self): |     def test_garbage_in_exception_out(self): | ||||||
|         vapor = type('blah', (), {}) |         vapor = type('blah', (), {}) | ||||||
|  | @ -5458,8 +5458,8 @@ def test_pathlike_subclasshook(self): | ||||||
|         # true on abstract implementation. |         # true on abstract implementation. | ||||||
|         class A(os.PathLike): |         class A(os.PathLike): | ||||||
|             pass |             pass | ||||||
|         self.assertFalse(issubclass(FakePath, A)) |         self.assertNotIsSubclass(FakePath, A) | ||||||
|         self.assertTrue(issubclass(FakePath, os.PathLike)) |         self.assertIsSubclass(FakePath, os.PathLike) | ||||||
| 
 | 
 | ||||||
|     def test_pathlike_class_getitem(self): |     def test_pathlike_class_getitem(self): | ||||||
|         self.assertIsInstance(os.PathLike[bytes], types.GenericAlias) |         self.assertIsInstance(os.PathLike[bytes], types.GenericAlias) | ||||||
|  | @ -5469,7 +5469,7 @@ class A(os.PathLike): | ||||||
|             __slots__ = () |             __slots__ = () | ||||||
|             def __fspath__(self): |             def __fspath__(self): | ||||||
|                 return '' |                 return '' | ||||||
|         self.assertFalse(hasattr(A(), '__dict__')) |         self.assertNotHasAttr(A(), '__dict__') | ||||||
| 
 | 
 | ||||||
|     def test_fspath_set_to_None(self): |     def test_fspath_set_to_None(self): | ||||||
|         class Foo: |         class Foo: | ||||||
|  |  | ||||||
|  | @ -77,8 +77,8 @@ def needs_symlinks(fn): | ||||||
| 
 | 
 | ||||||
| class UnsupportedOperationTest(unittest.TestCase): | class UnsupportedOperationTest(unittest.TestCase): | ||||||
|     def test_is_notimplemented(self): |     def test_is_notimplemented(self): | ||||||
|         self.assertTrue(issubclass(pathlib.UnsupportedOperation, NotImplementedError)) |         self.assertIsSubclass(pathlib.UnsupportedOperation, NotImplementedError) | ||||||
|         self.assertTrue(isinstance(pathlib.UnsupportedOperation(), NotImplementedError)) |         self.assertIsInstance(pathlib.UnsupportedOperation(), NotImplementedError) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class LazyImportTest(unittest.TestCase): | class LazyImportTest(unittest.TestCase): | ||||||
|  | @ -300,8 +300,8 @@ def test_repr_common(self): | ||||||
|                 clsname = p.__class__.__name__ |                 clsname = p.__class__.__name__ | ||||||
|                 r = repr(p) |                 r = repr(p) | ||||||
|                 # The repr() is in the form ClassName("forward-slashes path"). |                 # The repr() is in the form ClassName("forward-slashes path"). | ||||||
|                 self.assertTrue(r.startswith(clsname + '('), r) |                 self.assertStartsWith(r, clsname + '(') | ||||||
|                 self.assertTrue(r.endswith(')'), r) |                 self.assertEndsWith(r, ')') | ||||||
|                 inner = r[len(clsname) + 1 : -1] |                 inner = r[len(clsname) + 1 : -1] | ||||||
|                 self.assertEqual(eval(inner), p.as_posix()) |                 self.assertEqual(eval(inner), p.as_posix()) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -316,7 +316,7 @@ def negzero(): | ||||||
|             return -(1.0-1.0) |             return -(1.0-1.0) | ||||||
| 
 | 
 | ||||||
|         for instr in dis.get_instructions(negzero): |         for instr in dis.get_instructions(negzero): | ||||||
|             self.assertFalse(instr.opname.startswith('UNARY_')) |             self.assertNotStartsWith(instr.opname, 'UNARY_') | ||||||
|         self.check_lnotab(negzero) |         self.check_lnotab(negzero) | ||||||
| 
 | 
 | ||||||
|     def test_constant_folding_binop(self): |     def test_constant_folding_binop(self): | ||||||
|  |  | ||||||
|  | @ -387,10 +387,10 @@ def test_with_stmt_with_paren(self) -> None: | ||||||
|         test_source = """ |         test_source = """ | ||||||
|         stmt = "with (\\n    a as b,\\n    c as d\\n): pass" |         stmt = "with (\\n    a as b,\\n    c as d\\n): pass" | ||||||
|         the_ast = parse.parse_string(stmt, mode=1) |         the_ast = parse.parse_string(stmt, mode=1) | ||||||
|         self.assertTrue(ast_dump(the_ast).startswith( |         self.assertStartsWith(ast_dump(the_ast), | ||||||
|             "Module(body=[With(items=[withitem(context_expr=Name(id='a', ctx=Load()), optional_vars=Name(id='b', ctx=Store())), " |             "Module(body=[With(items=[withitem(context_expr=Name(id='a', ctx=Load()), optional_vars=Name(id='b', ctx=Store())), " | ||||||
|             "withitem(context_expr=Name(id='c', ctx=Load()), optional_vars=Name(id='d', ctx=Store()))]" |             "withitem(context_expr=Name(id='c', ctx=Load()), optional_vars=Name(id='d', ctx=Store()))]" | ||||||
|         )) |         ) | ||||||
|         """ |         """ | ||||||
|         self.run_test(grammar_source, test_source) |         self.run_test(grammar_source, test_source) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -91,10 +91,8 @@ def test_gather(self) -> None: | ||||||
|         """ |         """ | ||||||
|         rules = parse_string(grammar, GrammarParser).rules |         rules = parse_string(grammar, GrammarParser).rules | ||||||
|         self.assertEqual(str(rules["start"]), "start: ','.thing+ NEWLINE") |         self.assertEqual(str(rules["start"]), "start: ','.thing+ NEWLINE") | ||||||
|         self.assertTrue( |         self.assertStartsWith(repr(rules["start"]), | ||||||
|             repr(rules["start"]).startswith( |             "Rule('start', None, Rhs([Alt([NamedItem(None, Gather(StringLeaf(\"','\"), NameLeaf('thing'" | ||||||
|                 "Rule('start', None, Rhs([Alt([NamedItem(None, Gather(StringLeaf(\"','\"), NameLeaf('thing'" |  | ||||||
|             ) |  | ||||||
|         ) |         ) | ||||||
|         self.assertEqual(str(rules["thing"]), "thing: NUMBER") |         self.assertEqual(str(rules["thing"]), "thing: NUMBER") | ||||||
|         parser_class = make_parser(grammar) |         parser_class = make_parser(grammar) | ||||||
|  |  | ||||||
|  | @ -93,9 +93,7 @@ def baz(): | ||||||
|                 perf_line, f"Could not find {expected_symbol} in perf file" |                 perf_line, f"Could not find {expected_symbol} in perf file" | ||||||
|             ) |             ) | ||||||
|             perf_addr = perf_line.split(" ")[0] |             perf_addr = perf_line.split(" ")[0] | ||||||
|             self.assertFalse( |             self.assertNotStartsWith(perf_addr, "0x") | ||||||
|                 perf_addr.startswith("0x"), "Address should not be prefixed with 0x" |  | ||||||
|             ) |  | ||||||
|             self.assertTrue( |             self.assertTrue( | ||||||
|                 set(perf_addr).issubset(string.hexdigits), |                 set(perf_addr).issubset(string.hexdigits), | ||||||
|                 "Address should contain only hex characters", |                 "Address should contain only hex characters", | ||||||
|  |  | ||||||
|  | @ -611,10 +611,10 @@ def test_name_mapping(self): | ||||||
|             with self.subTest(((module3, name3), (module2, name2))): |             with self.subTest(((module3, name3), (module2, name2))): | ||||||
|                 if (module2, name2) == ('exceptions', 'OSError'): |                 if (module2, name2) == ('exceptions', 'OSError'): | ||||||
|                     attr = getattribute(module3, name3) |                     attr = getattribute(module3, name3) | ||||||
|                     self.assertTrue(issubclass(attr, OSError)) |                     self.assertIsSubclass(attr, OSError) | ||||||
|                 elif (module2, name2) == ('exceptions', 'ImportError'): |                 elif (module2, name2) == ('exceptions', 'ImportError'): | ||||||
|                     attr = getattribute(module3, name3) |                     attr = getattribute(module3, name3) | ||||||
|                     self.assertTrue(issubclass(attr, ImportError)) |                     self.assertIsSubclass(attr, ImportError) | ||||||
|                 else: |                 else: | ||||||
|                     module, name = mapping(module2, name2) |                     module, name = mapping(module2, name2) | ||||||
|                     if module3[:1] != '_': |                     if module3[:1] != '_': | ||||||
|  |  | ||||||
|  | @ -410,7 +410,7 @@ def test_win32_ver(self): | ||||||
|             for v in version.split('.'): |             for v in version.split('.'): | ||||||
|                 int(v)  # should not fail |                 int(v)  # should not fail | ||||||
|         if csd: |         if csd: | ||||||
|             self.assertTrue(csd.startswith('SP'), msg=csd) |             self.assertStartsWith(csd, 'SP') | ||||||
|         if ptype: |         if ptype: | ||||||
|             if os.cpu_count() > 1: |             if os.cpu_count() > 1: | ||||||
|                 self.assertIn('Multiprocessor', ptype) |                 self.assertIn('Multiprocessor', ptype) | ||||||
|  |  | ||||||
|  | @ -1107,7 +1107,7 @@ def test_lchmod_dir_symlink(self): | ||||||
| 
 | 
 | ||||||
|     def _test_chflags_regular_file(self, chflags_func, target_file, **kwargs): |     def _test_chflags_regular_file(self, chflags_func, target_file, **kwargs): | ||||||
|         st = os.stat(target_file) |         st = os.stat(target_file) | ||||||
|         self.assertTrue(hasattr(st, 'st_flags')) |         self.assertHasAttr(st, 'st_flags') | ||||||
| 
 | 
 | ||||||
|         # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE. |         # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE. | ||||||
|         flags = st.st_flags | stat.UF_IMMUTABLE |         flags = st.st_flags | stat.UF_IMMUTABLE | ||||||
|  | @ -1143,7 +1143,7 @@ def test_lchflags_regular_file(self): | ||||||
|     def test_lchflags_symlink(self): |     def test_lchflags_symlink(self): | ||||||
|         testfn_st = os.stat(os_helper.TESTFN) |         testfn_st = os.stat(os_helper.TESTFN) | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(hasattr(testfn_st, 'st_flags')) |         self.assertHasAttr(testfn_st, 'st_flags') | ||||||
| 
 | 
 | ||||||
|         self.addCleanup(os_helper.unlink, _DUMMY_SYMLINK) |         self.addCleanup(os_helper.unlink, _DUMMY_SYMLINK) | ||||||
|         os.symlink(os_helper.TESTFN, _DUMMY_SYMLINK) |         os.symlink(os_helper.TESTFN, _DUMMY_SYMLINK) | ||||||
|  | @ -2218,12 +2218,12 @@ def _verify_available(self, name): | ||||||
|     def test_pwritev(self): |     def test_pwritev(self): | ||||||
|         self._verify_available("HAVE_PWRITEV") |         self._verify_available("HAVE_PWRITEV") | ||||||
|         if self.mac_ver >= (10, 16): |         if self.mac_ver >= (10, 16): | ||||||
|             self.assertTrue(hasattr(os, "pwritev"), "os.pwritev is not available") |             self.assertHasAttr(os, "pwritev") | ||||||
|             self.assertTrue(hasattr(os, "preadv"), "os.readv is not available") |             self.assertHasAttr(os, "preadv") | ||||||
| 
 | 
 | ||||||
|         else: |         else: | ||||||
|             self.assertFalse(hasattr(os, "pwritev"), "os.pwritev is available") |             self.assertNotHasAttr(os, "pwritev") | ||||||
|             self.assertFalse(hasattr(os, "preadv"), "os.readv is available") |             self.assertNotHasAttr(os, "preadv") | ||||||
| 
 | 
 | ||||||
|     def test_stat(self): |     def test_stat(self): | ||||||
|         self._verify_available("HAVE_FSTATAT") |         self._verify_available("HAVE_FSTATAT") | ||||||
|  |  | ||||||
|  | @ -87,8 +87,8 @@ def test_property_decorator_baseclass(self): | ||||||
|         self.assertEqual(base.spam, 10) |         self.assertEqual(base.spam, 10) | ||||||
|         self.assertEqual(base._spam, 10) |         self.assertEqual(base._spam, 10) | ||||||
|         delattr(base, "spam") |         delattr(base, "spam") | ||||||
|         self.assertTrue(not hasattr(base, "spam")) |         self.assertNotHasAttr(base, "spam") | ||||||
|         self.assertTrue(not hasattr(base, "_spam")) |         self.assertNotHasAttr(base, "_spam") | ||||||
|         base.spam = 20 |         base.spam = 20 | ||||||
|         self.assertEqual(base.spam, 20) |         self.assertEqual(base.spam, 20) | ||||||
|         self.assertEqual(base._spam, 20) |         self.assertEqual(base._spam, 20) | ||||||
|  |  | ||||||
|  | @ -46,7 +46,7 @@ def test_parse_semantics(self): | ||||||
|         items = pulldom.parseString(SMALL_SAMPLE) |         items = pulldom.parseString(SMALL_SAMPLE) | ||||||
|         evt, node = next(items) |         evt, node = next(items) | ||||||
|         # Just check the node is a Document: |         # Just check the node is a Document: | ||||||
|         self.assertTrue(hasattr(node, "createElement")) |         self.assertHasAttr(node, "createElement") | ||||||
|         self.assertEqual(pulldom.START_DOCUMENT, evt) |         self.assertEqual(pulldom.START_DOCUMENT, evt) | ||||||
|         evt, node = next(items) |         evt, node = next(items) | ||||||
|         self.assertEqual(pulldom.START_ELEMENT, evt) |         self.assertEqual(pulldom.START_ELEMENT, evt) | ||||||
|  | @ -192,7 +192,7 @@ def _test_thorough(self, pd, before_root=True): | ||||||
|         evt, node = next(pd) |         evt, node = next(pd) | ||||||
|         self.assertEqual(pulldom.START_DOCUMENT, evt) |         self.assertEqual(pulldom.START_DOCUMENT, evt) | ||||||
|         # Just check the node is a Document: |         # Just check the node is a Document: | ||||||
|         self.assertTrue(hasattr(node, "createElement")) |         self.assertHasAttr(node, "createElement") | ||||||
| 
 | 
 | ||||||
|         if before_root: |         if before_root: | ||||||
|             evt, node = next(pd) |             evt, node = next(pd) | ||||||
|  |  | ||||||
|  | @ -103,7 +103,7 @@ def ismethod(oclass, obj, name): | ||||||
|         for name, value in dict.items(): |         for name, value in dict.items(): | ||||||
|             if name in ignore: |             if name in ignore: | ||||||
|                 continue |                 continue | ||||||
|             self.assertHasAttr(module, name, ignore) |             self.assertHasAttr(module, name) | ||||||
|             py_item = getattr(module, name) |             py_item = getattr(module, name) | ||||||
|             if isinstance(value, pyclbr.Function): |             if isinstance(value, pyclbr.Function): | ||||||
|                 self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType)) |                 self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType)) | ||||||
|  |  | ||||||
|  | @ -1380,7 +1380,7 @@ def test_modules_search_builtin(self): | ||||||
|             helper('modules garbage') |             helper('modules garbage') | ||||||
|         result = help_io.getvalue() |         result = help_io.getvalue() | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(result.startswith(expected)) |         self.assertStartsWith(result, expected) | ||||||
| 
 | 
 | ||||||
|     def test_importfile(self): |     def test_importfile(self): | ||||||
|         try: |         try: | ||||||
|  |  | ||||||
|  | @ -1415,27 +1415,27 @@ class CommandLineTest(unittest.TestCase): | ||||||
|     def test_parse_args(self): |     def test_parse_args(self): | ||||||
|         args, help_text = random._parse_args(shlex.split("--choice a b c")) |         args, help_text = random._parse_args(shlex.split("--choice a b c")) | ||||||
|         self.assertEqual(args.choice, ["a", "b", "c"]) |         self.assertEqual(args.choice, ["a", "b", "c"]) | ||||||
|         self.assertTrue(help_text.startswith("usage: ")) |         self.assertStartsWith(help_text, "usage: ") | ||||||
| 
 | 
 | ||||||
|         args, help_text = random._parse_args(shlex.split("--integer 5")) |         args, help_text = random._parse_args(shlex.split("--integer 5")) | ||||||
|         self.assertEqual(args.integer, 5) |         self.assertEqual(args.integer, 5) | ||||||
|         self.assertTrue(help_text.startswith("usage: ")) |         self.assertStartsWith(help_text, "usage: ") | ||||||
| 
 | 
 | ||||||
|         args, help_text = random._parse_args(shlex.split("--float 2.5")) |         args, help_text = random._parse_args(shlex.split("--float 2.5")) | ||||||
|         self.assertEqual(args.float, 2.5) |         self.assertEqual(args.float, 2.5) | ||||||
|         self.assertTrue(help_text.startswith("usage: ")) |         self.assertStartsWith(help_text, "usage: ") | ||||||
| 
 | 
 | ||||||
|         args, help_text = random._parse_args(shlex.split("a b c")) |         args, help_text = random._parse_args(shlex.split("a b c")) | ||||||
|         self.assertEqual(args.input, ["a", "b", "c"]) |         self.assertEqual(args.input, ["a", "b", "c"]) | ||||||
|         self.assertTrue(help_text.startswith("usage: ")) |         self.assertStartsWith(help_text, "usage: ") | ||||||
| 
 | 
 | ||||||
|         args, help_text = random._parse_args(shlex.split("5")) |         args, help_text = random._parse_args(shlex.split("5")) | ||||||
|         self.assertEqual(args.input, ["5"]) |         self.assertEqual(args.input, ["5"]) | ||||||
|         self.assertTrue(help_text.startswith("usage: ")) |         self.assertStartsWith(help_text, "usage: ") | ||||||
| 
 | 
 | ||||||
|         args, help_text = random._parse_args(shlex.split("2.5")) |         args, help_text = random._parse_args(shlex.split("2.5")) | ||||||
|         self.assertEqual(args.input, ["2.5"]) |         self.assertEqual(args.input, ["2.5"]) | ||||||
|         self.assertTrue(help_text.startswith("usage: ")) |         self.assertStartsWith(help_text, "usage: ") | ||||||
| 
 | 
 | ||||||
|     def test_main(self): |     def test_main(self): | ||||||
|         for command, expected in [ |         for command, expected in [ | ||||||
|  |  | ||||||
|  | @ -2868,11 +2868,11 @@ def test_long_pattern(self): | ||||||
|         pattern = 'Very %spattern' % ('long ' * 1000) |         pattern = 'Very %spattern' % ('long ' * 1000) | ||||||
|         r = repr(re.compile(pattern)) |         r = repr(re.compile(pattern)) | ||||||
|         self.assertLess(len(r), 300) |         self.assertLess(len(r), 300) | ||||||
|         self.assertEqual(r[:30], "re.compile('Very long long lon") |         self.assertStartsWith(r, "re.compile('Very long long lon") | ||||||
|         r = repr(re.compile(pattern, re.I)) |         r = repr(re.compile(pattern, re.I)) | ||||||
|         self.assertLess(len(r), 300) |         self.assertLess(len(r), 300) | ||||||
|         self.assertEqual(r[:30], "re.compile('Very long long lon") |         self.assertStartsWith(r, "re.compile('Very long long lon") | ||||||
|         self.assertEqual(r[-16:], ", re.IGNORECASE)") |         self.assertEndsWith(r, ", re.IGNORECASE)") | ||||||
| 
 | 
 | ||||||
|     def test_flags_repr(self): |     def test_flags_repr(self): | ||||||
|         self.assertEqual(repr(re.I), "re.IGNORECASE") |         self.assertEqual(repr(re.I), "re.IGNORECASE") | ||||||
|  | @ -2951,7 +2951,7 @@ def test_deprecated_modules(self): | ||||||
|                 self.assertEqual(mod.__name__, name) |                 self.assertEqual(mod.__name__, name) | ||||||
|                 self.assertEqual(mod.__package__, '') |                 self.assertEqual(mod.__package__, '') | ||||||
|                 for attr in deprecated[name]: |                 for attr in deprecated[name]: | ||||||
|                     self.assertTrue(hasattr(mod, attr)) |                     self.assertHasAttr(mod, attr) | ||||||
|                 del sys.modules[name] |                 del sys.modules[name] | ||||||
| 
 | 
 | ||||||
|     @cpython_only |     @cpython_only | ||||||
|  |  | ||||||
|  | @ -173,13 +173,13 @@ def test_instance(self): | ||||||
|         eq(r(i3), ("<ClassWithFailingRepr instance at %#x>"%id(i3))) |         eq(r(i3), ("<ClassWithFailingRepr instance at %#x>"%id(i3))) | ||||||
| 
 | 
 | ||||||
|         s = r(ClassWithFailingRepr) |         s = r(ClassWithFailingRepr) | ||||||
|         self.assertTrue(s.startswith("<class ")) |         self.assertStartsWith(s, "<class ") | ||||||
|         self.assertTrue(s.endswith(">")) |         self.assertEndsWith(s, ">") | ||||||
|         self.assertIn(s.find("..."), [12, 13]) |         self.assertIn(s.find("..."), [12, 13]) | ||||||
| 
 | 
 | ||||||
|     def test_lambda(self): |     def test_lambda(self): | ||||||
|         r = repr(lambda x: x) |         r = repr(lambda x: x) | ||||||
|         self.assertTrue(r.startswith("<function ReprTests.test_lambda.<locals>.<lambda"), r) |         self.assertStartsWith(r, "<function ReprTests.test_lambda.<locals>.<lambda") | ||||||
|         # XXX anonymous functions?  see func_repr |         # XXX anonymous functions?  see func_repr | ||||||
| 
 | 
 | ||||||
|     def test_builtin_function(self): |     def test_builtin_function(self): | ||||||
|  | @ -187,8 +187,8 @@ def test_builtin_function(self): | ||||||
|         # Functions |         # Functions | ||||||
|         eq(repr(hash), '<built-in function hash>') |         eq(repr(hash), '<built-in function hash>') | ||||||
|         # Methods |         # Methods | ||||||
|         self.assertTrue(repr(''.split).startswith( |         self.assertStartsWith(repr(''.split), | ||||||
|             '<built-in method split of str object at 0x')) |             '<built-in method split of str object at 0x') | ||||||
| 
 | 
 | ||||||
|     def test_range(self): |     def test_range(self): | ||||||
|         eq = self.assertEqual |         eq = self.assertEqual | ||||||
|  | @ -730,8 +730,8 @@ class baz: | ||||||
|         importlib.invalidate_caches() |         importlib.invalidate_caches() | ||||||
|         from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz |         from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz | ||||||
|         ibaz = baz.baz() |         ibaz = baz.baz() | ||||||
|         self.assertTrue(repr(ibaz).startswith( |         self.assertStartsWith(repr(ibaz), | ||||||
|             "<%s.baz object at 0x" % baz.__name__)) |             "<%s.baz object at 0x" % baz.__name__) | ||||||
| 
 | 
 | ||||||
|     def test_method(self): |     def test_method(self): | ||||||
|         self._check_path_limitations('qux') |         self._check_path_limitations('qux') | ||||||
|  | @ -744,13 +744,13 @@ def amethod(self): pass | ||||||
|         from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux |         from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux | ||||||
|         # Unbound methods first |         # Unbound methods first | ||||||
|         r = repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod) |         r = repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod) | ||||||
|         self.assertTrue(r.startswith('<function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod'), r) |         self.assertStartsWith(r, '<function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod') | ||||||
|         # Bound method next |         # Bound method next | ||||||
|         iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() |         iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() | ||||||
|         r = repr(iqux.amethod) |         r = repr(iqux.amethod) | ||||||
|         self.assertTrue(r.startswith( |         self.assertStartsWith(r, | ||||||
|             '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa object at 0x' \ |             '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa object at 0x' \ | ||||||
|             % (qux.__name__,) ), r) |             % (qux.__name__,) ) | ||||||
| 
 | 
 | ||||||
|     @unittest.skip('needs a built-in function with a really long name') |     @unittest.skip('needs a built-in function with a really long name') | ||||||
|     def test_builtin_function(self): |     def test_builtin_function(self): | ||||||
|  |  | ||||||
|  | @ -88,7 +88,7 @@ def create_expected_for_none(): | ||||||
|                          ['CompleteMe._ham']) |                          ['CompleteMe._ham']) | ||||||
|         matches = self.completer.attr_matches('CompleteMe.__') |         matches = self.completer.attr_matches('CompleteMe.__') | ||||||
|         for x in matches: |         for x in matches: | ||||||
|             self.assertTrue(x.startswith('CompleteMe.__'), x) |             self.assertStartsWith(x, 'CompleteMe.__') | ||||||
|         self.assertIn('CompleteMe.__name__', matches) |         self.assertIn('CompleteMe.__name__', matches) | ||||||
|         self.assertIn('CompleteMe.__new__(', matches) |         self.assertIn('CompleteMe.__new__(', matches) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -796,7 +796,7 @@ def assertSigInt(self, cmd, *args, **kwargs): | ||||||
|         # Use -E to ignore PYTHONSAFEPATH |         # Use -E to ignore PYTHONSAFEPATH | ||||||
|         cmd = [sys.executable, '-E', *cmd] |         cmd = [sys.executable, '-E', *cmd] | ||||||
|         proc = subprocess.run(cmd, *args, **kwargs, text=True, stderr=subprocess.PIPE) |         proc = subprocess.run(cmd, *args, **kwargs, text=True, stderr=subprocess.PIPE) | ||||||
|         self.assertTrue(proc.stderr.endswith("\nKeyboardInterrupt\n"), proc.stderr) |         self.assertEndsWith(proc.stderr, "\nKeyboardInterrupt\n") | ||||||
|         self.assertEqual(proc.returncode, self.EXPECTED_CODE) |         self.assertEqual(proc.returncode, self.EXPECTED_CODE) | ||||||
| 
 | 
 | ||||||
|     def test_pymain_run_file(self): |     def test_pymain_run_file(self): | ||||||
|  |  | ||||||
|  | @ -778,7 +778,7 @@ class X: | ||||||
|         class X: |         class X: | ||||||
|             locals()["x"] = 43 |             locals()["x"] = 43 | ||||||
|             del x |             del x | ||||||
|         self.assertFalse(hasattr(X, "x")) |         self.assertNotHasAttr(X, "x") | ||||||
|         self.assertEqual(x, 42) |         self.assertEqual(x, 42) | ||||||
| 
 | 
 | ||||||
|     @cpython_only |     @cpython_only | ||||||
|  |  | ||||||
|  | @ -74,8 +74,7 @@ class TestScriptHelperEnvironment(unittest.TestCase): | ||||||
|     """Code coverage for interpreter_requires_environment().""" |     """Code coverage for interpreter_requires_environment().""" | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.assertTrue( |         self.assertHasAttr(script_helper, '__cached_interp_requires_environment') | ||||||
|             hasattr(script_helper, '__cached_interp_requires_environment')) |  | ||||||
|         # Reset the private cached state. |         # Reset the private cached state. | ||||||
|         script_helper.__dict__['__cached_interp_requires_environment'] = None |         script_helper.__dict__['__cached_interp_requires_environment'] = None | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -237,7 +237,7 @@ def test_pickling(self): | ||||||
|             if type(self.s) not in (set, frozenset): |             if type(self.s) not in (set, frozenset): | ||||||
|                 self.assertEqual(self.s.x, dup.x) |                 self.assertEqual(self.s.x, dup.x) | ||||||
|                 self.assertEqual(self.s.z, dup.z) |                 self.assertEqual(self.s.z, dup.z) | ||||||
|                 self.assertFalse(hasattr(self.s, 'y')) |                 self.assertNotHasAttr(self.s, 'y') | ||||||
|                 del self.s.x, self.s.z |                 del self.s.x, self.s.z | ||||||
| 
 | 
 | ||||||
|     def test_iterator_pickling(self): |     def test_iterator_pickling(self): | ||||||
|  | @ -876,8 +876,8 @@ def test_repr(self): | ||||||
| 
 | 
 | ||||||
|     def check_repr_against_values(self): |     def check_repr_against_values(self): | ||||||
|         text = repr(self.set) |         text = repr(self.set) | ||||||
|         self.assertTrue(text.startswith('{')) |         self.assertStartsWith(text, '{') | ||||||
|         self.assertTrue(text.endswith('}')) |         self.assertEndsWith(text, '}') | ||||||
| 
 | 
 | ||||||
|         result = text[1:-1].split(', ') |         result = text[1:-1].split(', ') | ||||||
|         result.sort() |         result.sort() | ||||||
|  |  | ||||||
|  | @ -427,12 +427,12 @@ def check_args_to_onerror(self, func, arg, exc): | ||||||
|             else: |             else: | ||||||
|                 self.assertIs(func, os.listdir) |                 self.assertIs(func, os.listdir) | ||||||
|                 self.assertIn(arg, [TESTFN, self.child_dir_path]) |                 self.assertIn(arg, [TESTFN, self.child_dir_path]) | ||||||
|             self.assertTrue(issubclass(exc[0], OSError)) |             self.assertIsSubclass(exc[0], OSError) | ||||||
|             self.errorState += 1 |             self.errorState += 1 | ||||||
|         else: |         else: | ||||||
|             self.assertEqual(func, os.rmdir) |             self.assertEqual(func, os.rmdir) | ||||||
|             self.assertEqual(arg, TESTFN) |             self.assertEqual(arg, TESTFN) | ||||||
|             self.assertTrue(issubclass(exc[0], OSError)) |             self.assertIsSubclass(exc[0], OSError) | ||||||
|             self.errorState = 3 |             self.errorState = 3 | ||||||
| 
 | 
 | ||||||
|     @unittest.skipIf(sys.platform[:6] == 'cygwin', |     @unittest.skipIf(sys.platform[:6] == 'cygwin', | ||||||
|  | @ -3479,7 +3479,7 @@ class PublicAPITests(unittest.TestCase): | ||||||
|     """Ensures that the correct values are exposed in the public API.""" |     """Ensures that the correct values are exposed in the public API.""" | ||||||
| 
 | 
 | ||||||
|     def test_module_all_attribute(self): |     def test_module_all_attribute(self): | ||||||
|         self.assertTrue(hasattr(shutil, '__all__')) |         self.assertHasAttr(shutil, '__all__') | ||||||
|         target_api = ['copyfileobj', 'copyfile', 'copymode', 'copystat', |         target_api = ['copyfileobj', 'copyfile', 'copymode', 'copystat', | ||||||
|                       'copy', 'copy2', 'copytree', 'move', 'rmtree', 'Error', |                       'copy', 'copy2', 'copytree', 'move', 'rmtree', 'Error', | ||||||
|                       'SpecialFileError', 'make_archive', |                       'SpecialFileError', 'make_archive', | ||||||
|  |  | ||||||
|  | @ -307,8 +307,7 @@ def test_getuserbase(self): | ||||||
| 
 | 
 | ||||||
|         with EnvironmentVarGuard() as environ: |         with EnvironmentVarGuard() as environ: | ||||||
|             environ['PYTHONUSERBASE'] = 'xoxo' |             environ['PYTHONUSERBASE'] = 'xoxo' | ||||||
|             self.assertTrue(site.getuserbase().startswith('xoxo'), |             self.assertStartsWith(site.getuserbase(), 'xoxo') | ||||||
|                             site.getuserbase()) |  | ||||||
| 
 | 
 | ||||||
|     @unittest.skipUnless(HAS_USER_SITE, 'need user site') |     @unittest.skipUnless(HAS_USER_SITE, 'need user site') | ||||||
|     def test_getusersitepackages(self): |     def test_getusersitepackages(self): | ||||||
|  | @ -318,7 +317,7 @@ def test_getusersitepackages(self): | ||||||
| 
 | 
 | ||||||
|         # the call sets USER_BASE *and* USER_SITE |         # the call sets USER_BASE *and* USER_SITE | ||||||
|         self.assertEqual(site.USER_SITE, user_site) |         self.assertEqual(site.USER_SITE, user_site) | ||||||
|         self.assertTrue(user_site.startswith(site.USER_BASE), user_site) |         self.assertStartsWith(user_site, site.USER_BASE) | ||||||
|         self.assertEqual(site.USER_BASE, site.getuserbase()) |         self.assertEqual(site.USER_BASE, site.getuserbase()) | ||||||
| 
 | 
 | ||||||
|     def test_getsitepackages(self): |     def test_getsitepackages(self): | ||||||
|  | @ -359,11 +358,10 @@ def test_no_home_directory(self): | ||||||
|             environ.unset('PYTHONUSERBASE', 'APPDATA') |             environ.unset('PYTHONUSERBASE', 'APPDATA') | ||||||
| 
 | 
 | ||||||
|             user_base = site.getuserbase() |             user_base = site.getuserbase() | ||||||
|             self.assertTrue(user_base.startswith('~' + os.sep), |             self.assertStartsWith(user_base, '~' + os.sep) | ||||||
|                             user_base) |  | ||||||
| 
 | 
 | ||||||
|             user_site = site.getusersitepackages() |             user_site = site.getusersitepackages() | ||||||
|             self.assertTrue(user_site.startswith(user_base), user_site) |             self.assertStartsWith(user_site, user_base) | ||||||
| 
 | 
 | ||||||
|         with mock.patch('os.path.isdir', return_value=False) as mock_isdir, \ |         with mock.patch('os.path.isdir', return_value=False) as mock_isdir, \ | ||||||
|              mock.patch.object(site, 'addsitedir') as mock_addsitedir, \ |              mock.patch.object(site, 'addsitedir') as mock_addsitedir, \ | ||||||
|  | @ -495,18 +493,18 @@ def test_add_build_dir(self): | ||||||
| 
 | 
 | ||||||
|     def test_setting_quit(self): |     def test_setting_quit(self): | ||||||
|         # 'quit' and 'exit' should be injected into builtins |         # 'quit' and 'exit' should be injected into builtins | ||||||
|         self.assertTrue(hasattr(builtins, "quit")) |         self.assertHasAttr(builtins, "quit") | ||||||
|         self.assertTrue(hasattr(builtins, "exit")) |         self.assertHasAttr(builtins, "exit") | ||||||
| 
 | 
 | ||||||
|     def test_setting_copyright(self): |     def test_setting_copyright(self): | ||||||
|         # 'copyright', 'credits', and 'license' should be in builtins |         # 'copyright', 'credits', and 'license' should be in builtins | ||||||
|         self.assertTrue(hasattr(builtins, "copyright")) |         self.assertHasAttr(builtins, "copyright") | ||||||
|         self.assertTrue(hasattr(builtins, "credits")) |         self.assertHasAttr(builtins, "credits") | ||||||
|         self.assertTrue(hasattr(builtins, "license")) |         self.assertHasAttr(builtins, "license") | ||||||
| 
 | 
 | ||||||
|     def test_setting_help(self): |     def test_setting_help(self): | ||||||
|         # 'help' should be set in builtins |         # 'help' should be set in builtins | ||||||
|         self.assertTrue(hasattr(builtins, "help")) |         self.assertHasAttr(builtins, "help") | ||||||
| 
 | 
 | ||||||
|     def test_sitecustomize_executed(self): |     def test_sitecustomize_executed(self): | ||||||
|         # If sitecustomize is available, it should have been imported. |         # If sitecustomize is available, it should have been imported. | ||||||
|  |  | ||||||
|  | @ -1085,9 +1085,7 @@ def test3542SocketOptions(self): | ||||||
|             'IPV6_USE_MIN_MTU', |             'IPV6_USE_MIN_MTU', | ||||||
|         } |         } | ||||||
|         for opt in opts: |         for opt in opts: | ||||||
|             self.assertTrue( |             self.assertHasAttr(socket, opt) | ||||||
|                 hasattr(socket, opt), f"Missing RFC3542 socket option '{opt}'" |  | ||||||
|             ) |  | ||||||
| 
 | 
 | ||||||
|     def testHostnameRes(self): |     def testHostnameRes(self): | ||||||
|         # Testing hostname resolution mechanisms |         # Testing hostname resolution mechanisms | ||||||
|  | @ -1593,11 +1591,11 @@ def test_getsockaddrarg(self): | ||||||
| 
 | 
 | ||||||
|     @unittest.skipUnless(os.name == "nt", "Windows specific") |     @unittest.skipUnless(os.name == "nt", "Windows specific") | ||||||
|     def test_sock_ioctl(self): |     def test_sock_ioctl(self): | ||||||
|         self.assertTrue(hasattr(socket.socket, 'ioctl')) |         self.assertHasAttr(socket.socket, 'ioctl') | ||||||
|         self.assertTrue(hasattr(socket, 'SIO_RCVALL')) |         self.assertHasAttr(socket, 'SIO_RCVALL') | ||||||
|         self.assertTrue(hasattr(socket, 'RCVALL_ON')) |         self.assertHasAttr(socket, 'RCVALL_ON') | ||||||
|         self.assertTrue(hasattr(socket, 'RCVALL_OFF')) |         self.assertHasAttr(socket, 'RCVALL_OFF') | ||||||
|         self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) |         self.assertHasAttr(socket, 'SIO_KEEPALIVE_VALS') | ||||||
|         s = socket.socket() |         s = socket.socket() | ||||||
|         self.addCleanup(s.close) |         self.addCleanup(s.close) | ||||||
|         self.assertRaises(ValueError, s.ioctl, -1, None) |         self.assertRaises(ValueError, s.ioctl, -1, None) | ||||||
|  | @ -6082,10 +6080,10 @@ def testTimeoutZero(self): | ||||||
| class TestExceptions(unittest.TestCase): | class TestExceptions(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def testExceptionTree(self): |     def testExceptionTree(self): | ||||||
|         self.assertTrue(issubclass(OSError, Exception)) |         self.assertIsSubclass(OSError, Exception) | ||||||
|         self.assertTrue(issubclass(socket.herror, OSError)) |         self.assertIsSubclass(socket.herror, OSError) | ||||||
|         self.assertTrue(issubclass(socket.gaierror, OSError)) |         self.assertIsSubclass(socket.gaierror, OSError) | ||||||
|         self.assertTrue(issubclass(socket.timeout, OSError)) |         self.assertIsSubclass(socket.timeout, OSError) | ||||||
|         self.assertIs(socket.error, OSError) |         self.assertIs(socket.error, OSError) | ||||||
|         self.assertIs(socket.timeout, TimeoutError) |         self.assertIs(socket.timeout, TimeoutError) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -145,8 +145,7 @@ def test_error_from_string(self): | ||||||
|             compile(input, "<string>", "exec") |             compile(input, "<string>", "exec") | ||||||
|         expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \ |         expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \ | ||||||
|                    "ordinal not in range(128)" |                    "ordinal not in range(128)" | ||||||
|         self.assertTrue(c.exception.args[0].startswith(expected), |         self.assertStartsWith(c.exception.args[0], expected) | ||||||
|                         msg=c.exception.args[0]) |  | ||||||
| 
 | 
 | ||||||
|     def test_file_parse_error_multiline(self): |     def test_file_parse_error_multiline(self): | ||||||
|         # gh96611: |         # gh96611: | ||||||
|  |  | ||||||
|  | @ -539,9 +539,9 @@ def test_openssl_version(self): | ||||||
|             openssl_ver = f"OpenSSL {major:d}.{minor:d}.{patch:d}" |             openssl_ver = f"OpenSSL {major:d}.{minor:d}.{patch:d}" | ||||||
|         else: |         else: | ||||||
|             openssl_ver = f"OpenSSL {major:d}.{minor:d}.{fix:d}" |             openssl_ver = f"OpenSSL {major:d}.{minor:d}.{fix:d}" | ||||||
|         self.assertTrue( |         self.assertStartsWith( | ||||||
|             s.startswith((openssl_ver, libressl_ver, "AWS-LC")), |             s, (openssl_ver, libressl_ver, "AWS-LC"), | ||||||
|             (s, t, hex(n)) |             (t, hex(n)) | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|     @support.cpython_only |     @support.cpython_only | ||||||
|  | @ -1668,7 +1668,7 @@ def test_lib_reason(self): | ||||||
|         regex = "(NO_START_LINE|UNSUPPORTED_PUBLIC_KEY_TYPE)" |         regex = "(NO_START_LINE|UNSUPPORTED_PUBLIC_KEY_TYPE)" | ||||||
|         self.assertRegex(cm.exception.reason, regex) |         self.assertRegex(cm.exception.reason, regex) | ||||||
|         s = str(cm.exception) |         s = str(cm.exception) | ||||||
|         self.assertTrue("NO_START_LINE" in s, s) |         self.assertIn("NO_START_LINE", s) | ||||||
| 
 | 
 | ||||||
|     def test_subclass(self): |     def test_subclass(self): | ||||||
|         # Check that the appropriate SSLError subclass is raised |         # Check that the appropriate SSLError subclass is raised | ||||||
|  | @ -1683,7 +1683,7 @@ def test_subclass(self): | ||||||
|                 with self.assertRaises(ssl.SSLWantReadError) as cm: |                 with self.assertRaises(ssl.SSLWantReadError) as cm: | ||||||
|                     c.do_handshake() |                     c.do_handshake() | ||||||
|                 s = str(cm.exception) |                 s = str(cm.exception) | ||||||
|                 self.assertTrue(s.startswith("The operation did not complete (read)"), s) |                 self.assertStartsWith(s, "The operation did not complete (read)") | ||||||
|                 # For compatibility |                 # For compatibility | ||||||
|                 self.assertEqual(cm.exception.errno, ssl.SSL_ERROR_WANT_READ) |                 self.assertEqual(cm.exception.errno, ssl.SSL_ERROR_WANT_READ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -157,7 +157,7 @@ def test_mode(self): | ||||||
| 
 | 
 | ||||||
|             os.chmod(TESTFN, 0o700) |             os.chmod(TESTFN, 0o700) | ||||||
|             st_mode, modestr = self.get_mode() |             st_mode, modestr = self.get_mode() | ||||||
|             self.assertEqual(modestr[:3], '-rw') |             self.assertStartsWith(modestr, '-rw') | ||||||
|             self.assertS_IS("REG", st_mode) |             self.assertS_IS("REG", st_mode) | ||||||
|             self.assertEqual(self.statmod.S_IFMT(st_mode), |             self.assertEqual(self.statmod.S_IFMT(st_mode), | ||||||
|                              self.statmod.S_IFREG) |                              self.statmod.S_IFREG) | ||||||
|  | @ -256,7 +256,7 @@ def test_flags_consistent(self): | ||||||
|                          "FILE_ATTRIBUTE_* constants are Win32 specific") |                          "FILE_ATTRIBUTE_* constants are Win32 specific") | ||||||
|     def test_file_attribute_constants(self): |     def test_file_attribute_constants(self): | ||||||
|         for key, value in sorted(self.file_attributes.items()): |         for key, value in sorted(self.file_attributes.items()): | ||||||
|             self.assertTrue(hasattr(self.statmod, key), key) |             self.assertHasAttr(self.statmod, key) | ||||||
|             modvalue = getattr(self.statmod, key) |             modvalue = getattr(self.statmod, key) | ||||||
|             self.assertEqual(value, modvalue, key) |             self.assertEqual(value, modvalue, key) | ||||||
| 
 | 
 | ||||||
|  | @ -314,7 +314,7 @@ def test_macosx_attribute_values(self): | ||||||
|         self.assertEqual(self.statmod.S_ISGID, 0o002000) |         self.assertEqual(self.statmod.S_ISGID, 0o002000) | ||||||
|         self.assertEqual(self.statmod.S_ISVTX, 0o001000) |         self.assertEqual(self.statmod.S_ISVTX, 0o001000) | ||||||
| 
 | 
 | ||||||
|         self.assertFalse(hasattr(self.statmod, "S_ISTXT")) |         self.assertNotHasAttr(self.statmod, "S_ISTXT") | ||||||
|         self.assertEqual(self.statmod.S_IREAD, self.statmod.S_IRUSR) |         self.assertEqual(self.statmod.S_IREAD, self.statmod.S_IRUSR) | ||||||
|         self.assertEqual(self.statmod.S_IWRITE, self.statmod.S_IWUSR) |         self.assertEqual(self.statmod.S_IWRITE, self.statmod.S_IWUSR) | ||||||
|         self.assertEqual(self.statmod.S_IEXEC, self.statmod.S_IXUSR) |         self.assertEqual(self.statmod.S_IEXEC, self.statmod.S_IXUSR) | ||||||
|  |  | ||||||
|  | @ -645,7 +645,7 @@ def do_test(self, args): | ||||||
| 
 | 
 | ||||||
|     def test_numerictestcase_is_testcase(self): |     def test_numerictestcase_is_testcase(self): | ||||||
|         # Ensure that NumericTestCase actually is a TestCase. |         # Ensure that NumericTestCase actually is a TestCase. | ||||||
|         self.assertTrue(issubclass(NumericTestCase, unittest.TestCase)) |         self.assertIsSubclass(NumericTestCase, unittest.TestCase) | ||||||
| 
 | 
 | ||||||
|     def test_error_msg_numeric(self): |     def test_error_msg_numeric(self): | ||||||
|         # Test the error message generated for numeric comparisons. |         # Test the error message generated for numeric comparisons. | ||||||
|  | @ -683,32 +683,23 @@ class GlobalsTest(unittest.TestCase): | ||||||
|     def test_meta(self): |     def test_meta(self): | ||||||
|         # Test for the existence of metadata. |         # Test for the existence of metadata. | ||||||
|         for meta in self.expected_metadata: |         for meta in self.expected_metadata: | ||||||
|             self.assertTrue(hasattr(self.module, meta), |             self.assertHasAttr(self.module, meta) | ||||||
|                             "%s not present" % meta) |  | ||||||
| 
 | 
 | ||||||
|     def test_check_all(self): |     def test_check_all(self): | ||||||
|         # Check everything in __all__ exists and is public. |         # Check everything in __all__ exists and is public. | ||||||
|         module = self.module |         module = self.module | ||||||
|         for name in module.__all__: |         for name in module.__all__: | ||||||
|             # No private names in __all__: |             # No private names in __all__: | ||||||
|             self.assertFalse(name.startswith("_"), |             self.assertNotStartsWith(name, "_", | ||||||
|                              'private name "%s" in __all__' % name) |                              'private name "%s" in __all__' % name) | ||||||
|             # And anything in __all__ must exist: |             # And anything in __all__ must exist: | ||||||
|             self.assertTrue(hasattr(module, name), |             self.assertHasAttr(module, name) | ||||||
|                             'missing name "%s" in __all__' % name) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class StatisticsErrorTest(unittest.TestCase): | class StatisticsErrorTest(unittest.TestCase): | ||||||
|     def test_has_exception(self): |     def test_has_exception(self): | ||||||
|         errmsg = ( |         self.assertHasAttr(statistics, 'StatisticsError') | ||||||
|                 "Expected StatisticsError to be a ValueError, but got a" |         self.assertIsSubclass(statistics.StatisticsError, ValueError) | ||||||
|                 " subclass of %r instead." |  | ||||||
|                 ) |  | ||||||
|         self.assertTrue(hasattr(statistics, 'StatisticsError')) |  | ||||||
|         self.assertTrue( |  | ||||||
|                 issubclass(statistics.StatisticsError, ValueError), |  | ||||||
|                 errmsg % statistics.StatisticsError.__base__ |  | ||||||
|                 ) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # === Tests for private utility functions === | # === Tests for private utility functions === | ||||||
|  |  | ||||||
|  | @ -42,7 +42,7 @@ def test_repr(self): | ||||||
|         # os.stat() gives a complicated struct sequence. |         # os.stat() gives a complicated struct sequence. | ||||||
|         st = os.stat(__file__) |         st = os.stat(__file__) | ||||||
|         rep = repr(st) |         rep = repr(st) | ||||||
|         self.assertTrue(rep.startswith("os.stat_result")) |         self.assertStartsWith(rep, "os.stat_result") | ||||||
|         self.assertIn("st_mode=", rep) |         self.assertIn("st_mode=", rep) | ||||||
|         self.assertIn("st_ino=", rep) |         self.assertIn("st_ino=", rep) | ||||||
|         self.assertIn("st_dev=", rep) |         self.assertIn("st_dev=", rep) | ||||||
|  | @ -307,7 +307,7 @@ def test_copy_replace_with_invisible_fields(self): | ||||||
|         self.assertEqual(t5.tm_mon, 2) |         self.assertEqual(t5.tm_mon, 2) | ||||||
| 
 | 
 | ||||||
|         # named invisible fields |         # named invisible fields | ||||||
|         self.assertTrue(hasattr(t, 'tm_zone'), f"{t} has no attribute 'tm_zone'") |         self.assertHasAttr(t, 'tm_zone') | ||||||
|         with self.assertRaisesRegex(AttributeError, 'readonly attribute'): |         with self.assertRaisesRegex(AttributeError, 'readonly attribute'): | ||||||
|             t.tm_zone = 'some other zone' |             t.tm_zone = 'some other zone' | ||||||
|         self.assertEqual(t2.tm_zone, t.tm_zone) |         self.assertEqual(t2.tm_zone, t.tm_zone) | ||||||
|  |  | ||||||
|  | @ -1178,7 +1178,7 @@ def test_universal_newlines_communicate_stdin_stdout_stderr(self): | ||||||
|         self.assertEqual("line1\nline2\nline3\nline4\nline5\n", stdout) |         self.assertEqual("line1\nline2\nline3\nline4\nline5\n", stdout) | ||||||
|         # Python debug build push something like "[42442 refs]\n" |         # Python debug build push something like "[42442 refs]\n" | ||||||
|         # to stderr at exit of subprocess. |         # to stderr at exit of subprocess. | ||||||
|         self.assertTrue(stderr.startswith("eline2\neline6\neline7\n")) |         self.assertStartsWith(stderr, "eline2\neline6\neline7\n") | ||||||
| 
 | 
 | ||||||
|     def test_universal_newlines_communicate_encodings(self): |     def test_universal_newlines_communicate_encodings(self): | ||||||
|         # Check that universal newlines mode works for various encodings, |         # Check that universal newlines mode works for various encodings, | ||||||
|  | @ -1510,7 +1510,7 @@ def test_issue8780(self): | ||||||
|                 "[sys.executable, '-c', 'print(\"Hello World!\")'])", |                 "[sys.executable, '-c', 'print(\"Hello World!\")'])", | ||||||
|             'assert retcode == 0')) |             'assert retcode == 0')) | ||||||
|         output = subprocess.check_output([sys.executable, '-c', code]) |         output = subprocess.check_output([sys.executable, '-c', code]) | ||||||
|         self.assertTrue(output.startswith(b'Hello World!'), ascii(output)) |         self.assertStartsWith(output, b'Hello World!') | ||||||
| 
 | 
 | ||||||
|     def test_handles_closed_on_exception(self): |     def test_handles_closed_on_exception(self): | ||||||
|         # If CreateProcess exits with an error, ensure the |         # If CreateProcess exits with an error, ensure the | ||||||
|  | @ -1835,8 +1835,8 @@ def test_encoding_warning(self): | ||||||
|                             capture_output=True) |                             capture_output=True) | ||||||
|         lines = cp.stderr.splitlines() |         lines = cp.stderr.splitlines() | ||||||
|         self.assertEqual(len(lines), 2, lines) |         self.assertEqual(len(lines), 2, lines) | ||||||
|         self.assertTrue(lines[0].startswith(b"<string>:2: EncodingWarning: ")) |         self.assertStartsWith(lines[0], b"<string>:2: EncodingWarning: ") | ||||||
|         self.assertTrue(lines[1].startswith(b"<string>:3: EncodingWarning: ")) |         self.assertStartsWith(lines[1], b"<string>:3: EncodingWarning: ") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _get_test_grp_name(): | def _get_test_grp_name(): | ||||||
|  |  | ||||||
|  | @ -547,11 +547,11 @@ def test_special_methods(self): | ||||||
|             self.assertEqual(s.__reduce__, e.__reduce__) |             self.assertEqual(s.__reduce__, e.__reduce__) | ||||||
|             self.assertEqual(s.__reduce_ex__, e.__reduce_ex__) |             self.assertEqual(s.__reduce_ex__, e.__reduce_ex__) | ||||||
|             self.assertEqual(s.__getstate__, e.__getstate__) |             self.assertEqual(s.__getstate__, e.__getstate__) | ||||||
|             self.assertFalse(hasattr(s, '__getnewargs__')) |             self.assertNotHasAttr(s, '__getnewargs__') | ||||||
|             self.assertFalse(hasattr(s, '__getnewargs_ex__')) |             self.assertNotHasAttr(s, '__getnewargs_ex__') | ||||||
|             self.assertFalse(hasattr(s, '__setstate__')) |             self.assertNotHasAttr(s, '__setstate__') | ||||||
|             self.assertFalse(hasattr(s, '__copy__')) |             self.assertNotHasAttr(s, '__copy__') | ||||||
|             self.assertFalse(hasattr(s, '__deepcopy__')) |             self.assertNotHasAttr(s, '__deepcopy__') | ||||||
| 
 | 
 | ||||||
|     def test_pickling(self): |     def test_pickling(self): | ||||||
|         e = E() |         e = E() | ||||||
|  |  | ||||||
|  | @ -407,10 +407,10 @@ class Obj: | ||||||
|         with support.swap_attr(obj, "y", 5) as y: |         with support.swap_attr(obj, "y", 5) as y: | ||||||
|             self.assertEqual(obj.y, 5) |             self.assertEqual(obj.y, 5) | ||||||
|             self.assertIsNone(y) |             self.assertIsNone(y) | ||||||
|         self.assertFalse(hasattr(obj, 'y')) |         self.assertNotHasAttr(obj, 'y') | ||||||
|         with support.swap_attr(obj, "y", 5): |         with support.swap_attr(obj, "y", 5): | ||||||
|             del obj.y |             del obj.y | ||||||
|         self.assertFalse(hasattr(obj, 'y')) |         self.assertNotHasAttr(obj, 'y') | ||||||
| 
 | 
 | ||||||
|     def test_swap_item(self): |     def test_swap_item(self): | ||||||
|         D = {"x":1} |         D = {"x":1} | ||||||
|  |  | ||||||
|  | @ -57,7 +57,7 @@ def test_original_displayhook(self): | ||||||
|             dh(None) |             dh(None) | ||||||
| 
 | 
 | ||||||
|         self.assertEqual(out.getvalue(), "") |         self.assertEqual(out.getvalue(), "") | ||||||
|         self.assertTrue(not hasattr(builtins, "_")) |         self.assertNotHasAttr(builtins, "_") | ||||||
| 
 | 
 | ||||||
|         # sys.displayhook() requires arguments |         # sys.displayhook() requires arguments | ||||||
|         self.assertRaises(TypeError, dh) |         self.assertRaises(TypeError, dh) | ||||||
|  | @ -172,7 +172,7 @@ def test_original_excepthook(self): | ||||||
|             with support.captured_stderr() as err: |             with support.captured_stderr() as err: | ||||||
|                 sys.__excepthook__(*sys.exc_info()) |                 sys.__excepthook__(*sys.exc_info()) | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(err.getvalue().endswith("ValueError: 42\n")) |         self.assertEndsWith(err.getvalue(), "ValueError: 42\n") | ||||||
| 
 | 
 | ||||||
|         self.assertRaises(TypeError, sys.__excepthook__) |         self.assertRaises(TypeError, sys.__excepthook__) | ||||||
| 
 | 
 | ||||||
|  | @ -192,7 +192,7 @@ def test_excepthook_bytes_filename(self): | ||||||
|         err = err.getvalue() |         err = err.getvalue() | ||||||
|         self.assertIn("""  File "b'bytes_filename'", line 123\n""", err) |         self.assertIn("""  File "b'bytes_filename'", line 123\n""", err) | ||||||
|         self.assertIn("""    text\n""", err) |         self.assertIn("""    text\n""", err) | ||||||
|         self.assertTrue(err.endswith("SyntaxError: msg\n")) |         self.assertEndsWith(err, "SyntaxError: msg\n") | ||||||
| 
 | 
 | ||||||
|     def test_excepthook(self): |     def test_excepthook(self): | ||||||
|         with test.support.captured_output("stderr") as stderr: |         with test.support.captured_output("stderr") as stderr: | ||||||
|  | @ -269,8 +269,7 @@ def check_exit_message(code, expected, **env_vars): | ||||||
|             rc, out, err = assert_python_failure('-c', code, **env_vars) |             rc, out, err = assert_python_failure('-c', code, **env_vars) | ||||||
|             self.assertEqual(rc, 1) |             self.assertEqual(rc, 1) | ||||||
|             self.assertEqual(out, b'') |             self.assertEqual(out, b'') | ||||||
|             self.assertTrue(err.startswith(expected), |             self.assertStartsWith(err, expected) | ||||||
|                 "%s doesn't start with %s" % (ascii(err), ascii(expected))) |  | ||||||
| 
 | 
 | ||||||
|         # test that stderr buffer is flushed before the exit message is written |         # test that stderr buffer is flushed before the exit message is written | ||||||
|         # into stderr |         # into stderr | ||||||
|  | @ -437,7 +436,7 @@ def test_call_tracing(self): | ||||||
|     @unittest.skipUnless(hasattr(sys, "setdlopenflags"), |     @unittest.skipUnless(hasattr(sys, "setdlopenflags"), | ||||||
|                          'test needs sys.setdlopenflags()') |                          'test needs sys.setdlopenflags()') | ||||||
|     def test_dlopenflags(self): |     def test_dlopenflags(self): | ||||||
|         self.assertTrue(hasattr(sys, "getdlopenflags")) |         self.assertHasAttr(sys, "getdlopenflags") | ||||||
|         self.assertRaises(TypeError, sys.getdlopenflags, 42) |         self.assertRaises(TypeError, sys.getdlopenflags, 42) | ||||||
|         oldflags = sys.getdlopenflags() |         oldflags = sys.getdlopenflags() | ||||||
|         self.assertRaises(TypeError, sys.setdlopenflags) |         self.assertRaises(TypeError, sys.setdlopenflags) | ||||||
|  | @ -623,8 +622,7 @@ def g456(): | ||||||
|             # And the next record must be for g456(). |             # And the next record must be for g456(). | ||||||
|             filename, lineno, funcname, sourceline = stack[i+1] |             filename, lineno, funcname, sourceline = stack[i+1] | ||||||
|             self.assertEqual(funcname, "g456") |             self.assertEqual(funcname, "g456") | ||||||
|             self.assertTrue((sourceline.startswith("if leave_g.wait(") or |             self.assertStartsWith(sourceline, ("if leave_g.wait(", "g_raised.set()")) | ||||||
|                              sourceline.startswith("g_raised.set()"))) |  | ||||||
|         finally: |         finally: | ||||||
|             # Reap the spawned thread. |             # Reap the spawned thread. | ||||||
|             leave_g.set() |             leave_g.set() | ||||||
|  | @ -860,7 +858,7 @@ def test_sys_flags(self): | ||||||
|                  "hash_randomization", "isolated", "dev_mode", "utf8_mode", |                  "hash_randomization", "isolated", "dev_mode", "utf8_mode", | ||||||
|                  "warn_default_encoding", "safe_path", "int_max_str_digits") |                  "warn_default_encoding", "safe_path", "int_max_str_digits") | ||||||
|         for attr in attrs: |         for attr in attrs: | ||||||
|             self.assertTrue(hasattr(sys.flags, attr), attr) |             self.assertHasAttr(sys.flags, attr) | ||||||
|             attr_type = bool if attr in ("dev_mode", "safe_path") else int |             attr_type = bool if attr in ("dev_mode", "safe_path") else int | ||||||
|             self.assertEqual(type(getattr(sys.flags, attr)), attr_type, attr) |             self.assertEqual(type(getattr(sys.flags, attr)), attr_type, attr) | ||||||
|         self.assertTrue(repr(sys.flags)) |         self.assertTrue(repr(sys.flags)) | ||||||
|  | @ -1072,10 +1070,10 @@ def test_implementation(self): | ||||||
| 
 | 
 | ||||||
|         levels = {'alpha': 0xA, 'beta': 0xB, 'candidate': 0xC, 'final': 0xF} |         levels = {'alpha': 0xA, 'beta': 0xB, 'candidate': 0xC, 'final': 0xF} | ||||||
| 
 | 
 | ||||||
|         self.assertTrue(hasattr(sys.implementation, 'name')) |         self.assertHasAttr(sys.implementation, 'name') | ||||||
|         self.assertTrue(hasattr(sys.implementation, 'version')) |         self.assertHasAttr(sys.implementation, 'version') | ||||||
|         self.assertTrue(hasattr(sys.implementation, 'hexversion')) |         self.assertHasAttr(sys.implementation, 'hexversion') | ||||||
|         self.assertTrue(hasattr(sys.implementation, 'cache_tag')) |         self.assertHasAttr(sys.implementation, 'cache_tag') | ||||||
| 
 | 
 | ||||||
|         version = sys.implementation.version |         version = sys.implementation.version | ||||||
|         self.assertEqual(version[:2], (version.major, version.minor)) |         self.assertEqual(version[:2], (version.major, version.minor)) | ||||||
|  | @ -1419,7 +1417,7 @@ def __del__(self): | ||||||
|                 else: |                 else: | ||||||
|                     self.assertIn("ValueError", report) |                     self.assertIn("ValueError", report) | ||||||
|                     self.assertIn("del is broken", report) |                     self.assertIn("del is broken", report) | ||||||
|                 self.assertTrue(report.endswith("\n")) |                 self.assertEndsWith(report, "\n") | ||||||
| 
 | 
 | ||||||
|     def test_original_unraisablehook_exception_qualname(self): |     def test_original_unraisablehook_exception_qualname(self): | ||||||
|         # See bpo-41031, bpo-45083. |         # See bpo-41031, bpo-45083. | ||||||
|  |  | ||||||
|  | @ -186,7 +186,7 @@ def test_posix_venv_scheme(self): | ||||||
|         # The include directory on POSIX isn't exactly the same as before, |         # The include directory on POSIX isn't exactly the same as before, | ||||||
|         # but it is "within" |         # but it is "within" | ||||||
|         sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv', vars=vars) |         sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv', vars=vars) | ||||||
|         self.assertTrue(sysconfig_includedir.startswith(incpath + os.sep)) |         self.assertStartsWith(sysconfig_includedir, incpath + os.sep) | ||||||
| 
 | 
 | ||||||
|     def test_nt_venv_scheme(self): |     def test_nt_venv_scheme(self): | ||||||
|         # The following directories were hardcoded in the venv module |         # The following directories were hardcoded in the venv module | ||||||
|  | @ -569,8 +569,7 @@ def test_linux_ext_suffix(self): | ||||||
|                 expected_suffixes = 'i386-linux-gnu.so', 'x86_64-linux-gnux32.so', 'i386-linux-musl.so' |                 expected_suffixes = 'i386-linux-gnu.so', 'x86_64-linux-gnux32.so', 'i386-linux-musl.so' | ||||||
|             else: # 8 byte pointer size |             else: # 8 byte pointer size | ||||||
|                 expected_suffixes = 'x86_64-linux-gnu.so', 'x86_64-linux-musl.so' |                 expected_suffixes = 'x86_64-linux-gnu.so', 'x86_64-linux-musl.so' | ||||||
|             self.assertTrue(suffix.endswith(expected_suffixes), |             self.assertEndsWith(suffix, expected_suffixes) | ||||||
|                             f'unexpected suffix {suffix!r}') |  | ||||||
| 
 | 
 | ||||||
|     @unittest.skipUnless(sys.platform == 'android', 'Android-specific test') |     @unittest.skipUnless(sys.platform == 'android', 'Android-specific test') | ||||||
|     def test_android_ext_suffix(self): |     def test_android_ext_suffix(self): | ||||||
|  | @ -582,13 +581,12 @@ def test_android_ext_suffix(self): | ||||||
|             "aarch64": "aarch64-linux-android", |             "aarch64": "aarch64-linux-android", | ||||||
|             "armv7l": "arm-linux-androideabi", |             "armv7l": "arm-linux-androideabi", | ||||||
|         }[machine] |         }[machine] | ||||||
|         self.assertTrue(suffix.endswith(f"-{expected_triplet}.so"), |         self.assertEndsWith(suffix, f"-{expected_triplet}.so") | ||||||
|                         f"{machine=}, {suffix=}") |  | ||||||
| 
 | 
 | ||||||
|     @unittest.skipUnless(sys.platform == 'darwin', 'OS X-specific test') |     @unittest.skipUnless(sys.platform == 'darwin', 'OS X-specific test') | ||||||
|     def test_osx_ext_suffix(self): |     def test_osx_ext_suffix(self): | ||||||
|         suffix = sysconfig.get_config_var('EXT_SUFFIX') |         suffix = sysconfig.get_config_var('EXT_SUFFIX') | ||||||
|         self.assertTrue(suffix.endswith('-darwin.so'), suffix) |         self.assertEndsWith(suffix, '-darwin.so') | ||||||
| 
 | 
 | ||||||
|     def test_always_set_py_debug(self): |     def test_always_set_py_debug(self): | ||||||
|         self.assertIn('Py_DEBUG', sysconfig.get_config_vars()) |         self.assertIn('Py_DEBUG', sysconfig.get_config_vars()) | ||||||
|  |  | ||||||
|  | @ -1650,7 +1650,7 @@ def test_cwd(self): | ||||||
|             try: |             try: | ||||||
|                 for t in tar: |                 for t in tar: | ||||||
|                     if t.name != ".": |                     if t.name != ".": | ||||||
|                         self.assertTrue(t.name.startswith("./"), t.name) |                         self.assertStartsWith(t.name, "./") | ||||||
|             finally: |             finally: | ||||||
|                 tar.close() |                 tar.close() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -516,11 +516,11 @@ def test_collision_with_existing_file(self): | ||||||
|              _mock_candidate_names('aaa', 'aaa', 'bbb'): |              _mock_candidate_names('aaa', 'aaa', 'bbb'): | ||||||
|             (fd1, name1) = self.make_temp() |             (fd1, name1) = self.make_temp() | ||||||
|             os.close(fd1) |             os.close(fd1) | ||||||
|             self.assertTrue(name1.endswith('aaa')) |             self.assertEndsWith(name1, 'aaa') | ||||||
| 
 | 
 | ||||||
|             (fd2, name2) = self.make_temp() |             (fd2, name2) = self.make_temp() | ||||||
|             os.close(fd2) |             os.close(fd2) | ||||||
|             self.assertTrue(name2.endswith('bbb')) |             self.assertEndsWith(name2, 'bbb') | ||||||
| 
 | 
 | ||||||
|     def test_collision_with_existing_directory(self): |     def test_collision_with_existing_directory(self): | ||||||
|         # _mkstemp_inner tries another name when a directory with |         # _mkstemp_inner tries another name when a directory with | ||||||
|  | @ -528,11 +528,11 @@ def test_collision_with_existing_directory(self): | ||||||
|         with _inside_empty_temp_dir(), \ |         with _inside_empty_temp_dir(), \ | ||||||
|              _mock_candidate_names('aaa', 'aaa', 'bbb'): |              _mock_candidate_names('aaa', 'aaa', 'bbb'): | ||||||
|             dir = tempfile.mkdtemp() |             dir = tempfile.mkdtemp() | ||||||
|             self.assertTrue(dir.endswith('aaa')) |             self.assertEndsWith(dir, 'aaa') | ||||||
| 
 | 
 | ||||||
|             (fd, name) = self.make_temp() |             (fd, name) = self.make_temp() | ||||||
|             os.close(fd) |             os.close(fd) | ||||||
|             self.assertTrue(name.endswith('bbb')) |             self.assertEndsWith(name, 'bbb') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestGetTempPrefix(BaseTestCase): | class TestGetTempPrefix(BaseTestCase): | ||||||
|  | @ -828,9 +828,9 @@ def test_collision_with_existing_file(self): | ||||||
|              _mock_candidate_names('aaa', 'aaa', 'bbb'): |              _mock_candidate_names('aaa', 'aaa', 'bbb'): | ||||||
|             file = tempfile.NamedTemporaryFile(delete=False) |             file = tempfile.NamedTemporaryFile(delete=False) | ||||||
|             file.close() |             file.close() | ||||||
|             self.assertTrue(file.name.endswith('aaa')) |             self.assertEndsWith(file.name, 'aaa') | ||||||
|             dir = tempfile.mkdtemp() |             dir = tempfile.mkdtemp() | ||||||
|             self.assertTrue(dir.endswith('bbb')) |             self.assertEndsWith(dir, 'bbb') | ||||||
| 
 | 
 | ||||||
|     def test_collision_with_existing_directory(self): |     def test_collision_with_existing_directory(self): | ||||||
|         # mkdtemp tries another name when a directory with |         # mkdtemp tries another name when a directory with | ||||||
|  | @ -838,9 +838,9 @@ def test_collision_with_existing_directory(self): | ||||||
|         with _inside_empty_temp_dir(), \ |         with _inside_empty_temp_dir(), \ | ||||||
|              _mock_candidate_names('aaa', 'aaa', 'bbb'): |              _mock_candidate_names('aaa', 'aaa', 'bbb'): | ||||||
|             dir1 = tempfile.mkdtemp() |             dir1 = tempfile.mkdtemp() | ||||||
|             self.assertTrue(dir1.endswith('aaa')) |             self.assertEndsWith(dir1, 'aaa') | ||||||
|             dir2 = tempfile.mkdtemp() |             dir2 = tempfile.mkdtemp() | ||||||
|             self.assertTrue(dir2.endswith('bbb')) |             self.assertEndsWith(dir2, 'bbb') | ||||||
| 
 | 
 | ||||||
|     def test_for_tempdir_is_bytes_issue40701_api_warts(self): |     def test_for_tempdir_is_bytes_issue40701_api_warts(self): | ||||||
|         orig_tempdir = tempfile.tempdir |         orig_tempdir = tempfile.tempdir | ||||||
|  |  | ||||||
|  | @ -290,8 +290,8 @@ def test_ioctl_constants(self): | ||||||
|                 self.assertGreaterEqual(value, 0) |                 self.assertGreaterEqual(value, 0) | ||||||
| 
 | 
 | ||||||
|     def test_exception(self): |     def test_exception(self): | ||||||
|         self.assertTrue(issubclass(termios.error, Exception)) |         self.assertIsSubclass(termios.error, Exception) | ||||||
|         self.assertFalse(issubclass(termios.error, OSError)) |         self.assertNotIsSubclass(termios.error, OSError) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|  |  | ||||||
|  | @ -761,17 +761,17 @@ def test_localtime_timezone(self): | ||||||
| 
 | 
 | ||||||
|         # Get the localtime and examine it for the offset and zone. |         # Get the localtime and examine it for the offset and zone. | ||||||
|         lt = time.localtime() |         lt = time.localtime() | ||||||
|         self.assertTrue(hasattr(lt, "tm_gmtoff")) |         self.assertHasAttr(lt, "tm_gmtoff") | ||||||
|         self.assertTrue(hasattr(lt, "tm_zone")) |         self.assertHasAttr(lt, "tm_zone") | ||||||
| 
 | 
 | ||||||
|         # See if the offset and zone are similar to the module |         # See if the offset and zone are similar to the module | ||||||
|         # attributes. |         # attributes. | ||||||
|         if lt.tm_gmtoff is None: |         if lt.tm_gmtoff is None: | ||||||
|             self.assertTrue(not hasattr(time, "timezone")) |             self.assertNotHasAttr(time, "timezone") | ||||||
|         else: |         else: | ||||||
|             self.assertEqual(lt.tm_gmtoff, -[time.timezone, time.altzone][lt.tm_isdst]) |             self.assertEqual(lt.tm_gmtoff, -[time.timezone, time.altzone][lt.tm_isdst]) | ||||||
|         if lt.tm_zone is None: |         if lt.tm_zone is None: | ||||||
|             self.assertTrue(not hasattr(time, "tzname")) |             self.assertNotHasAttr(time, "tzname") | ||||||
|         else: |         else: | ||||||
|             self.assertEqual(lt.tm_zone, time.tzname[lt.tm_isdst]) |             self.assertEqual(lt.tm_zone, time.tzname[lt.tm_isdst]) | ||||||
| 
 | 
 | ||||||
|  | @ -1184,11 +1184,11 @@ def test_clock_functions(self): | ||||||
| 
 | 
 | ||||||
|         if mac_ver >= (10, 12): |         if mac_ver >= (10, 12): | ||||||
|             for name in clock_names: |             for name in clock_names: | ||||||
|                 self.assertTrue(hasattr(time, name), f"time.{name} is not available") |                 self.assertHasAttr(time, name) | ||||||
| 
 | 
 | ||||||
|         else: |         else: | ||||||
|             for name in clock_names: |             for name in clock_names: | ||||||
|                 self.assertFalse(hasattr(time, name), f"time.{name} is available") |                 self.assertNotHasAttr(time, name) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|  |  | ||||||
|  | @ -222,8 +222,8 @@ def test_repeat_function_zero_iters(self): | ||||||
|     def assert_exc_string(self, exc_string, expected_exc_name): |     def assert_exc_string(self, exc_string, expected_exc_name): | ||||||
|         exc_lines = exc_string.splitlines() |         exc_lines = exc_string.splitlines() | ||||||
|         self.assertGreater(len(exc_lines), 2) |         self.assertGreater(len(exc_lines), 2) | ||||||
|         self.assertTrue(exc_lines[0].startswith('Traceback')) |         self.assertStartsWith(exc_lines[0], 'Traceback') | ||||||
|         self.assertTrue(exc_lines[-1].startswith(expected_exc_name)) |         self.assertStartsWith(exc_lines[-1], expected_exc_name) | ||||||
| 
 | 
 | ||||||
|     def test_print_exc(self): |     def test_print_exc(self): | ||||||
|         s = io.StringIO() |         s = io.StringIO() | ||||||
|  |  | ||||||
|  | @ -58,7 +58,7 @@ def _test_widget(self, constructor): | ||||||
|         destroy_default_root() |         destroy_default_root() | ||||||
|         tkinter.NoDefaultRoot() |         tkinter.NoDefaultRoot() | ||||||
|         self.assertRaises(RuntimeError, constructor) |         self.assertRaises(RuntimeError, constructor) | ||||||
|         self.assertFalse(hasattr(tkinter, '_default_root')) |         self.assertNotHasAttr(tkinter, '_default_root') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def destroy_default_root(): | def destroy_default_root(): | ||||||
|  |  | ||||||
|  | @ -497,7 +497,7 @@ def test_info_patchlevel(self): | ||||||
|             self.assertEqual(vi.serial, 0) |             self.assertEqual(vi.serial, 0) | ||||||
|         else: |         else: | ||||||
|             self.assertEqual(vi.micro, 0) |             self.assertEqual(vi.micro, 0) | ||||||
|         self.assertTrue(str(vi).startswith(f'{vi.major}.{vi.minor}')) |         self.assertStartsWith(str(vi), f'{vi.major}.{vi.minor}') | ||||||
| 
 | 
 | ||||||
|     def test_embedded_null(self): |     def test_embedded_null(self): | ||||||
|         widget = tkinter.Entry(self.root) |         widget = tkinter.Entry(self.root) | ||||||
|  | @ -609,7 +609,7 @@ def test_focus(self): | ||||||
|         self.assertIsInstance(e.serial, int) |         self.assertIsInstance(e.serial, int) | ||||||
|         self.assertEqual(e.time, '??') |         self.assertEqual(e.time, '??') | ||||||
|         self.assertIs(e.send_event, False) |         self.assertIs(e.send_event, False) | ||||||
|         self.assertFalse(hasattr(e, 'focus')) |         self.assertNotHasAttr(e, 'focus') | ||||||
|         self.assertEqual(e.num, '??') |         self.assertEqual(e.num, '??') | ||||||
|         self.assertEqual(e.state, '??') |         self.assertEqual(e.state, '??') | ||||||
|         self.assertEqual(e.char, '??') |         self.assertEqual(e.char, '??') | ||||||
|  | @ -642,7 +642,7 @@ def test_configure(self): | ||||||
|         self.assertIsInstance(e.serial, int) |         self.assertIsInstance(e.serial, int) | ||||||
|         self.assertEqual(e.time, '??') |         self.assertEqual(e.time, '??') | ||||||
|         self.assertIs(e.send_event, False) |         self.assertIs(e.send_event, False) | ||||||
|         self.assertFalse(hasattr(e, 'focus')) |         self.assertNotHasAttr(e, 'focus') | ||||||
|         self.assertEqual(e.num, '??') |         self.assertEqual(e.num, '??') | ||||||
|         self.assertEqual(e.state, '??') |         self.assertEqual(e.state, '??') | ||||||
|         self.assertEqual(e.char, '??') |         self.assertEqual(e.char, '??') | ||||||
|  | @ -676,7 +676,7 @@ def test_event_generate_key_press(self): | ||||||
|         self.assertIsInstance(e.serial, int) |         self.assertIsInstance(e.serial, int) | ||||||
|         self.assertEqual(e.time, 0) |         self.assertEqual(e.time, 0) | ||||||
|         self.assertIs(e.send_event, False) |         self.assertIs(e.send_event, False) | ||||||
|         self.assertFalse(hasattr(e, 'focus')) |         self.assertNotHasAttr(e, 'focus') | ||||||
|         self.assertEqual(e.num, '??') |         self.assertEqual(e.num, '??') | ||||||
|         self.assertIsInstance(e.state, int) |         self.assertIsInstance(e.state, int) | ||||||
|         self.assertNotEqual(e.state, 0) |         self.assertNotEqual(e.state, 0) | ||||||
|  | @ -747,7 +747,7 @@ def test_event_generate_button_press(self): | ||||||
|         self.assertIsInstance(e.serial, int) |         self.assertIsInstance(e.serial, int) | ||||||
|         self.assertEqual(e.time, 0) |         self.assertEqual(e.time, 0) | ||||||
|         self.assertIs(e.send_event, False) |         self.assertIs(e.send_event, False) | ||||||
|         self.assertFalse(hasattr(e, 'focus')) |         self.assertNotHasAttr(e, 'focus') | ||||||
|         self.assertEqual(e.num, 1) |         self.assertEqual(e.num, 1) | ||||||
|         self.assertEqual(e.state, 0) |         self.assertEqual(e.state, 0) | ||||||
|         self.assertEqual(e.char, '??') |         self.assertEqual(e.char, '??') | ||||||
|  | @ -781,7 +781,7 @@ def test_event_generate_motion(self): | ||||||
|         self.assertIsInstance(e.serial, int) |         self.assertIsInstance(e.serial, int) | ||||||
|         self.assertEqual(e.time, 0) |         self.assertEqual(e.time, 0) | ||||||
|         self.assertIs(e.send_event, False) |         self.assertIs(e.send_event, False) | ||||||
|         self.assertFalse(hasattr(e, 'focus')) |         self.assertNotHasAttr(e, 'focus') | ||||||
|         self.assertEqual(e.num, '??') |         self.assertEqual(e.num, '??') | ||||||
|         self.assertEqual(e.state, 0x100) |         self.assertEqual(e.state, 0x100) | ||||||
|         self.assertEqual(e.char, '??') |         self.assertEqual(e.char, '??') | ||||||
|  | @ -814,7 +814,7 @@ def test_event_generate_mouse_wheel(self): | ||||||
|         self.assertIs(e.widget, f) |         self.assertIs(e.widget, f) | ||||||
|         self.assertIsInstance(e.serial, int) |         self.assertIsInstance(e.serial, int) | ||||||
|         self.assertIs(e.send_event, False) |         self.assertIs(e.send_event, False) | ||||||
|         self.assertFalse(hasattr(e, 'focus')) |         self.assertNotHasAttr(e, 'focus') | ||||||
|         self.assertEqual(e.time, 0) |         self.assertEqual(e.time, 0) | ||||||
|         self.assertEqual(e.num, '??') |         self.assertEqual(e.num, '??') | ||||||
|         self.assertEqual(e.state, 0) |         self.assertEqual(e.state, 0) | ||||||
|  | @ -849,7 +849,7 @@ def test_generate_event_virtual_event(self): | ||||||
|         self.assertIsInstance(e.serial, int) |         self.assertIsInstance(e.serial, int) | ||||||
|         self.assertEqual(e.time, 0) |         self.assertEqual(e.time, 0) | ||||||
|         self.assertIs(e.send_event, False) |         self.assertIs(e.send_event, False) | ||||||
|         self.assertFalse(hasattr(e, 'focus')) |         self.assertNotHasAttr(e, 'focus') | ||||||
|         self.assertEqual(e.num, '??') |         self.assertEqual(e.num, '??') | ||||||
|         self.assertEqual(e.state, 0) |         self.assertEqual(e.state, 0) | ||||||
|         self.assertEqual(e.char, '??') |         self.assertEqual(e.char, '??') | ||||||
|  | @ -1308,17 +1308,17 @@ def test_no_default_root(self): | ||||||
|         self.assertIs(tkinter._default_root, root) |         self.assertIs(tkinter._default_root, root) | ||||||
|         tkinter.NoDefaultRoot() |         tkinter.NoDefaultRoot() | ||||||
|         self.assertIs(tkinter._support_default_root, False) |         self.assertIs(tkinter._support_default_root, False) | ||||||
|         self.assertFalse(hasattr(tkinter, '_default_root')) |         self.assertNotHasAttr(tkinter, '_default_root') | ||||||
|         # repeated call is no-op |         # repeated call is no-op | ||||||
|         tkinter.NoDefaultRoot() |         tkinter.NoDefaultRoot() | ||||||
|         self.assertIs(tkinter._support_default_root, False) |         self.assertIs(tkinter._support_default_root, False) | ||||||
|         self.assertFalse(hasattr(tkinter, '_default_root')) |         self.assertNotHasAttr(tkinter, '_default_root') | ||||||
|         root.destroy() |         root.destroy() | ||||||
|         self.assertIs(tkinter._support_default_root, False) |         self.assertIs(tkinter._support_default_root, False) | ||||||
|         self.assertFalse(hasattr(tkinter, '_default_root')) |         self.assertNotHasAttr(tkinter, '_default_root') | ||||||
|         root = tkinter.Tk() |         root = tkinter.Tk() | ||||||
|         self.assertIs(tkinter._support_default_root, False) |         self.assertIs(tkinter._support_default_root, False) | ||||||
|         self.assertFalse(hasattr(tkinter, '_default_root')) |         self.assertNotHasAttr(tkinter, '_default_root') | ||||||
|         root.destroy() |         root.destroy() | ||||||
| 
 | 
 | ||||||
|     def test_getboolean(self): |     def test_getboolean(self): | ||||||
|  |  | ||||||
|  | @ -344,7 +344,7 @@ def test_longargs(self): | ||||||
|                 todo = set(t.name[1:]) |                 todo = set(t.name[1:]) | ||||||
|                 self.assertEqual(len(t.args.args) + len(t.args.posonlyargs), |                 self.assertEqual(len(t.args.args) + len(t.args.posonlyargs), | ||||||
|                                  len(todo) - bool(t.args.vararg) - bool(t.args.kwarg)) |                                  len(todo) - bool(t.args.vararg) - bool(t.args.kwarg)) | ||||||
|                 self.assertTrue(t.name.startswith('f'), t.name) |                 self.assertStartsWith(t.name, 'f') | ||||||
|                 for index, c in enumerate(t.name[1:]): |                 for index, c in enumerate(t.name[1:]): | ||||||
|                     todo.remove(c) |                     todo.remove(c) | ||||||
|                     if c == 'v': |                     if c == 'v': | ||||||
|  |  | ||||||
Some files were not shown because too many files have changed in this diff Show more
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)