Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix test_parser.py.
  • Loading branch information
devdanzin committed Jul 2, 2024
commit 9a239ea252329a7f58a658923bd21d34663488fa
21 changes: 14 additions & 7 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def function() -> int:
assert parser.raw_statements == {1, 3, 4, 5, 6, 8, 9}
assert parser.statements == {1, 8, 9}

def test_multiline_exclusion(self) -> None:
def test_multiline_exclusion_single_line(self) -> None:
regex = r"print\('.*'\)"
parser = self.parse_text("""\
def foo():
Expand All @@ -791,17 +791,19 @@ def foo():
assert parser.raw_statements == {1, 2}
assert parser.statements == {1}

regex = r"if True:\n\s+print\('Hello, world!'\)"
def test_multiline_exclusion_suite(self) -> None:
regex = r"if T:\n\s+print\('Hello, world!'\)"
parser = self.parse_text("""\
def foo():
if True:
if T:
print('Hello, world!')
print('This is a multiline regex test.')
""", regex)
assert parser.lines_matching(regex) == {2, 3}
assert parser.raw_statements == {1, 2, 3, 4}
assert parser.statements == {1}

def test_multiline_exclusion_no_match(self) -> None:
regex = r"nonexistent"
parser = self.parse_text("""\
def foo():
Expand All @@ -811,12 +813,14 @@ def foo():
assert parser.raw_statements == {1, 2}
assert parser.statements == {1, 2}

def test_multiline_exclusion_no_source(self) -> None:
regex = r"anything"
parser = PythonParser(text="", filename="dummy.py", exclude=regex)
assert parser.lines_matching(regex) == set()
assert parser.raw_statements == set()
assert parser.statements == set()

def test_multiline_exclusion_multiple_matches(self) -> None:
regex = r"print\('.*'\)"
Copy link
Owner

Choose a reason for hiding this comment

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

This isn't a multi-line regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, that was just a sanity check from when I was sketching this that slipped through. I'll rewrite the test so it covers multiple multi-line matches.

parser = self.parse_text("""\
def foo():
Expand All @@ -828,22 +832,25 @@ def bar():
assert parser.raw_statements == {1, 2, 3, 4}
assert parser.statements == {1, 3}

regex = r"print\('Hello, world!'\)\n\s+if True:"
def test_multiline_exclusion_suite2(self) -> None:
regex = r"print\('Hello, world!'\)\n\s+if T:"
parser = self.parse_text("""\
def foo():
print('Hello, world!')
if True:
if T:
print('This is a test.')
""", regex)
assert parser.lines_matching(regex) == {2, 3}
assert parser.raw_statements == {1, 2, 3, 4}
assert parser.statements == {1}

regex = r"""def foo\(\):\n\s+print\('Hello, world!'\)\n\s+if True:\n\s+print\('This is a test\.'\)"""
def test_multiline_exclusion_match_all(self) -> None:
regex = (r"""def foo\(\):\n\s+print\('Hello, world!'\)\n"
"\s+if T:\n\s+print\('This is a test\.'\)""")
parser = self.parse_text("""\
def foo():
print('Hello, world!')
if True:
if T:
print('This is a test.')
""", regex)
assert parser.lines_matching(regex) == {1, 2, 3, 4}
Expand Down