@@ -59,6 +59,37 @@ def test_make_constant_invalid() -> None:
59
59
ast_utils .make_constant (object ())
60
60
61
61
62
+ @test_utils .require_at_most (7 )
63
+ @pytest .mark .parametrize (
64
+ "value,expected" ,
65
+ [
66
+ (ast .Bytes (s = b"foo" ), True ),
67
+ (ast .Constant ("bar" ), True ),
68
+ (ast .Ellipsis (), True ),
69
+ (ast .NameConstant (value = None ), True ),
70
+ (ast .Num (n = 123 ), True ),
71
+ (ast .Str (s = "baz" ), True ),
72
+ (ast .Expr (value = ast .Num (456 )), False ),
73
+ (ast .Global ("qux" ), False ),
74
+ ],
75
+ )
76
+ def test_is_constant_legacy (value : ast .AST , expected : bool ) -> None :
77
+ assert ast_utils .is_constant (value ) is expected
78
+
79
+
80
+ @test_utils .require_at_least (8 )
81
+ @pytest .mark .parametrize (
82
+ "value,expected" ,
83
+ [
84
+ (ast .Constant ("foo" ), True ),
85
+ (ast .Expr (value = ast .Constant (123 )), False ),
86
+ (ast .Global ("bar" ), False ),
87
+ ],
88
+ )
89
+ def test_is_constant (value : ast .AST , expected : bool ) -> None :
90
+ assert ast_utils .is_constant (value ) is expected
91
+
92
+
62
93
def test_extract_int_or_none () -> None :
63
94
assert ast_utils .extract_int_or_none (ast_utils .make_constant (- 123 )) == - 123
64
95
assert ast_utils .extract_int_or_none (ast_utils .make_constant (0 )) == 0
0 commit comments