Exemple #1
0
def test_iterchildren_match(
        advanced_data_regression: AdvancedDataRegressionFixture,
        absolute: bool):
    repo_path = PathPlus(__file__).parent.parent
    with in_directory(repo_path.parent):

        assert repo_path.is_dir()

        if not absolute:
            repo_path = repo_path.relative_to(repo_path.parent)

        if (repo_path / "build").is_dir():
            shutil.rmtree(repo_path / "build")

        children = list(repo_path.iterchildren(match="**/*.py"))
        assert children

        child_paths = sorted(
            p.relative_to(repo_path).as_posix() for p in children)

        for exclude_filename in {
                ".coverage", "pathtype_demo.py", "dist", "htmlcov", "conda",
                ".idea", "mutdef.py"
        }:
            if exclude_filename in child_paths:
                child_paths.remove(exclude_filename)

        advanced_data_regression.check(child_paths,
                                       basename="test_iterchildren_match")
Exemple #2
0
def test_visitor(advanced_data_regression: AdvancedDataRegressionFixture):
    example_source = """

	import builtins, io

	source = open("source.py")


	def foo():

		result = builtins.open("source.py")
		result = io.open("source.py")
		result = open("source.py", encoding=None)


	class F:

		def foo():
			result = open("source.py", encoding="utf-8")
			result = open("source.py", mode="rb")

		def read(mode: str = "r"):
			result = open("source.py", mode=mode)

	"""

    visitor = Visitor()
    visitor.visit(ast.parse(dedent(example_source)))
    advanced_data_regression.check(visitor.errors)
def test_make_github_linux_case_2(
    tmp_pathplus: PathPlus,
    demo_environment,
    advanced_file_regression: AdvancedFileRegressionFixture,
    advanced_data_regression: AdvancedDataRegressionFixture,
):

    demo_environment.globals["platforms"] = ["Linux"]
    demo_environment.globals["travis_ubuntu_version"] = "bionic"
    demo_environment.globals["github_ci_requirements"] = {
        "Linux": {
            "pre": ["sudo apt update"],
            "post": ["sudo apt install python3-gi"]
        }
    }
    demo_environment.globals["travis_additional_requirements"] = [
        "isort", "black"
    ]
    demo_environment.globals["enable_tests"] = False
    demo_environment.globals["enable_conda"] = False
    demo_environment.globals["enable_releases"] = False

    managed_files = make_github_ci(tmp_pathplus, demo_environment)
    advanced_data_regression.check(managed_files,
                                   basename="github_ci_managed_files")
    assert not (tmp_pathplus / managed_files[0]).is_file()
    assert not (tmp_pathplus / managed_files[1]).is_file()
    assert (tmp_pathplus / managed_files[2]).is_file()

    advanced_file_regression.check_file(tmp_pathplus / managed_files[2])
def test_make_github_linux_case_3(
    tmp_pathplus: PathPlus,
    advanced_file_regression: AdvancedFileRegressionFixture,
    demo_environment,
    pure_python,
    enable_conda,
    enable_tests,
    enable_releases,
    advanced_data_regression: AdvancedDataRegressionFixture,
):

    demo_environment.globals["platforms"] = ["Linux"]
    demo_environment.globals["pure_python"] = pure_python
    demo_environment.globals["enable_tests"] = enable_conda
    demo_environment.globals["enable_conda"] = enable_tests
    demo_environment.globals["enable_releases"] = enable_releases

    managed_files = make_github_ci(tmp_pathplus, demo_environment)
    advanced_data_regression.check(managed_files,
                                   basename="github_ci_managed_files")

    assert not (tmp_pathplus / managed_files[0]).is_file()
    assert not (tmp_pathplus / managed_files[1]).is_file()
    assert (tmp_pathplus / managed_files[2]).is_file()

    advanced_file_regression.check_file(tmp_pathplus / managed_files[2])
Exemple #5
0
def test_plugin(tmp_pathplus: PathPlus,
                advanced_data_regression: AdvancedDataRegressionFixture):
    example_source = """

	import builtins, io

	source = open("source.py")


	def foo():

		result = builtins.open("source.py")
		result = io.open("source.py")
		result = open("source.py", encoding=None)


	class F:

		def foo():
			result = open("source.py", encoding="utf-8")
			result = open("source.py", mode="rb")

		def read(mode: str = "r"):
			result = open("source.py", mode=mode)

	"""

    (tmp_pathplus / "code.py").write_clean(example_source)
    plugin = Plugin(ast.parse(dedent(example_source)),
                    filename=tmp_pathplus / "code.py")
    advanced_data_regression.check(
        list("{}:{}: {}".format(*r) for r in plugin.run()))
