|
7 | 7 | __author__ = "Guido U. Draheim" |
8 | 8 | __version__ = "1.1.1127" |
9 | 9 |
|
| 10 | +from typing import cast |
10 | 11 | import sys |
11 | 12 | import unittest |
12 | 13 | import logging |
13 | 14 | import os.path |
14 | 15 | from fnmatch import fnmatchcase as fnmatch |
| 16 | +import ast |
15 | 17 |
|
16 | 18 | logg = logging.getLogger(os.path.basename(__file__)) |
17 | 19 |
|
@@ -90,6 +92,112 @@ def test_1112(self) -> None: |
90 | 92 | self.assertEqual(c, "a\nb\n") |
91 | 93 | self.assertEqual(d, "a\n b\n") |
92 | 94 | self.assertEqual(e, "a\n b\n") |
| 95 | + def test_1201(self) -> None: |
| 96 | + other = ast.Constant(1) # unknown element |
| 97 | + have: ast.Module = app.pyi_module([other]) |
| 98 | + have0 = cast(ast.Constant, have.body[0]) |
| 99 | + self.assertEqual(other.value, have0.value) |
| 100 | + def test_1210(self) -> None: |
| 101 | + pyi = ast.parse(app.text4(""" |
| 102 | + def foo(a: A) -> B: |
| 103 | + pass |
| 104 | + """)) |
| 105 | + py1 = ast.parse(app.text4(""" |
| 106 | + from x import A |
| 107 | + """)) |
| 108 | + py2 = ast.parse(app.text4(""" |
| 109 | + from y import B |
| 110 | + """)) |
| 111 | + want = app.text4(""" |
| 112 | + from x import A |
| 113 | + from y import B |
| 114 | +
|
| 115 | + def foo(a: A) -> B: |
| 116 | + pass""") |
| 117 | + pyi2 = app.pyi_copy_imports(pyi, py1, py2) |
| 118 | + have = ast.unparse(pyi2) + "\n" |
| 119 | + self.assertEqual(want, have) |
| 120 | + def test_1211(self) -> None: |
| 121 | + pyi = ast.parse(app.text4(""" |
| 122 | + def foo(a: A) -> B: |
| 123 | + pass |
| 124 | + """)) |
| 125 | + py1 = ast.parse(app.text4(""" |
| 126 | + from x.z import A |
| 127 | + """)) |
| 128 | + py2 = ast.parse(app.text4(""" |
| 129 | + from y.z import B |
| 130 | + """)) |
| 131 | + want = app.text4(""" |
| 132 | + from x.z import A |
| 133 | + from y.z import B |
| 134 | +
|
| 135 | + def foo(a: A) -> B: |
| 136 | + pass""") |
| 137 | + pyi2 = app.pyi_copy_imports(pyi, py1, py2) |
| 138 | + have = ast.unparse(pyi2) + "\n" |
| 139 | + self.assertEqual(want, have) |
| 140 | + def test_1212(self) -> None: |
| 141 | + pyi = ast.parse(app.text4(""" |
| 142 | + def foo(a: x.A) -> y.B: |
| 143 | + pass |
| 144 | + """)) |
| 145 | + py1 = ast.parse(app.text4(""" |
| 146 | + import x |
| 147 | + """)) |
| 148 | + py2 = ast.parse(app.text4(""" |
| 149 | + import y |
| 150 | + """)) |
| 151 | + want = app.text4(""" |
| 152 | + import x, y |
| 153 | +
|
| 154 | + def foo(a: x.A) -> y.B: |
| 155 | + pass""") |
| 156 | + pyi2 = app.pyi_copy_imports(pyi, py1, py2) |
| 157 | + have = ast.unparse(pyi2) + "\n" |
| 158 | + self.assertEqual(want, have) |
| 159 | + def test_1213(self) -> None: |
| 160 | + pyi = ast.parse(app.text4(""" |
| 161 | + def foo(a: x.A) -> y.B: |
| 162 | + pass |
| 163 | + """)) |
| 164 | + py1 = ast.parse(app.text4(""" |
| 165 | + import app1.x as x |
| 166 | + """)) |
| 167 | + py2 = ast.parse(app.text4(""" |
| 168 | + import app2.y as y |
| 169 | + """)) |
| 170 | + want = app.text4(""" |
| 171 | + from app1 import x |
| 172 | + from app2 import y |
| 173 | +
|
| 174 | + def foo(a: x.A) -> y.B: |
| 175 | + pass""") |
| 176 | + pyi2 = app.pyi_copy_imports(pyi, py1, py2) |
| 177 | + have = ast.unparse(pyi2) + "\n" |
| 178 | + self.assertEqual(want, have) |
| 179 | + @unittest.expectedFailure |
| 180 | + def test_1215(self) -> None: |
| 181 | + pyi = ast.parse(app.text4(""" |
| 182 | + def foo(a: app1.x.A) -> app2.y.B: |
| 183 | + pass |
| 184 | + """)) |
| 185 | + py1 = ast.parse(app.text4(""" |
| 186 | + import app1.x |
| 187 | + """)) |
| 188 | + py2 = ast.parse(app.text4(""" |
| 189 | + import app2.y |
| 190 | + """)) |
| 191 | + want = app.text4(""" |
| 192 | + import app1.x |
| 193 | + import app2.y |
| 194 | +
|
| 195 | + def foo(a: app1.x.A) -> app2.y.B: |
| 196 | + pass""") |
| 197 | + pyi2 = app.pyi_copy_imports(pyi, py1, py2) |
| 198 | + have = ast.unparse(pyi2) + "\n" |
| 199 | + self.assertEqual(want, have) |
| 200 | + |
93 | 201 |
|
94 | 202 | if __name__ == "__main__": |
95 | 203 | # unittest.main() |
|
0 commit comments