Skip to content

Commit 83f0763

Browse files
SONARPY-1342 Improve typeshed unit test to avoid serializing Typeshed (#1448)
1 parent 0f14f79 commit 83f0763

File tree

15 files changed

+816
-1
lines changed

15 files changed

+816
-1
lines changed

python-frontend/typeshed_serializer/tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
@pytest.fixture(scope="session")
3333
def typeshed_stdlib():
34+
typeshed_serializer.STDLIB_PATH = "resources/mock_stdlib"
35+
typeshed_serializer.CURRENT_PATH = CURRENT_PATH
3436
build_result, _ = typeshed_serializer.walk_typeshed_stdlib()
3537
return build_result
3638

@@ -55,6 +57,7 @@ def fake_module_36_38():
5557

5658
@pytest.fixture(scope="session")
5759
def typeshed_third_parties():
60+
typeshed_serializer.THIRD_PARTIES_STUBS = os.listdir(os.path.join(CURRENT_PATH, "resources/mock_third_parties"))
5861
return symbols_merger.merge_multiple_python_versions(is_third_parties=True)
5962

6063

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from _typeshed import SupportsWrite
2+
from typing import Any, Callable, Dict, Tuple, Type, TypeVar
3+
4+
_T = TypeVar("_T")
5+
_FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
6+
7+
# These definitions have special processing in mypy
8+
class ABCMeta(type):
9+
__abstractmethods__: frozenset[str]
10+
def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> None: ...
11+
def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ...
12+
def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ...
13+
def _dump_registry(cls: ABCMeta, file: SupportsWrite[str] | None = ...) -> None: ...
14+
def register(cls: ABCMeta, subclass: Type[_T]) -> Type[_T]: ...
15+
16+
def abstractmethod(funcobj: _FuncT) -> _FuncT: ...
17+
18+
class abstractproperty(property): ...
19+
20+
# These two are deprecated and not supported by mypy
21+
def abstractstaticmethod(callable: _FuncT) -> _FuncT: ...
22+
def abstractclassmethod(callable: _FuncT) -> _FuncT: ...
23+
24+
class ABC(metaclass=ABCMeta): ...
25+
26+
def get_cache_token() -> object: ...
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from typing import IO, Any, Callable, List, Optional, Tuple
2+
3+
class Cmd:
4+
prompt: str
5+
identchars: str
6+
ruler: str
7+
lastcmd: str
8+
intro: Optional[Any]
9+
doc_leader: str
10+
doc_header: str
11+
misc_header: str
12+
undoc_header: str
13+
nohelp: str
14+
use_rawinput: bool
15+
stdin: IO[str]
16+
stdout: IO[str]
17+
cmdqueue: List[str]
18+
completekey: str
19+
def __init__(self, completekey: str = ..., stdin: Optional[IO[str]] = ..., stdout: Optional[IO[str]] = ...) -> None: ...
20+
old_completer: Optional[Callable[[str, int], Optional[str]]]
21+
def cmdloop(self, intro: Optional[Any] = ...) -> None: ...
22+
def precmd(self, line: str) -> str: ...
23+
def postcmd(self, stop: bool, line: str) -> bool: ...
24+
def preloop(self) -> None: ...
25+
def postloop(self) -> None: ...
26+
def parseline(self, line: str) -> Tuple[Optional[str], Optional[str], str]: ...
27+
def onecmd(self, line: str) -> bool: ...
28+
def emptyline(self) -> bool: ...
29+
def default(self, line: str) -> bool: ...
30+
def completedefault(self, *ignored: Any) -> List[str]: ...
31+
def completenames(self, text: str, *ignored: Any) -> List[str]: ...
32+
completion_matches: Optional[List[str]]
33+
def complete(self, text: str, state: int) -> Optional[List[str]]: ...
34+
def get_names(self) -> List[str]: ...
35+
# Only the first element of args matters.
36+
def complete_help(self, *args: Any) -> List[str]: ...
37+
def do_help(self, arg: str) -> Optional[bool]: ...
38+
def print_topics(self, header: str, cmds: Optional[List[str]], cmdlen: Any, maxcol: int) -> None: ...
39+
def columnize(self, list: Optional[List[str]], displaywidth: int = ...) -> None: ...

0 commit comments

Comments
 (0)