summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMonadChains <monadchains@gmail.com>2022-10-03 20:37:15 (GMT)
committerGitHub <noreply@github.com>2022-10-03 20:37:15 (GMT)
commit9302e331c7e2edf1bb42f6b31085408a315195f5 (patch)
tree17e9ee3a9c62ea301d9943f78b50fc93c994abf6 /Lib/test
parent3a49dbb98ccc1b90554ed181386316efa38adfba (diff)
downloadcpython-9302e331c7e2edf1bb42f6b31085408a315195f5.zip
cpython-9302e331c7e2edf1bb42f6b31085408a315195f5.tar.gz
cpython-9302e331c7e2edf1bb42f6b31085408a315195f5.tar.bz2
gh-94808: Add test coverage for PyObject_HasAttrString (#96627)
* gh-94808: Add test for HasAttrString * Harmonize to Python C code style guidelines * Add check to verify no exception thrown
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_class.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index 91c53b7..61df81b 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -445,6 +445,20 @@ class ClassTests(unittest.TestCase):
del testme.cardinal
self.assertCallStack([('__delattr__', (testme, "cardinal"))])
+ def testHasAttrString(self):
+ import sys
+ from test.support import import_helper
+ _testcapi = import_helper.import_module('_testcapi')
+
+ class A:
+ def __init__(self):
+ self.attr = 1
+
+ a = A()
+ self.assertEqual(_testcapi.hasattr_string(a, "attr"), True)
+ self.assertEqual(_testcapi.hasattr_string(a, "noattr"), False)
+ self.assertEqual(sys.exc_info(), (None, None, None))
+
def testDel(self):
x = []