]> granicus.if.org Git - python/commitdiff
Issue #7818: set().test_c_api() doesn't expect a set('abc'), modify the set.
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 13 Mar 2010 00:13:22 +0000 (00:13 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 13 Mar 2010 00:13:22 +0000 (00:13 +0000)
Lib/test/test_set.py
Objects/setobject.c

index 32f2803d93d2bdcf6de56661428cf1b4c19ddc04..808cf275ff80b86c2663d2ba1c530dacd3fc2c59 100644 (file)
@@ -562,7 +562,7 @@ class TestSet(TestJointOps):
     # C API test only available in a debug build
     if hasattr(set, "test_c_api"):
         def test_c_api(self):
-            self.assertEqual(set('abc').test_c_api(), True)
+            self.assertEqual(set().test_c_api(), True)
 
 class SetSubclass(set):
     pass
index af5d576b98d16c8c7d35a92c5ebcd6ffd8927eac..ab281af3f5b09a8f26ff480587a6795415180a9b 100644 (file)
@@ -2387,11 +2387,25 @@ test_c_api(PySetObject *so)
        Py_ssize_t i;
        PyObject *elem=NULL, *dup=NULL, *t, *f, *dup2, *x;
        PyObject *ob = (PyObject *)so;
+       PyObject *str;
 
-       /* Verify preconditions and exercise type/size checks */
+       /* Verify preconditions */
        assert(PyAnySet_Check(ob));
        assert(PyAnySet_CheckExact(ob));
        assert(!PyFrozenSet_CheckExact(ob));
+
+       /* so.clear(); so |= set("abc"); */
+       str = PyString_FromString("abc");
+       if (str == NULL)
+               return NULL;
+       set_clear_internal(so);
+       if (set_update_internal(so, str) == -1) {
+               Py_DECREF(str);
+               return NULL;
+       }
+       Py_DECREF(str);
+
+       /* Exercise type/size checks */
        assert(PySet_Size(ob) == 3);
        assert(PySet_GET_SIZE(ob) == 3);