Exemple #6
0
def test_discover_entry_points_by_name_object_match_func(
        advanced_data_regression: AdvancedDataRegressionFixture):
    entry_points = discover_entry_points_by_name(
        "flake8.extension",
        object_match_func=lambda f: f.__name__.startswith("break"))
    advanced_data_regression.check(
        {k: v.__name__
         for k, v in entry_points.items()})
Exemple #7
0
def test_iterchildren(advanced_data_regression: AdvancedDataRegressionFixture):
    repo_path = PathPlus(__file__).parent.parent
    assert repo_path.is_dir()

    children = list((repo_path / "domdf_python_tools").iterchildren())
    assert children
    advanced_data_regression.check(
        sorted(p.relative_to(repo_path).as_posix() for p in children))
def test_render_rst_error(
        capsys, advanced_data_regression: AdvancedDataRegressionFixture):
    pytest.importorskip("readme_renderer")

    with pytest.raises(BadConfigError, match="Error rendering README."):
        render_rst(".. seealso::")  # A sphinx directive

    advanced_data_regression.check(capsys.readouterr())
Exemple #9
0
def test_discover_entry_points_by_name_name_match_func(
        advanced_data_regression: AdvancedDataRegressionFixture):
    entry_points = discover_entry_points_by_name(
        "flake8.extension",
        name_match_func=lambda n: n.startswith("pycodestyle."))
    advanced_data_regression.check(
        {k: v.__name__
         for k, v in entry_points.items()})
def test_quartile_outliers(
        data, advanced_data_regression: AdvancedDataRegressionFixture):
    outliers, data_exc_outliers = quartile_outliers(data)
    advanced_data_regression.check({
        "outliers":
        list(to_std_nums(outliers)),
        "data_exc_outliers":
        list(to_std_nums(data_exc_outliers)),
    })
Exemple #11
0
def test_parse_valid_config(
    toml_config: str,
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
):
    (tmp_pathplus / "pyproject.toml").write_clean(toml_config)
    config = PEP621Parser().parse(
        dom_toml.loads(toml_config, decoder=TomlPureDecoder)["project"])
    advanced_data_regression.check(config)
Exemple #12
0
def test_build_additional_files(
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
    file_regression: FileRegressionFixture,
    capsys,
):

    (tmp_pathplus / "pyproject.toml").write_lines([
        COMPLETE_A,
        '',
        "additional-wheel-files = [",
        '  "include _virtualenv.py",',
        ']',
    ])
    (tmp_pathplus / "whey").mkdir()
    (tmp_pathplus / "whey" / "__init__.py").write_clean("print('hello world)")
    (tmp_pathplus /
     "_virtualenv.py").write_clean("This is the _virtualenv.py file")
    (tmp_pathplus / "README.rst").write_clean("Spam Spam Spam Spam")
    (tmp_pathplus / "LICENSE").write_clean("This is the license")
    (tmp_pathplus / "requirements.txt").write_clean("domdf_python_tools")

    data = {}

    with tempfile.TemporaryDirectory() as tmpdir:
        wheel_builder = PthWheelBuilder(
            project_dir=tmp_pathplus,
            config=load_toml(tmp_pathplus / "pyproject.toml"),
            build_dir=tmpdir,
            out_dir=tmp_pathplus,
            verbose=True,
            colour=False,
        )
        wheel = wheel_builder.build_wheel()
        assert (tmp_pathplus / wheel).is_file()
        zip_file = zipfile.ZipFile(tmp_pathplus / wheel)
        data["wheel_content"] = sorted(zip_file.namelist())

        with zip_file.open("whey/__init__.py", mode='r') as fp:
            assert fp.read().decode("UTF-8") == "print('hello world)\n"

        with zip_file.open("whey-2021.0.0.dist-info/METADATA", mode='r') as fp:
            check_file_regression(fp.read().decode("UTF-8"), file_regression)

        with zip_file.open("my_project.pth", mode='r') as fp:
            assert fp.read().decode("UTF-8") == "import _virtualenv\n"

        with zip_file.open("_virtualenv.py", mode='r') as fp:
            assert fp.read().decode(
                "UTF-8") == "This is the _virtualenv.py file\n"

    outerr = capsys.readouterr()
    data["stdout"] = outerr.out.replace(tmp_pathplus.as_posix(), "...")
    data["stderr"] = outerr.err

    advanced_data_regression.check(data)
def test_mad_outliers(data,
                      advanced_data_regression: AdvancedDataRegressionFixture,
                      threshold: int):
    outliers, data_exc_outliers = mad_outliers(data, threshold=threshold)
    advanced_data_regression.check({
        "outliers":
        list(to_std_nums(outliers)),
        "data_exc_outliers":
        list(to_std_nums(data_exc_outliers)),
    })
