forked from ucloud/ucloud-sdk-python2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_migrate.py
More file actions
44 lines (39 loc) · 1.15 KB
/
test_migrate.py
File metadata and controls
44 lines (39 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import ast
import astor
import pytest
from scripts.migrate._plugin_py3to2 import SDK3to2Transformer
@pytest.mark.parametrize(
"input_vector,expected",
[
("foo: int = 42", "foo = 42"),
("def fn(foo: str) -> int: pass", "def fn(foo):\n pass"),
("class Foo: pass", "class Foo(object):\n pass"),
("import typing", ""),
("str(value)", "unicode(value)"),
("def deco(fn: typing.Callable[[Client, dict], dict]): pass", "def deco(fn):\n pass"),
("""
def step(self, **kwargs):
def deco(fn: typing.Callable[[Client, dict], dict]):
return fn
return deco
""", """
def step(self, **kwargs):
def deco(fn):
return fn
return deco
"""),
],
)
def test_transformer(input_vector, expected):
transformer = SDK3to2Transformer()
result = transformer.convert(input_vector)
assert result == astor.to_source(ast.parse(expected))
def test_parse_ast():
input_vector = """
def step(self, **kwargs):
def deco(fn: typing.Callable[[Client, dict], dict]):
return fn
return deco
"""
node = ast.parse(input_vector)
print(astor.dump_tree(node))