Skip to content

Commit 5c083c7

Browse files
Distinguish 3.14 tests in test_module_as_str
1 parent 40268d1 commit 5c083c7

File tree

3 files changed

+104
-8
lines changed

3 files changed

+104
-8
lines changed

tests/test_nodes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
transforms,
2929
util,
3030
)
31-
from astroid.const import IS_PYPY, PY310_PLUS, PY312_PLUS, Context
31+
from astroid.const import IS_PYPY, PY310_PLUS, PY312_PLUS, PY314_PLUS, Context
3232
from astroid.context import InferenceContext
3333
from astroid.exceptions import (
3434
AstroidBuildingError,
@@ -114,12 +114,20 @@ def test_varargs_kwargs_as_string(self) -> None:
114114
ast = abuilder.string_build("raise_string(*args, **kwargs)").body[0]
115115
self.assertEqual(ast.as_string(), "raise_string(*args, **kwargs)")
116116

117-
def test_module_as_string(self) -> None:
118-
"""Check as_string on a whole module prepared to be returned identically."""
117+
@pytest.mark.skipif(PY314_PLUS, "return in finally is now a syntax error")
118+
def test_module_as_string_pre_3_14(self) -> None:
119+
"""Check as_string on a whole module prepared to be returned identically for py < 3.14."""
119120
module = resources.build_file("data/module.py", "data.module")
120121
with open(resources.find("data/module.py"), encoding="utf-8") as fobj:
121122
self.assertMultiLineEqual(module.as_string(), fobj.read())
122123

124+
@pytest.mark.skipif(not PY314_PLUS, "return in finally is now a syntax error")
125+
def test_module_as_string(self) -> None:
126+
"""Check as_string on a whole module prepared to be returned identically for py > 3.14."""
127+
module = resources.build_file("data/module3.14.py", "data.module3.14")
128+
with open(resources.find("data/module3.14.py"), encoding="utf-8") as fobj:
129+
self.assertMultiLineEqual(module.as_string(), fobj.read())
130+
123131
def test_module2_as_string(self) -> None:
124132
"""Check as_string on a whole module prepared to be returned identically."""
125133
module2 = resources.build_file("data/module2.py", "data.module2")

tests/testdata/python3/data/module.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ def method(self):
6363
global_access(local, val=autre)
6464
finally:
6565
# return in finally was previousely tested here but became a syntax error
66-
# in 3.14 and is used in 188/1464 tests
67-
if sys.version_info >= (3, 14):
68-
pass
69-
else:
70-
return local
66+
# in 3.14 and this file is used in 188/1464 tests
67+
print(local)
7168

7269
def static_method():
7370
"""static method test"""
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""test module for astroid
2+
"""
3+
4+
__revision__ = '$Id: module.py,v 1.2 2005-11-02 11:56:54 syt Exp $'
5+
from astroid.nodes.node_classes import Name as NameNode
6+
from astroid import modutils
7+
from astroid.utils import *
8+
import os.path
9+
MY_DICT = {}
10+
11+
def global_access(key, val):
12+
"""function test"""
13+
local = 1
14+
MY_DICT[key] = val
15+
for i in val:
16+
if i:
17+
del MY_DICT[i]
18+
continue
19+
else:
20+
break
21+
else:
22+
return
23+
24+
25+
class YO:
26+
"""hehe
27+
haha"""
28+
a = 1
29+
30+
def __init__(self):
31+
try:
32+
self.yo = 1
33+
except ValueError as ex:
34+
pass
35+
except (NameError, TypeError):
36+
raise XXXError()
37+
except:
38+
raise
39+
40+
41+
42+
class YOUPI(YO):
43+
class_attr = None
44+
45+
def __init__(self):
46+
self.member = None
47+
48+
def method(self):
49+
"""method
50+
test"""
51+
global MY_DICT
52+
try:
53+
MY_DICT = {}
54+
local = None
55+
autre = [a for (a, b) in MY_DICT if b]
56+
if b in autre:
57+
return
58+
elif a in autre:
59+
return 'hehe'
60+
global_access(local, val=autre)
61+
finally:
62+
# return in finally was previousely tested here but became a syntax error
63+
# in 3.14 and is used in 188/1464 tests
64+
print(local)
65+
66+
def static_method():
67+
"""static method test"""
68+
assert MY_DICT, '???'
69+
static_method = staticmethod(static_method)
70+
71+
def class_method(cls):
72+
"""class method test"""
73+
exec(a, b)
74+
class_method = classmethod(class_method)
75+
76+
77+
def four_args(a, b, c, d):
78+
"""four arguments (was nested_args)"""
79+
while 1:
80+
if a:
81+
break
82+
a += +1
83+
else:
84+
b += -2
85+
if c:
86+
d = a and (b or c)
87+
else:
88+
c = a and b or d
89+
list(map(lambda x, y: (y, x), a))
90+
redirect = four_args
91+

0 commit comments

Comments
 (0)