|
28 | 28 | transforms, |
29 | 29 | util, |
30 | 30 | ) |
31 | | -from astroid.const import IS_PYPY, PY310_PLUS, PY311_PLUS, PY312_PLUS, Context |
| 31 | +from astroid.const import ( |
| 32 | + IS_PYPY, |
| 33 | + PY310_PLUS, |
| 34 | + PY311_PLUS, |
| 35 | + PY312_PLUS, |
| 36 | + PY314_PLUS, |
| 37 | + Context, |
| 38 | +) |
32 | 39 | from astroid.context import InferenceContext |
33 | 40 | from astroid.exceptions import ( |
34 | 41 | AstroidBuildingError, |
@@ -115,11 +122,31 @@ def test_varargs_kwargs_as_string(self) -> None: |
115 | 122 | ast = abuilder.string_build("raise_string(*args, **kwargs)").body[0] |
116 | 123 | self.assertEqual(ast.as_string(), "raise_string(*args, **kwargs)") |
117 | 124 |
|
118 | | - def test_module_as_string(self) -> None: |
119 | | - """Check as_string on a whole module prepared to be returned identically.""" |
| 125 | + @pytest.mark.skipif(PY314_PLUS, reason="return in finally is now a syntax error") |
| 126 | + def test_module_as_string_pre_3_14(self) -> None: |
| 127 | + """Check as_string on a whole module prepared to be returned identically for py < 3.14.""" |
| 128 | + self.maxDiff = None |
120 | 129 | module = resources.build_file("data/module.py", "data.module") |
121 | 130 | with open(resources.find("data/module.py"), encoding="utf-8") as fobj: |
122 | | - self.assertMultiLineEqual(module.as_string(), fobj.read()) |
| 131 | + # Ignore comments in python file |
| 132 | + data_str = "\n".join( |
| 133 | + [s for s in fobj.read().split("\n") if not s.lstrip().startswith("# ")] |
| 134 | + ) |
| 135 | + self.assertMultiLineEqual(module.as_string(), data_str) |
| 136 | + |
| 137 | + @pytest.mark.skipif( |
| 138 | + not PY314_PLUS, reason="return in finally is now a syntax error" |
| 139 | + ) |
| 140 | + def test_module_as_string(self) -> None: |
| 141 | + """Check as_string on a whole module prepared to be returned identically for py > 3.14.""" |
| 142 | + self.maxDiff = None |
| 143 | + module = resources.build_file("data/module3.14.py", "data.module3.14") |
| 144 | + with open(resources.find("data/module3.14.py"), encoding="utf-8") as fobj: |
| 145 | + # Ignore comments in python file |
| 146 | + data_str = "\n".join( |
| 147 | + [s for s in fobj.read().split("\n") if not s.lstrip().startswith("# ")] |
| 148 | + ) |
| 149 | + self.assertMultiLineEqual(module.as_string(), data_str) |
123 | 150 |
|
124 | 151 | def test_module2_as_string(self) -> None: |
125 | 152 | """Check as_string on a whole module prepared to be returned identically.""" |
|
0 commit comments