Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1860,8 +1860,8 @@ class D(C):
self.assertEqual(b.foo, 3)
self.assertEqual(b.__class__, D)

# TODO: RUSTPYTHON; The `expectedFailure` here is from CPython, so this test must fail
# @unittest.expectedFailure
@unittest.expectedSuccess # TODO: RUSTPYTHON; The `expectedFailure` here is from CPython, so this test must fail
@unittest.expectedFailure
def test_bad_new(self):
self.assertRaises(TypeError, object.__new__)
self.assertRaises(TypeError, object.__new__, '')
Expand Down Expand Up @@ -1908,8 +1908,8 @@ def __init__(self, foo):
object.__init__(A(3))
self.assertRaises(TypeError, object.__init__, A(3), 5)

# TODO: RUSTPYTHON; The `expectedFailure` here is from CPython, so this test must fail
# @unittest.expectedFailure
@unittest.expectedSuccess # TODO: RUSTPYTHON; The `expectedFailure` here is from CPython, so this test must fail
@unittest.expectedFailure
def test_restored_object_new(self):
class A(object):
def __new__(cls, *args, **kwargs):
Expand Down
22 changes: 16 additions & 6 deletions scripts/update_lib/patch_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,23 @@ def iter_patch_entries(
if ut_method.has_cond():
cond = ast.unparse(dec_node.args[0])
else:
# Search first on decorator line, then in the line before
for line in lines[dec_node.lineno - 1 : dec_node.lineno - 3 : -1]:
if found := re.search(rf"{COMMENT}.?(.*)", line):
reason = found.group()
break
pattern = re.compile(rf"{COMMENT}.?(.*)")
dec_lineno = dec_node.lineno

curr_line = lines[dec_lineno - 1]
prev_line = lines[dec_lineno - 2]

# If we see our comment at the decorator line, take it
if found := pattern.search(curr_line):
reason = found.group()
elif prev_line.strip().startswith("#") and (
found := pattern.search(prev_line)
):
# Search the previous line of the decorator,
# only take the comment if the line starts with a `#`
reason = found.group()
else:
# Didn't find our `COMMENT` :)
# Didn't find our `COMMENT`, so the patch isn't ours :)
continue
Comment thread
coderabbitai[bot] marked this conversation as resolved.

reason = reason.removeprefix(COMMENT).strip(";:, ")
Expand Down
24 changes: 24 additions & 0 deletions scripts/update_lib/tests/test_patch_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ def test_one(self):
specs = patches["TestFoo"]["test_one"]
self.assertEqual(len(specs), 2)

def test_comment_confusion(self):
"""
Test that we only extract our patches when CPython set one of the UT methods,
that we search for
"""

code = f"""
class TestFoo(unittest.TestCase):
@unittest.expectedSuccess # {COMMENT}; reason
@unittest.expectedFailure
def test_one(self):
pass
"""

patches = extract_patches(code)
specs = patches["TestFoo"]["test_one"]
self.assertEqual(len(specs), 1)

spec = specs[0]
self.assertEqual(
spec,
PatchSpec(ut_method=UtMethod.ExpectedSuccess, cond=None, reason="reason"),
)


class TestApplyPatches(unittest.TestCase):
"""Tests for apply_patches function."""
Expand Down
Loading