GeezerVison is showing github.com — gh-71339: Use new assertion methods in tests (GH-129046) · miss-islington/cpython@1b9bb43
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Lib/test/_test_embed_structseq.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ def check_structseq(self, obj_type): | 11 | 11 | # ob_refcnt | 12 | 12 | self.assertGreaterEqual(sys.getrefcount(obj_type), 1) | 13 | 13 | # tp_base | 14 | | - self.assertTrue(issubclass(obj_type, tuple)) | | 14 | + self.assertIsSubclass(obj_type, tuple) | 15 | 15 | # tp_bases | 16 | 16 | self.assertEqual(obj_type.__bases__, (tuple,)) | 17 | 17 | # tp_dict | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/datetimetester.py +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -183,7 +183,7 @@ class NotEnough(tzinfo): | 183 | 183 | def __init__(self, offset, name): | 184 | 184 | self.__offset = offset | 185 | 185 | self.__name = name | 186 | | - self.assertTrue(issubclass(NotEnough, tzinfo)) | | 186 | + self.assertIsSubclass(NotEnough, tzinfo) | 187 | 187 | ne = NotEnough(3, "NotByALongShot") | 188 | 188 | self.assertIsInstance(ne, tzinfo) | 189 | 189 |
| @@ -232,7 +232,7 @@ def test_pickling_subclass(self): | 232 | 232 | self.assertIs(type(derived), otype) | 233 | 233 | self.assertEqual(derived.utcoffset(None), offset) | 234 | 234 | self.assertEqual(derived.tzname(None), oname) | 235 | | - self.assertFalse(hasattr(derived, 'spam')) | | 235 | + self.assertNotHasAttr(derived, 'spam') | 236 | 236 |
| 237 | 237 | def test_issue23600(self): | 238 | 238 | DSTDIFF = DSTOFFSET = timedelta(hours=1) | @@ -813,7 +813,7 @@ def test_roundtrip(self): | 813 | 813 |
| 814 | 814 | # Verify td -> string -> td identity. | 815 | 815 | s = repr(td) | 816 | | - self.assertTrue(s.startswith('datetime.')) | | 816 | + self.assertStartsWith(s, 'datetime.') | 817 | 817 | s = s[9:] | 818 | 818 | td2 = eval(s) | 819 | 819 | self.assertEqual(td, td2) | @@ -1231,7 +1231,7 @@ def test_roundtrip(self): | 1231 | 1231 | self.theclass.today()): | 1232 | 1232 | # Verify dt -> string -> date identity. | 1233 | 1233 | s = repr(dt) | 1234 | | - self.assertTrue(s.startswith('datetime.')) | | 1234 | + self.assertStartsWith(s, 'datetime.') | 1235 | 1235 | s = s[9:] | 1236 | 1236 | dt2 = eval(s) | 1237 | 1237 | self.assertEqual(dt, dt2) | @@ -2218,7 +2218,7 @@ def test_roundtrip(self): | 2218 | 2218 | self.theclass.now()): | 2219 | 2219 | # Verify dt -> string -> datetime identity. | 2220 | 2220 | s = repr(dt) | 2221 | | - self.assertTrue(s.startswith('datetime.')) | | 2221 | + self.assertStartsWith(s, 'datetime.') | 2222 | 2222 | s = s[9:] | 2223 | 2223 | dt2 = eval(s) | 2224 | 2224 | self.assertEqual(dt, dt2) | @@ -3672,7 +3672,7 @@ def test_roundtrip(self): | 3672 | 3672 |
| 3673 | 3673 | # Verify t -> string -> time identity. | 3674 | 3674 | s = repr(t) | 3675 | | - self.assertTrue(s.startswith('datetime.')) | | 3675 | + self.assertStartsWith(s, 'datetime.') | 3676 | 3676 | s = s[9:] | 3677 | 3677 | t2 = eval(s) | 3678 | 3678 | self.assertEqual(t, t2) | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/mapping_tests.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,8 +70,8 @@ def test_read(self): | 70 | 70 | if not d: self.fail("Full mapping must compare to True") | 71 | 71 | # keys(), items(), iterkeys() ... | 72 | 72 | def check_iterandlist(iter, lst, ref): | 73 | | - self.assertTrue(hasattr(iter, '__next__')) | 74 | | - self.assertTrue(hasattr(iter, '__iter__')) | | 73 | + self.assertHasAttr(iter, '__next__') | | 74 | + self.assertHasAttr(iter, '__iter__') | 75 | 75 | x = list(iter) | 76 | 76 | self.assertTrue(set(x)==set(lst)==set(ref)) | 77 | 77 | check_iterandlist(iter(d.keys()), list(d.keys()), | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/pickletester.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3068,7 +3068,7 @@ def test_proto(self): | 3068 | 3068 | pickled = self.dumps(None, proto) | 3069 | 3069 | if proto >= 2: | 3070 | 3070 | proto_header = pickle.PROTO + bytes([proto]) | 3071 | | - self.assertTrue(pickled.startswith(proto_header)) | | 3071 | + self.assertStartsWith(pickled, proto_header) | 3072 | 3072 | else: | 3073 | 3073 | self.assertEqual(count_opcode(pickle.PROTO, pickled), 0) | 3074 | 3074 |
| @@ -5007,7 +5007,7 @@ def test_default_dispatch_table(self): | 5007 | 5007 | p = self.pickler_class(f, 0) | 5008 | 5008 | with self.assertRaises(AttributeError): | 5009 | 5009 | p.dispatch_table | 5010 | | - self.assertFalse(hasattr(p, 'dispatch_table')) | | 5010 | + self.assertNotHasAttr(p, 'dispatch_table') | 5011 | 5011 |
| 5012 | 5012 | def test_class_dispatch_table(self): | 5013 | 5013 | # A dispatch_table attribute can be specified class-wide | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/support/warnings_helper.py +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,8 +23,7 @@ def check_syntax_warning(testcase, statement, errtext='', | 23 | 23 | testcase.assertEqual(len(warns), 1, warns) | 24 | 24 |
| 25 | 25 | warn, = warns | 26 | | - testcase.assertTrue(issubclass(warn.category, SyntaxWarning), | 27 | | - warn.category) | | 26 | + testcase.assertIsSubclass(warn.category, SyntaxWarning) | 28 | 27 | if errtext: | 29 | 28 | testcase.assertRegex(str(warn.message), errtext) | 30 | 29 | testcase.assertEqual(warn.filename, '<testcase>') | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test__osx_support.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -66,8 +66,8 @@ def test__find_build_tool(self): | 66 | 66 | 'cc not found - check xcode-select') | 67 | 67 |
| 68 | 68 | def test__get_system_version(self): | 69 | | - self.assertTrue(platform.mac_ver()[0].startswith( | 70 | | - _osx_support._get_system_version())) | | 69 | + self.assertStartsWith(platform.mac_ver()[0], | | 70 | + _osx_support._get_system_version()) | 71 | 71 |
| 72 | 72 | def test__remove_original_values(self): | 73 | 73 | config_vars = { | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_abstract_numbers.py +15-15Lines changed: 15 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,11 +24,11 @@ def not_implemented(*args, **kwargs): | 24 | 24 |
| 25 | 25 | class TestNumbers(unittest.TestCase): | 26 | 26 | def test_int(self): | 27 | | - self.assertTrue(issubclass(int, Integral)) | 28 | | - self.assertTrue(issubclass(int, Rational)) | 29 | | - self.assertTrue(issubclass(int, Real)) | 30 | | - self.assertTrue(issubclass(int, Complex)) | 31 | | - self.assertTrue(issubclass(int, Number)) | | 27 | + self.assertIsSubclass(int, Integral) | | 28 | + self.assertIsSubclass(int, Rational) | | 29 | + self.assertIsSubclass(int, Real) | | 30 | + self.assertIsSubclass(int, Complex) | | 31 | + self.assertIsSubclass(int, Number) | 32 | 32 |
| 33 | 33 | self.assertEqual(7, int(7).real) | 34 | 34 | self.assertEqual(0, int(7).imag) | @@ -38,23 +38,23 @@ def test_int(self): | 38 | 38 | self.assertEqual(1, int(7).denominator) | 39 | 39 |
| 40 | 40 | def test_float(self): | 41 | | - self.assertFalse(issubclass(float, Integral)) | 42 | | - self.assertFalse(issubclass(float, Rational)) | 43 | | - self.assertTrue(issubclass(float, Real)) | 44 | | - self.assertTrue(issubclass(float, Complex)) | 45 | | - self.assertTrue(issubclass(float, Number)) | | 41 | + self.assertNotIsSubclass(float, Integral) | | 42 | + self.assertNotIsSubclass(float, Rational) | | 43 | + self.assertIsSubclass(float, Real) | | 44 | + self.assertIsSubclass(float, Complex) | | 45 | + self.assertIsSubclass(float, Number) | 46 | 46 |
| 47 | 47 | self.assertEqual(7.3, float(7.3).real) | 48 | 48 | self.assertEqual(0, float(7.3).imag) | 49 | 49 | self.assertEqual(7.3, float(7.3).conjugate()) | 50 | 50 | self.assertEqual(-7.3, float(-7.3).conjugate()) | 51 | 51 |
| 52 | 52 | def test_complex(self): | 53 | | - self.assertFalse(issubclass(complex, Integral)) | 54 | | - self.assertFalse(issubclass(complex, Rational)) | 55 | | - self.assertFalse(issubclass(complex, Real)) | 56 | | - self.assertTrue(issubclass(complex, Complex)) | 57 | | - self.assertTrue(issubclass(complex, Number)) | | 53 | + self.assertNotIsSubclass(complex, Integral) | | 54 | + self.assertNotIsSubclass(complex, Rational) | | 55 | + self.assertNotIsSubclass(complex, Real) | | 56 | + self.assertIsSubclass(complex, Complex) | | 57 | + self.assertIsSubclass(complex, Number) | 58 | 58 |
| 59 | 59 | c1, c2 = complex(3, 2), complex(4,1) | 60 | 60 | # XXX: This is not ideal, but see the comment in math_trunc(). | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_argparse.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -6805,7 +6805,7 @@ class TestImportStar(TestCase): | 6805 | 6805 |
| 6806 | 6806 | def test(self): | 6807 | 6807 | for name in argparse.__all__: | 6808 | | - self.assertTrue(hasattr(argparse, name)) | | 6808 | + self.assertHasAttr(argparse, name) | 6809 | 6809 |
| 6810 | 6810 | def test_all_exports_everything_but_modules(self): | 6811 | 6811 | items = [ | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_ast/test_ast.py +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -275,12 +275,12 @@ def test_alias(self): | 275 | 275 | self.assertEqual(alias.end_col_offset, 17) | 276 | 276 |
| 277 | 277 | def test_base_classes(self): | 278 | | - self.assertTrue(issubclass(ast.For, ast.stmt)) | 279 | | - self.assertTrue(issubclass(ast.Name, ast.expr)) | 280 | | - self.assertTrue(issubclass(ast.stmt, ast.AST)) | 281 | | - self.assertTrue(issubclass(ast.expr, ast.AST)) | 282 | | - self.assertTrue(issubclass(ast.comprehension, ast.AST)) | 283 | | - self.assertTrue(issubclass(ast.Gt, ast.AST)) | | 278 | + self.assertIsSubclass(ast.For, ast.stmt) | | 279 | + self.assertIsSubclass(ast.Name, ast.expr) | | 280 | + self.assertIsSubclass(ast.stmt, ast.AST) | | 281 | + self.assertIsSubclass(ast.expr, ast.AST) | | 282 | + self.assertIsSubclass(ast.comprehension, ast.AST) | | 283 | + self.assertIsSubclass(ast.Gt, ast.AST) | 284 | 284 |
| 285 | 285 | def test_field_attr_existence(self): | 286 | 286 | for name, item in ast.__dict__.items(): | @@ -1101,7 +1101,7 @@ def test_copy_with_parents(self): | 1101 | 1101 | def test_replace_interface(self): | 1102 | 1102 | for klass in self.iter_ast_classes(): | 1103 | 1103 | with self.subTest(klass=klass): | 1104 | | - self.assertTrue(hasattr(klass, '__replace__')) | | 1104 | + self.assertHasAttr(klass, '__replace__') | 1105 | 1105 |
| 1106 | 1106 | fields = set(klass._fields) | 1107 | 1107 | with self.subTest(klass=klass, fields=fields): | @@ -1330,7 +1330,7 @@ def test_replace_reject_known_custom_instance_fields_commits(self): | 1330 | 1330 | context = node.ctx | 1331 | 1331 |
| 1332 | 1332 | # explicit rejection of known instance fields | 1333 | | - self.assertTrue(hasattr(node, 'extra')) | | 1333 | + self.assertHasAttr(node, 'extra') | 1334 | 1334 | msg = "Name.__replace__ got an unexpected keyword argument 'extra'." | 1335 | 1335 | with self.assertRaisesRegex(TypeError, re.escape(msg)): | 1336 | 1336 | copy.replace(node, extra=1) | @@ -3071,7 +3071,7 @@ def test_FunctionDef(self): | 3071 | 3071 | with self.assertWarnsRegex(DeprecationWarning, | 3072 | 3072 | r"FunctionDef\.__init__ missing 1 required positional argument: 'name'"): | 3073 | 3073 | node = ast.FunctionDef(args=args) | 3074 | | - self.assertFalse(hasattr(node, "name")) | | 3074 | + self.assertNotHasAttr(node, "name") | 3075 | 3075 | self.assertEqual(node.decorator_list, []) | 3076 | 3076 | node = ast.FunctionDef(name='foo', args=args) | 3077 | 3077 | self.assertEqual(node.name, 'foo') | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_audit.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -134,7 +134,7 @@ def test_socket(self): | 134 | 134 | self.assertEqual(events[0][0], "socket.gethostname") | 135 | 135 | self.assertEqual(events[1][0], "socket.__new__") | 136 | 136 | self.assertEqual(events[2][0], "socket.bind") | 137 | | - self.assertTrue(events[2][2].endswith("('127.0.0.1', 8080)")) | | 137 | + self.assertEndsWith(events[2][2], "('127.0.0.1', 8080)") | 138 | 138 |
| 139 | 139 | def test_gc(self): | 140 | 140 | returncode, events, stderr = self.run_python("test_gc") | |
|