Skip to content

Commit

Permalink
More precise checking for warning source (#5506)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: becd5a9c50a9492e5206cd3616626c76a480b0b3
  • Loading branch information
embe-pw authored and Manul from Pathway committed Jan 26, 2024
1 parent 13596d5 commit a97ef16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
13 changes: 7 additions & 6 deletions python/pathway/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3463,13 +3463,14 @@ def test_update_cells_0_rows():
"""
)

with warns_here(
match=re.escape(
"Key sets of self and other in update_cells are the same. "
"Using with_columns instead of update_cells."
),
):
match = re.escape(
"Key sets of self and other in update_cells are the same. "
"Using with_columns instead of update_cells."
)

with warns_here(match=match):
new = old.update_cells(update)
with warns_here(match=match):
new2 = old << update
assert_table_equality(new, expected)
assert_table_equality(new2, expected)
Expand Down
25 changes: 21 additions & 4 deletions python/pathway/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,27 @@ def warns_here(
with pytest.warns(expected_warning, match=match) as context:
yield context

for warning in context:
assert warning.filename == file_name
assert warning.lineno >= first_line
assert warning.lineno in function_lines
def matches(warning) -> bool:
if not isinstance(warning.message, expected_warning):
return False
if match is not None and not re.search(match, str(warning.message)):
return False
if warning.filename != file_name:
return False
if warning.lineno < first_line:
return False
if warning.lineno not in function_lines:
return False
return True

if not any(matches(warning) for warning in context):
raise AssertionError(
"No matched warning caused by expected source line.\n"
"All warnings:\n"
+ "\n".join(f" {warning}" for warning in context)
+ f"\nExpected: {file_name!r}, line in "
f"{list(line for line in function_lines if line >= first_line)}"
)


def deprecated_call_here(
Expand Down

0 comments on commit a97ef16

Please sign in to comment.