FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update test_baseexception.py from cpython 3.11.2 by dalinaum · Pull Request #4624 · RustPython/RustPython · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
36 changes: 33 additions & 3 deletions Lib/test/test_baseexception.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def verify_instance_interface(self, ins):
"%s missing %s attribute" %
(ins.__class__.__name__, attr))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_inheritance(self):
# Make sure the inheritance hierarchy matches the documentation
exc_set = set()
Expand All @@ -28,8 +30,9 @@ def test_inheritance(self):
except TypeError:
pass

inheritance_tree = open(os.path.join(os.path.split(__file__)[0],
'exception_hierarchy.txt'))
inheritance_tree = open(
os.path.join(os.path.split(__file__)[0], 'exception_hierarchy.txt'),
encoding="utf-8")
Comment on lines +33 to +35

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

One thing: since this references a file named exception_hierarchy.txt, it would make sense if it could also be brought up to date.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I uploaded it as a PR #4627.

try:
superclass_name = inheritance_tree.readline().rstrip()
try:
Expand All @@ -43,7 +46,7 @@ def test_inheritance(self):
last_depth = 0
for exc_line in inheritance_tree:
exc_line = exc_line.rstrip()
depth = exc_line.rindex('-')
depth = exc_line.rindex('')
exc_name = exc_line[depth+2:] # Slice past space
if '(' in exc_name:
paren_index = exc_name.index('(')
Expand Down Expand Up @@ -117,6 +120,33 @@ def test_interface_no_arg(self):
[repr(exc), exc.__class__.__name__ + '()'])
self.interface_test_driver(results)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_setstate_refcount_no_crash(self):
# gh-97591: Acquire strong reference before calling tp_hash slot
# in PyObject_SetAttr.
import gc
d = {}
class HashThisKeyWillClearTheDict(str):
def __hash__(self) -> int:
d.clear()
return super().__hash__()
class Value(str):
pass
exc = Exception()

d[HashThisKeyWillClearTheDict()] = Value() # refcount of Value() is 1 now

# Exception.__setstate__ should aquire a strong reference of key and
# value in the dict. Otherwise, Value()'s refcount would go below
# zero in the tp_hash call in PyObject_SetAttr(), and it would cause
# crash in GC.
exc.__setstate__(d) # __hash__() is called again here, clearing the dict.

# This GC would crash if the refcount of Value() goes below zero.
gc.collect()


class UsageTests(unittest.TestCase):

"""Test usage of exceptions"""
Expand Down

Back | FazBrowse Home | New Git URL