def test_parse_config(
    tmp_pathplus: PathPlus,
    config: str,
    size: int,
    advanced_data_regression: AdvancedDataRegressionFixture,
):
    (tmp_pathplus / "pyproject.toml").write_text(config)

    loaded_config = SphinxConfig(tmp_pathplus / "pyproject.toml")
    advanced_data_regression.check(loaded_config)
    assert len(loaded_config) == size
def test_spss_outliers(
        data, advanced_data_regression: AdvancedDataRegressionFixture):
    extremes, outliers, data_exc_outliers = spss_outliers(data)
    advanced_data_regression.check({
        "extremes":
        list(to_std_nums(extremes)),
        "outliers":
        list(to_std_nums(outliers)),
        "data_exc_outliers":
        list(to_std_nums(data_exc_outliers)),
    })
Exemple #16
0
def test_importchecker(
    tmp_pathplus: PathPlus,
    advanced_file_regression: AdvancedFileRegressionFixture,
    advanced_data_regression: AdvancedDataRegressionFixture,
    modules: Iterable[str],
    show: bool,
) -> None:

    checker = ImportChecker(modules, show=show)

    advanced_data_regression.check(dict(checker.check_modules()))
    advanced_file_regression.check(checker.format_statistics())
Exemple #17
0
def test_custom_pyproject_class(
    toml_config: str,
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
):

    (tmp_pathplus / "pyproject.toml").write_clean(toml_config)

    with in_directory(tmp_pathplus):
        config = WheyPyProject.load(tmp_pathplus / "pyproject.toml")

    advanced_data_regression.check(config.to_dict())
def test_pep621_subclass(
    toml_config: str,
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
):

    (tmp_pathplus / "pyproject.toml").write_clean(toml_config)

    with in_directory(tmp_pathplus):
        config = ReducedPEP621Parser().parse(
            dom_toml.load(tmp_pathplus / "pyproject.toml")["project"])

    advanced_data_regression.check(config)
Exemple #19
0
def test_valid_config_resolve_files(
    toml_config: str,
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
):

    (tmp_pathplus / "pyproject.toml").write_clean(toml_config)
    (tmp_pathplus / "README.rst").write_clean("This is the README")
    (tmp_pathplus / "LICENSE").write_clean("This is the LICENSE")

    with in_directory(tmp_pathplus):
        config = PyProject.load(tmp_pathplus / "pyproject.toml")
        config.resolve_files()

    advanced_data_regression.check(config.to_dict())
def test_buildsystem_parser_valid_config(
    toml_config: str,
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
    set_defaults: bool,
):
    (tmp_pathplus / "pyproject.toml").write_clean(toml_config)
    config = BuildSystemParser().parse(
        dom_toml.load(tmp_pathplus / "pyproject.toml")["build-system"],
        set_defaults=set_defaults,
    )

    config["requires"] = list(map(str, config["requires"]))  # type: ignore

    advanced_data_regression.check(config)
Exemple #21
0
def test_hidden_cursor(
        monkeypatch, capsys,
        advanced_data_regression: AdvancedDataRegressionFixture):
    monkeypatch.setattr(consolekit.terminal_colours, "resolve_color_default",
                        lambda *args: True)

    hide_cursor()
    show_cursor()

    with hidden_cursor():
        click.echo(f"\r{next(solidus_spinner)}", nl=False)
        click.echo(f"\r{next(solidus_spinner)}", nl=False)
        click.echo(f"\r{next(solidus_spinner)}", nl=False)

    advanced_data_regression.check(tuple(capsys.readouterr()))
def test_pep621_class_valid_config(
    toml_config: str,
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
    set_defaults: bool,
):

    (tmp_pathplus / "pyproject.toml").write_clean(toml_config)

    with in_directory(tmp_pathplus):
        config = PEP621Parser().parse(
            dom_toml.load(tmp_pathplus / "pyproject.toml")["project"],
            set_defaults=set_defaults,
        )

    advanced_data_regression.check(config)
Exemple #23
0
def test_greppy_summary(
    cloned_repos: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
    capsys,
    search_term: str,
    fixed_sort_order,
):

    data = {}

    greppy(search_term, cloned_repos, summary=True)

    outerr = capsys.readouterr()
    data["stdout"] = outerr.out.replace(cloned_repos.as_posix(), "...")
    data["stderr"] = outerr.err.replace(cloned_repos.as_posix(), "...")
    advanced_data_regression.check(data)
