Skip to content

Commit 148240d

Browse files
committed
Fix module_as_string test case
1 parent 93064fe commit 148240d

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

tests/test_nodes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,24 @@ def test_module_as_string_pre_3_14(self) -> None:
121121
self.maxDiff = None
122122
module = resources.build_file("data/module.py", "data.module")
123123
with open(resources.find("data/module.py"), encoding="utf-8") as fobj:
124-
self.assertMultiLineEqual(module.as_string(), fobj.read())
124+
data_str = "\n".join(
125+
[s for s in fobj.read().split("\n") if not s.lstrip().startswith("# ")]
126+
)
127+
self.assertMultiLineEqual(module.as_string(), data_str)
125128

126129
@pytest.mark.skipif(
127130
not PY314_PLUS, reason="return in finally is now a syntax error"
128131
)
129132
def test_module_as_string(self) -> None:
130133
"""Check as_string on a whole module prepared to be returned identically for py > 3.14."""
134+
self.maxDiff = None
131135
module = resources.build_file("data/module3.14.py", "data.module3.14")
132136
with open(resources.find("data/module3.14.py"), encoding="utf-8") as fobj:
133-
self.assertMultiLineEqual(module.as_string(), fobj.read())
137+
# Ignore comments in python file
138+
data_str = "\n".join(
139+
[s for s in fobj.read().split("\n") if not s.lstrip().startswith("# ")]
140+
)
141+
self.assertMultiLineEqual(module.as_string(), data_str)
134142

135143
def test_module2_as_string(self) -> None:
136144
"""Check as_string on a whole module prepared to be returned identically."""

tests/testdata/python3/data/module.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ def method(self):
5959
return 'hehe'
6060
global_access(local, val=autre)
6161
finally:
62-
# return in finally was previousely tested here but became a syntax error
62+
# return in finally was previously tested here but became a syntax error
6363
# in 3.14 and this file is used in 188/1464 tests
6464
a = local
65-
65+
6666
def static_method():
6767
"""static method test"""
6868
assert MY_DICT, '???'
@@ -88,4 +88,3 @@ def four_args(a, b, c, d):
8888
c = a and b or d
8989
list(map(lambda x, y: (y, x), a))
9090
redirect = four_args
91-

tests/testdata/python3/data/module3.14.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ def method(self):
5959
return 'hehe'
6060
global_access(local, val=autre)
6161
finally:
62-
# return in finally was previousely tested here but became a syntax error
62+
# return in finally was previously tested here but became a syntax error
6363
# in 3.14 and is used in 188/1464 tests
6464
print(local)
65-
65+
6666
def static_method():
6767
"""static method test"""
6868
assert MY_DICT, '???'

0 commit comments

Comments
 (0)