示例#1
0
def run_stubtest(
    stub: str,
    runtime: str,
    options: List[str],
    config_file: Optional[str] = None,
) -> str:
    with use_tmp_dir():
        with open("builtins.pyi", "w") as f:
            f.write(stubtest_builtins_stub)
        with open("{}.pyi".format(TEST_MODULE_NAME), "w") as f:
            f.write(stub)
        with open("{}.py".format(TEST_MODULE_NAME), "w") as f:
            f.write(runtime)
        if config_file:
            with open("{}_config.ini".format(TEST_MODULE_NAME), "w") as f:
                f.write(config_file)
            options = options + [
                "--mypy-config-file", "{}_config.ini".format(TEST_MODULE_NAME)
            ]
        if sys.path[0] != ".":
            sys.path.insert(0, ".")
        if TEST_MODULE_NAME in sys.modules:
            del sys.modules[TEST_MODULE_NAME]

        output = io.StringIO()
        with contextlib.redirect_stdout(output):
            test_stubs(parse_options([TEST_MODULE_NAME] + options),
                       use_builtins_fixtures=True)

        return output.getvalue()
示例#2
0
def run_stubtest(
    stub: str,
    runtime: str,
    options: List[str],
    config_file: Optional[str] = None,
) -> str:
    with use_tmp_dir(TEST_MODULE_NAME) as tmp_dir:
        with open("builtins.pyi", "w") as f:
            f.write(stubtest_builtins_stub)
        with open("typing.pyi", "w") as f:
            f.write(stubtest_typing_stub)
        with open(f"{TEST_MODULE_NAME}.pyi", "w") as f:
            f.write(stub)
        with open(f"{TEST_MODULE_NAME}.py", "w") as f:
            f.write(runtime)
        if config_file:
            with open(f"{TEST_MODULE_NAME}_config.ini", "w") as f:
                f.write(config_file)
            options = options + [
                "--mypy-config-file", f"{TEST_MODULE_NAME}_config.ini"
            ]
        output = io.StringIO()
        with contextlib.redirect_stdout(output):
            test_stubs(parse_options([TEST_MODULE_NAME] + options),
                       use_builtins_fixtures=True)
        # remove cwd as it's not available from outside
        return output.getvalue().replace(tmp_dir + os.sep, "")
示例#3
0
def run_stubtest(stub: str, runtime: str, options: List[str]) -> str:
    with use_tmp_dir():
        with open("{}.pyi".format(TEST_MODULE_NAME), "w") as f:
            f.write(stub)
        with open("{}.py".format(TEST_MODULE_NAME), "w") as f:
            f.write(runtime)

        if sys.path[0] != ".":
            sys.path.insert(0, ".")
        if TEST_MODULE_NAME in sys.modules:
            del sys.modules[TEST_MODULE_NAME]

        output = io.StringIO()
        with contextlib.redirect_stdout(output):
            test_stubs(parse_options([TEST_MODULE_NAME] + options))

        return output.getvalue()
示例#4
0
 def test_missing_stubs(self) -> None:
     output = io.StringIO()
     with contextlib.redirect_stdout(output):
         test_stubs(parse_options(["not_a_module"]))
     assert "error: not_a_module failed to find stubs" in remove_color_code(output.getvalue())
示例#5
0
    # TODO (decorator changes argument names)
    "pandas._libs.tslibs.offsets.BaseOffset._apply_array",
    "pandas._libs.tslibs.offsets.BusinessHour.rollback",
    "pandas._libs.tslibs.offsets.BusinessHour.rollforward ",
    # type alias
    "pandas._libs.tslibs.timedeltas.UnitChoices",
]

if __name__ == "__main__":
    # find pyi files
    root = Path.cwd()
    pyi_modules = [
        str(pyi.relative_to(root).with_suffix("")).replace(os.sep, ".")
        for pyi in root.glob("pandas/**/*.pyi")
    ]

    # create allowlist
    with tempfile.NamedTemporaryFile(mode="w+t") as allow:
        allow.write("\n".join(_ALLOWLIST))
        allow.flush()

        args = pyi_modules + [
            "--ignore-missing-stub",
            "--concise",
            "--mypy-config-file",
            "pyproject.toml",
            "--allowlist",
            allow.name,
        ]
        sys.exit(stubtest.test_stubs(stubtest.parse_options(args)))
示例#6
0
 def test_typeshed(self) -> None:
     # check we don't crash while checking typeshed
     test_stubs(parse_options(["--check-typeshed"]))