def test_loads(advanced_data_regression: AdvancedDataRegressionFixture,
               tmp_pathplus: PathPlus):
    style = [
        ".wy-nav-content {",
        "    max-width: 1200rem !important;",
        "    }",
        '',
        "li p:last-child {",
        "    margin-bottom: 12em !important;",
        "    margin-top: 6em;",
        "    }",
        '',
        "@media screen {",
        "    html {",
        "        scroll-behavior: smooth;",
        "        }",
        '}',
    ]

    advanced_data_regression.check(loads('\n'.join(style)))

    stylesheet: Mapping[str, Mapping] = {
        ".wy-nav-content": {
            "max-width": (rem(1200), IMPORTANT)
        },
        "li p:last-child": {
            "margin-bottom": (em(12), IMPORTANT),
            "margin-top": em(6),
        },
        "html": {
            "scroll-behavior": "smooth"
        },
        "@media screen and (min-width: 870px)": {
            "li p:last-child": {
                "max-width": (rem(1200), IMPORTANT)
            }
        },
    }

    assert loads(dumps(stylesheet)) == stylesheet

    style_file = tmp_pathplus / "style.css"
    dump(stylesheet, style_file)
    assert load(style_file) == stylesheet

    with style_file.open() as fp:
        assert load(fp) == stylesheet
Exemple #25
0
def test_greppy_summary(
		cloned_repos: PathPlus,
		advanced_data_regression: AdvancedDataRegressionFixture,
		capsys,
		search_term: str,
		fixed_sort_order,
		):

	runner = CliRunner(mix_stderr=False)
	result = runner.invoke(main, args=[search_term, "--dir", cloned_repos.as_posix()])

	data = {}

	data["stdout"] = result.stdout.replace(cloned_repos.as_posix(), "...")
	data["stderr"] = result.stderr.replace(cloned_repos.as_posix(), "...")

	advanced_data_regression.check(data)
def test_pep621_class_valid_config_license_dict(
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
):

    (tmp_pathplus / "pyproject.toml").write_lines([
        f'[project]',
        f'name = "spam"',
        f'version = "2020.0.0"',
        f'license = {{text = "This is the MIT License"}}',
    ])

    with in_directory(tmp_pathplus):
        config = PEP621Parser().parse(
            dom_toml.load(tmp_pathplus / "pyproject.toml")["project"])

    advanced_data_regression.check(config)
Exemple #27
0
def test_make_github_linux_case_1(
    tmp_pathplus: PathPlus,
    demo_environment,
    advanced_file_regression: AdvancedFileRegressionFixture,
    advanced_data_regression: AdvancedDataRegressionFixture,
):

    demo_environment.globals["platforms"] = ["Linux"]

    managed_files = make_github_ci(tmp_pathplus, demo_environment)
    advanced_data_regression.check(managed_files,
                                   basename="github_ci_managed_files")
    assert not (tmp_pathplus / managed_files[0]).is_file()
    assert not (tmp_pathplus / managed_files[1]).is_file()
    assert (tmp_pathplus / managed_files[2]).is_file()

    advanced_file_regression.check_file(tmp_pathplus / managed_files[2])
Exemple #28
0
def test_importchecker_errors_show(
    tmp_pathplus: PathPlus,
    advanced_file_regression: AdvancedFileRegressionFixture,
    advanced_data_regression: AdvancedDataRegressionFixture,
    version: str,
    show: bool,
) -> None:

    checker = ImportChecker(
        [
            "collections", "i_dont_exist", "this-is&invalid",
            "domdf_python_tools", "coincidence"
        ],
        show=show,
    )

    advanced_data_regression.check(dict(checker.check_modules()))
    advanced_file_regression.check(checker.format_statistics())
def check_out(result: Union[Result, CaptureResult[str]],
              advanced_data_regression: AdvancedDataRegressionFixture):

    if hasattr(result, "stdout"):
        stdout = result.stdout
    else:
        stdout = result.out

    if hasattr(result, "stderr"):
        stderr = result.stderr
    else:
        stderr = result.err

    data_dict = {
        "out": strip_ansi(path_sub.sub(" ...", stdout)).split('\n'),
        "err": strip_ansi(path_sub.sub(" ...", stderr)).split('\n'),
    }

    advanced_data_regression.check(data_dict)
def test_pep621_class_valid_config_readme(
    filename: str,
    tmp_pathplus: PathPlus,
    advanced_data_regression: AdvancedDataRegressionFixture,
):

    (tmp_pathplus / "pyproject.toml").write_lines([
        "[project]",
        'name = "spam"',
        'version = "2020.0.0"',
        f'readme = {filename!r}',
    ])
    (tmp_pathplus / filename).write_text("This is the readme.")

    with in_directory(tmp_pathplus):
        config = PEP621Parser().parse(
            dom_toml.load(tmp_pathplus / "pyproject.toml")["project"])

    advanced_data_regression.check(config)