Skip to content

Commit e7dd248

Browse files
committed
adjust tests
1 parent 5c19de2 commit e7dd248

2 files changed

Lines changed: 9 additions & 31 deletions

File tree

Lib/test/test_capi/test_set.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import gc
21
import unittest
32

43
from test.support import import_helper
@@ -222,33 +221,12 @@ def test_clear(self):
222221

223222

224223
class TestPySet_Add(unittest.TestCase):
225-
def test_pyset_add(self):
226-
# Run C-level tests for PySet_Add
227-
_testcapi.test_pyset_add()
224+
def test_pyset_add_exact_set(self):
225+
_testcapi.test_pyset_add_exact_set()
228226

229-
def test_set(self):
230-
# Test the PySet_Add c-api for set objects
231-
s = set()
232-
self.assertEqual(_testlimitedcapi.pyset_add(s, 1), {1})
233-
self.assertRaises(TypeError, _testlimitedcapi.pyset_add, s, [])
227+
def test_pyset_add_frozenset(self):
228+
_testcapi.test_pyset_add_frozenset()
234229

235-
def test_frozenset(self):
236-
# Test the PySet_Add c-api for frozenset objects
237-
self.assertEqual(_testlimitedcapi.pyset_add(frozenset(), 1), frozenset([1]))
238-
frozen_set = frozenset()
239-
# if the argument to PySet_Add is a frozenset that is not uniquely references an error is generated
240-
self.assertRaises(SystemError, _testlimitedcapi.pyset_add, frozen_set, 1)
241-
242-
def test_frozenset_gc_tracking(self):
243-
# see gh-140234
244-
class TrackedHashableClass():
245-
pass
246-
247-
a = TrackedHashableClass()
248-
result_set = _testlimitedcapi.pyset_add(frozenset(), 1)
249-
self.assertFalse(gc.is_tracked(result_set))
250-
result_set = _testlimitedcapi.pyset_add(frozenset(), a)
251-
self.assertTrue(gc.is_tracked(result_set))
252230

253231

254232
class TestInternalCAPI(BaseSetTests, unittest.TestCase):

Modules/_testcapimodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,17 +2447,17 @@ test_pyset_add_exact_set(PyObject *self, PyObject *Py_UNUSED(ignored))
24472447

24482448
if (PySet_Add(set, one) < 0) {
24492449
Py_DECREF(set);
2450-
return raiseTestError(self, "test_pyset_add",
2450+
return raiseTestError(self, "test_pyset_add_exact_set",
24512451
"PySet_Add to empty set failed");
24522452
}
24532453
if (PySet_Size(set) != 1) {
24542454
Py_DECREF(set);
2455-
return raiseTestError(self, "test_pyset_add",
2455+
return raiseTestError(self, "test_pyset_add_exact_set",
24562456
"set size should be 1 after adding one element");
24572457
}
24582458
if (PySet_Contains(set, one) != 1) {
24592459
Py_DECREF(set);
2460-
return raiseTestError(self, "test_pyset_add",
2460+
return raiseTestError(self, "test_pyset_add_exact_set",
24612461
"set should contain the added element");
24622462
}
24632463
Py_DECREF(set);
@@ -2475,13 +2475,13 @@ test_pyset_add_exact_set(PyObject *self, PyObject *Py_UNUSED(ignored))
24752475
if (PySet_Add(set, unhashable) != -1) {
24762476
Py_DECREF(unhashable);
24772477
Py_DECREF(set);
2478-
return raiseTestError(self, "test_pyset_add",
2478+
return raiseTestError(self, "test_pyset_add_exact_set",
24792479
"PySet_Add with unhashable should fail");
24802480
}
24812481
if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
24822482
Py_DECREF(unhashable);
24832483
Py_DECREF(set);
2484-
return raiseTestError(self, "test_pyset_add",
2484+
return raiseTestError(self, "test_pyset_add_exact_set",
24852485
"PySet_Add with unhashable should raise TypeError");
24862486
}
24872487
PyErr_Clear();

0 commit comments

Comments
 (0)