Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-71339: Use new assertion methods in test_capi#129053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-71339: Use new assertion methods in test_capi
  • Loading branch information
@serhiy-storchaka
serhiy-storchaka committedJan 20, 2025
commit7bddb8e3b1f7c3239cd3488e9ed86f85324c0d06
12 changes: 6 additions & 6 deletionsLib/test/test_capi/test_abstract.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -274,7 +274,7 @@ def test_object_setattr(self):

# PyObject_SetAttr(obj, attr_name, NULL) removes the attribute
xsetattr(obj, 'a', NULL)
self.assertFalse(hasattr(obj, 'a'))
self.assertNotHasAttr(obj, 'a')
self.assertRaises(AttributeError, xsetattr, obj, 'b', NULL)
self.assertRaises(RuntimeError, xsetattr, obj, 'evil', NULL)

Expand All@@ -294,7 +294,7 @@ def test_object_setattrstring(self):

# PyObject_SetAttrString(obj, attr_name, NULL) removes the attribute
setattrstring(obj, b'a', NULL)
self.assertFalse(hasattr(obj, 'a'))
self.assertNotHasAttr(obj, 'a')
self.assertRaises(AttributeError, setattrstring, obj, b'b', NULL)
self.assertRaises(RuntimeError, setattrstring, obj, b'evil', NULL)

Expand All@@ -311,10 +311,10 @@ def test_object_delattr(self):
obj.a = 1
setattr(obj, '\U0001f40d', 2)
xdelattr(obj, 'a')
self.assertFalse(hasattr(obj, 'a'))
self.assertNotHasAttr(obj, 'a')
self.assertRaises(AttributeError, xdelattr, obj, 'b')
xdelattr(obj, '\U0001f40d')
self.assertFalse(hasattr(obj, '\U0001f40d'))
self.assertNotHasAttr(obj, '\U0001f40d')

self.assertRaises(AttributeError, xdelattr, 42, 'numerator')
self.assertRaises(RuntimeError, xdelattr, obj, 'evil')
Expand All@@ -328,10 +328,10 @@ def test_object_delattrstring(self):
obj.a = 1
setattr(obj, '\U0001f40d', 2)
delattrstring(obj, b'a')
self.assertFalse(hasattr(obj, 'a'))
self.assertNotHasAttr(obj, 'a')
self.assertRaises(AttributeError, delattrstring, obj, b'b')
delattrstring(obj, '\U0001f40d'.encode())
self.assertFalse(hasattr(obj, '\U0001f40d'))
self.assertNotHasAttr(obj, '\U0001f40d')

self.assertRaises(AttributeError, delattrstring, 42, b'numerator')
self.assertRaises(RuntimeError, delattrstring, obj, b'evil')
Expand Down
20 changes: 10 additions & 10 deletionsLib/test/test_capi/test_misc.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,8 +116,7 @@ def test_no_FatalError_infinite_loop(self):
"after Python initialization and before Python finalization, "
"but it was called without an active thread state. "
"Are you trying to call the C API inside of a Py_BEGIN_ALLOW_THREADS block?").encode()
self.assertTrue(err.rstrip().startswith(msg),
err)
self.assertStartsWith(err.rstrip(), msg)

def test_memoryview_from_NULL_pointer(self):
self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer)
Expand DownExpand Up@@ -720,7 +719,7 @@ def test_heaptype_with_setattro(self):

def test_heaptype_with_custom_metaclass(self):
metaclass = _testcapi.HeapCTypeMetaclass
self.assertTrue(issubclass(metaclass, type))
self.assertIsSubclass(metaclass, type)

# Class creation from C
t = _testcapi.pytype_fromspec_meta(metaclass)
Expand All@@ -736,7 +735,7 @@ def test_heaptype_with_custom_metaclass(self):
def test_heaptype_with_custom_metaclass_null_new(self):
metaclass = _testcapi.HeapCTypeMetaclassNullNew

self.assertTrue(issubclass(metaclass, type))
self.assertIsSubclass(metaclass, type)

# Class creation from C
t = _testcapi.pytype_fromspec_meta(metaclass)
Expand All@@ -751,7 +750,7 @@ def test_heaptype_with_custom_metaclass_null_new(self):
def test_heaptype_with_custom_metaclass_custom_new(self):
metaclass = _testcapi.HeapCTypeMetaclassCustomNew

self.assertTrue(issubclass(_testcapi.HeapCTypeMetaclassCustomNew, type))
self.assertIsSubclass(_testcapi.HeapCTypeMetaclassCustomNew, type)

msg = "Metaclasses with custom tp_new are not supported."
with self.assertRaisesRegex(TypeError, msg):
Expand DownExpand Up@@ -910,8 +909,7 @@ def test_export_symbols(self):
names.append('Py_FrozenMain')

for name in names:
with self.subTest(name=name):
self.assertTrue(hasattr(ctypes.pythonapi, name))
self.assertHasAttr(ctypes.pythonapi, name)

def test_clear_managed_dict(self):

Expand DownExpand Up@@ -1503,7 +1501,8 @@ def inner(arg5, arg6):
self.assertIsInstance(closure, tuple)
self.assertEqual(len(closure), 1)
self.assertEqual(len(closure), len(func.__code__.co_freevars))
self.assertTrue(all(isinstance(cell, CellType) for cell in closure))
for cell in closure:
self.assertIsInstance(cell, CellType)
self.assertTrue(closure[0].cell_contents, 5)

func = with_two_levels(1, 2)(3, 4)
Expand All@@ -1512,7 +1511,8 @@ def inner(arg5, arg6):
self.assertIsInstance(closure, tuple)
self.assertEqual(len(closure), 4)
self.assertEqual(len(closure), len(func.__code__.co_freevars))
self.assertTrue(all(isinstance(cell, CellType) for cell in closure))
for cell in closure:
self.assertIsInstance(cell, CellType)
self.assertEqual([cell.cell_contents for cell in closure],
[1, 2, 3, 4])

Expand DownExpand Up@@ -2365,7 +2365,7 @@ def test_mutate_exception(self):

support.run_in_subinterp("import binascii; binascii.Error.foobar = 'foobar'")

self.assertFalse(hasattr(binascii.Error, "foobar"))
self.assertNotHasAttr(binascii.Error, "foobar")

@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
# gh-117649: The free-threaded build does not currently support sharing
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/test_capi/test_sys.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,7 @@ def test_sys_setobject(self):
self.assertEqual(setobject(b'newattr', value2), 0)
self.assertIs(sys.newattr, value2)
self.assertEqual(setobject(b'newattr', NULL), 0)
self.assertFalse(hasattr(sys, 'newattr'))
self.assertNotHasAttr(sys, 'newattr')
self.assertEqual(setobject(b'newattr', NULL), 0)
finally:
with contextlib.suppress(AttributeError):
Expand All@@ -60,7 +60,7 @@ def test_sys_setobject(self):
self.assertEqual(setobject('\U0001f40d'.encode(), value), 0)
self.assertIs(getattr(sys, '\U0001f40d'), value)
self.assertEqual(setobject('\U0001f40d'.encode(), NULL), 0)
self.assertFalse(hasattr(sys, '\U0001f40d'))
self.assertNotHasAttr(sys, '\U0001f40d')
finally:
with contextlib.suppress(AttributeError):
delattr(sys, '\U0001f40d')
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp