Skip to content

Commit 8d477de

Browse files
Add coverage
1 parent f5e7021 commit 8d477de

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tests/test_nodes.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
transforms,
2929
util,
3030
)
31-
from astroid.const import PY310_PLUS, Context
31+
from astroid.const import PY310_PLUS, PY312_PLUS, Context
3232
from astroid.context import InferenceContext
3333
from astroid.exceptions import (
3434
AstroidBuildingError,
@@ -279,6 +279,31 @@ def test_as_string_unknown() -> None:
279279
assert nodes.Unknown(lineno=1, col_offset=0).as_string() == "Unknown.Unknown()"
280280

281281

282+
@pytest.mark.skipif(not PY312_PLUS, reason="Uses 3.12 type param nodes")
283+
class AsStringTypeParamNodes(unittest.TestCase):
284+
@staticmethod
285+
def test_as_string_type_alias() -> None:
286+
ast = abuilder.string_build("type Point = tuple[float, float]")
287+
assert ast.as_string().strip() == "Point"
288+
289+
@staticmethod
290+
def test_as_string_type_var() -> None:
291+
ast = abuilder.string_build("type Point[T] = tuple[float, float]")
292+
type_var = ast.body[0].type_params[0]
293+
assert type_var.as_string().strip() == "T"
294+
295+
@staticmethod
296+
def test_as_string_type_var_tuple() -> None:
297+
ast = abuilder.string_build("type Alias[*Ts] = tuple[*Ts]")
298+
type_var_tuple = ast.body[0].type_params[0]
299+
assert type_var_tuple.as_string().strip() == "*Ts"
300+
301+
@staticmethod
302+
def test_as_string_param_spec() -> None:
303+
ast = abuilder.string_build("type Alias[**P] = Callable[P, int]")
304+
assert ast.as_string().strip() == "Alias"
305+
306+
282307
class _NodeTest(unittest.TestCase):
283308
"""Test transformation of If Node."""
284309

0 commit comments

Comments
 (0)