-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97c6c52
commit 1c2c80f
Showing
8 changed files
with
212 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""tests for python code. any tests for typescript code should go in | ||
`packages/pyright-internal/src/tests` instead""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
these tests assume that the doc stubs have already run (they should get run as part of | ||
`pdm install`) as they validate that the current state of the `docstubs` folder is correct | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
import sys | ||
from functools import wraps | ||
from locale import getpreferredencoding | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, Callable | ||
|
||
from pytest import mark | ||
|
||
if TYPE_CHECKING: | ||
from basedtyping import P, T | ||
|
||
|
||
def needs_all_docstubs( | ||
condition_to_run_locally: bool, # noqa: FBT001 | ||
) -> Callable[[Callable[P, T]], Callable[P, T]]: | ||
def decorator(fn: Callable[P, T]) -> Callable[P, T]: | ||
@wraps(fn) | ||
@mark.needs_all_docstubs | ||
@mark.skipif( | ||
not condition_to_run_locally and not os.getenv("GITHUB_ACTIONS"), | ||
reason="condition not met", | ||
) | ||
def wrapped(*args: P.args, **kwargs: P.kwargs): | ||
return fn(*args, **kwargs) | ||
|
||
return wrapped | ||
|
||
return decorator | ||
|
||
|
||
def read_module_text(name: str): | ||
return Path("docstubs/stdlib", name).read_text( | ||
encoding=getpreferredencoding(do_setlocale=False) | ||
) | ||
|
||
|
||
def test_builtin_docstring(): | ||
assert ''' | ||
class float: | ||
"""Convert a string or number to a floating point number, if possible.""" | ||
''' in read_module_text("builtins.pyi") | ||
|
||
|
||
@needs_all_docstubs(sys.platform == "win32") | ||
def test_windows_only_docstring(): | ||
assert read_module_text("nt.pyi").startswith('''""" | ||
This module provides access to operating system functionality that is | ||
standardized by the C Standard and the POSIX standard (a thinly | ||
disguised Unix interface). Refer to the library manual and | ||
corresponding Unix manual entries for more information on calls. | ||
"""''') | ||
|
||
|
||
@needs_all_docstubs(sys.platform != "win32") | ||
def test_linux_or_mac_only_docstring(): | ||
assert ''' | ||
def tzset() -> None: | ||
""" | ||
tzset() | ||
Initialize, or reinitialize, the local timezone to the value stored in | ||
os.environ['TZ']. The TZ environment variable should be specified in | ||
standard Unix timezone format as documented in the tzset man page | ||
(eg. 'US/Eastern', 'Europe/Amsterdam'). Unknown timezones will silently | ||
fall back to UTC. If the TZ environment variable is not set, the local | ||
timezone is set to the systems best guess of wallclock time. | ||
Changing the TZ environment variable without calling tzset *may* change | ||
the local timezone used by methods such as localtime, but this behaviour | ||
should not be relied on. | ||
""" | ||
''' in read_module_text("time.pyi") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
from subprocess import run | ||
|
||
|
||
def test_version(): | ||
"""pretty useless test, this is mainly just making sure the python wrapper scripts aren't | ||
busted""" | ||
result = run(["basedpyright", "--version"], check=True, capture_output=True) | ||
assert result.returncode == 0 | ||
assert result.stdout.startswith(b"basedpyright ") | ||
assert b"based on pyright " in result.stdout |