Test that if annotation references type from same module but using full path, no module will be imported, and type specification will be striped to local reference.
(self)
| 1237 | assert_equal(gen.get_imports().splitlines(), ["import argparse"]) |
| 1238 | |
| 1239 | def test_generate_c_function_same_module(self) -> None: |
| 1240 | """Test that if annotation references type from same module but using full path, no module |
| 1241 | will be imported, and type specification will be striped to local reference. |
| 1242 | """ |
| 1243 | |
| 1244 | # Provide different type in python spec than in docstring to make sure, that docstring |
| 1245 | # information is used. |
| 1246 | def test(arg0: str) -> None: |
| 1247 | """ |
| 1248 | test(arg0: argparse.Action) -> argparse.Action |
| 1249 | """ |
| 1250 | |
| 1251 | output: list[str] = [] |
| 1252 | mod = ModuleType("argparse", "") |
| 1253 | gen = InspectionStubGenerator(mod.__name__, known_modules=[mod.__name__], module=mod) |
| 1254 | gen.generate_function_stub("test", test, output=output) |
| 1255 | assert_equal(output, ["def test(arg0: Action) -> Action: ..."]) |
| 1256 | assert_equal(gen.get_imports().splitlines(), []) |
| 1257 | |
| 1258 | def test_generate_c_function_other_module(self) -> None: |
| 1259 | """Test that if annotation references type from other module, module will be imported.""" |
nothing calls this directly
no test coverage detected