Skip to content

Commit d218d09

Browse files
committed
Polish literal_test.py
1 parent 0a9ea9c commit d218d09

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

rewrite/tests/python/all/tree/literal_test.py

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,76 +9,49 @@
99

1010

1111
def test_none():
12-
def after_recipe(cu):
13-
assert find_first(cu, Literal).type == JavaType.Primitive.None_
14-
1512
# language=python
16-
rewrite_run(python("assert None", after_recipe=after_recipe))
13+
rewrite_run(python("assert None", after_recipe=check_first_literal_type(JavaType.Primitive.None_)))
1714

1815

1916
def test_boolean():
20-
def after_recipe(cu):
21-
assert find_first(cu, Literal).type == JavaType.Primitive.Boolean
22-
2317
# language=python
24-
rewrite_run(python("assert True", after_recipe=after_recipe))
25-
rewrite_run(python("assert False", after_recipe=after_recipe))
18+
rewrite_run(python("assert True", after_recipe=check_first_literal_type(JavaType.Primitive.Boolean)))
19+
rewrite_run(python("assert False", after_recipe=check_first_literal_type(JavaType.Primitive.Boolean)))
2620

2721

2822
def test_dec_int():
29-
def after_recipe(cu):
30-
assert find_first(cu, Literal).type == JavaType.Primitive.Int
31-
3223
# language=python
33-
rewrite_run(python("assert 0", after_recipe=after_recipe))
24+
rewrite_run(python("assert 0", after_recipe=check_first_literal_type(JavaType.Primitive.Int)))
3425

3526

3627
def test_hex_int():
37-
def after_recipe(cu):
38-
assert find_first(cu, Literal).type == JavaType.Primitive.Int
39-
4028
# language=python
41-
rewrite_run(python("assert 0x1f", after_recipe=after_recipe))
29+
rewrite_run(python("assert 0x1f", after_recipe=check_first_literal_type(JavaType.Primitive.Int)))
4230

4331

4432
def test_fraction():
45-
def after_recipe(cu):
46-
assert find_first(cu, Literal).type == JavaType.Primitive.Double
47-
4833
# language=python
49-
rewrite_run(python("assert 0.000", after_recipe=after_recipe))
34+
rewrite_run(python("assert 0.000", after_recipe=check_first_literal_type(JavaType.Primitive.Double)))
5035

5136

5237
def test_fraction_leading_dot():
53-
def after_recipe(cu):
54-
assert find_first(cu, Literal).type == JavaType.Primitive.Double
55-
5638
# language=python
57-
rewrite_run(python("assert .0", after_recipe=after_recipe))
39+
rewrite_run(python("assert .0", after_recipe=check_first_literal_type(JavaType.Primitive.Double)))
5840

5941

6042
def test_large_int():
61-
def after_recipe(cu):
62-
assert find_first(cu, Literal).type == JavaType.Primitive.Int
63-
6443
# language=python
65-
rewrite_run(python("assert 0xC03A0019", after_recipe=after_recipe))
44+
rewrite_run(python("assert 0xC03A0019", after_recipe=check_first_literal_type(JavaType.Primitive.Int)))
6645

6746

6847
def test_byte_string_concatenation():
69-
def after_recipe(cu):
70-
assert find_first(cu, Literal).type == JavaType.Primitive.Double
71-
7248
# language=python
73-
rewrite_run(python("assert b'hello' b'world'", after_recipe=after_recipe))
49+
rewrite_run(python("assert b'hello' b'world'", after_recipe=check_first_literal_type(JavaType.Primitive.String)))
7450

7551

7652
def test_bigint():
77-
def after_recipe(cu):
78-
assert find_first(cu, Literal).type == JavaType.Primitive.Int
79-
8053
# language=python
81-
rewrite_run(python("assert 9223372036854775808", after_recipe=after_recipe))
54+
rewrite_run(python("assert 9223372036854775808", after_recipe=check_first_literal_type(JavaType.Primitive.Int)))
8255

8356

8457
def test_single_quoted_string():
@@ -194,3 +167,9 @@ def visit(self, t: Tree, p: list[Tree]) -> Optional[Tree]:
194167
found = []
195168
Find().visit(tree, found)
196169
return found[0]
170+
171+
def check_first_literal_type(expected_type):
172+
def after_recipe(cu):
173+
assert find_first(cu, Literal).type == expected_type
174+
return after_recipe
175+

0 commit comments

Comments
 (0)