def test_rewrite_docs_index( tmp_pathplus, demo_environment, file_regression: FileRegressionFixture, filename, fixed_date, ): demo_environment.globals["version"] = "1.2.3" demo_environment.globals["enable_docs"] = True demo_environment.globals["docker_shields"] = False demo_environment.globals["docker_name"] = '' demo_environment.globals["enable_pre_commit"] = True demo_environment.globals["license"] = "MIT" demo_environment.globals["primary_conda_channel"] = "octocat" demo_environment.globals["preserve_custom_theme"] = False index_file = tmp_pathplus / "doc-source" / "index.rst" index_file.parent.maybe_make() with resource(tests.test_files.test_rewrite_docs_index_input, filename) as p: index_file.write_clean(PathPlus(p).read_text()) managed_files = rewrite_docs_index(tmp_pathplus, demo_environment) assert managed_files == ["doc-source/index.rst"] check_file_output(index_file, file_regression)
def test_rewrite_readme( tmp_pathplus, demo_environment, file_regression: FileRegressionFixture, filename, fixed_date, ): demo_environment.globals["version"] = "1.2.3" demo_environment.globals["enable_docs"] = True demo_environment.globals["docker_shields"] = False demo_environment.globals["docker_name"] = '' demo_environment.globals["enable_pre_commit"] = True demo_environment.globals["license"] = "MIT" demo_environment.globals["primary_conda_channel"] = "octocat" readme_file = tmp_pathplus / "README.rst" with resource(tests.test_files.test_readme_input, filename) as p: readme_file.write_clean(PathPlus(p).read_text()) managed_files = rewrite_readme(tmp_pathplus, demo_environment) assert managed_files == ["README.rst"] check_file_output(readme_file, file_regression) rendered = render(readme_file.read_text(), stream=sys.stderr) assert rendered is not None check_file_regression(rendered, file_regression, extension=".html")
def test_conda_recipe_specifiers( tmp_pathplus, file_regression: FileRegressionFixture, example_config, ): config = example_config.replace("repo_helper_demo", "repo_helper").replace("0.0.1", "2021.3.8") (tmp_pathplus / "repo_helper.yml").write_text(config) (tmp_pathplus / "requirements.txt").write_lines([ 'apeye>=0.3.0; python_version < "3.10"', "attrs[extra]>=20.2.0", ]) with in_directory(tmp_pathplus): runner = CliRunner() result: Result = runner.invoke(make_recipe, catch_exceptions=False) assert result.exit_code == 0 if os.sep == '/': assert re.match(r"Wrote recipe to .*/conda/meta\.yaml", result.stdout) elif os.sep == '\\': assert re.match(r"Wrote recipe to .*(\\)?conda\\meta\.yaml", result.stdout.splitlines()[0]) else: raise NotImplementedError(os.sep) check_file_output(tmp_pathplus / "conda/meta.yaml", file_regression)
def check_asset_copy( func: Callable[[sphinx.application.Sphinx, Exception], Any], *asset_files: PathLike, file_regression: FileRegressionFixture, ): r""" Helper to test functions which respond to Sphinx ``build-finished`` events and copy asset files. .. versionadded:: 2.0.0 :param func: The function to test. :param \*asset_files: The paths of asset files copied by the function, relative to the Sphinx output directory. :param file_regression: """ __tracebackhide__ = True with tempfile.TemporaryDirectory() as tmpdir: tmp_pathplus = PathPlus(tmpdir) fake_app = SimpleNamespace() fake_app.builder = SimpleNamespace() fake_app.builder.format = "html" fake_app.outdir = fake_app.builder.outdir = tmp_pathplus func(fake_app, None) # type: ignore for filename in asset_files: filename = tmp_pathplus / filename check_file_output(filename, file_regression, extension=f"_{filename.stem}{filename.suffix}")
def test_make_rtfd_case_2(tmp_pathplus, demo_environment, file_regression: FileRegressionFixture): demo_environment.globals["tox_testenv_extras"] = "all" demo_environment.globals["additional_requirements_files"] = [ "hello_world/submodule/requirements.txt" ] demo_environment.globals["docs_dir"] = "userguide" managed_files = make_rtfd(tmp_pathplus, demo_environment) assert managed_files == [".readthedocs.yml"] check_file_output(tmp_pathplus / managed_files[0], file_regression)
def test_make_docs_contributing( tmp_pathplus, demo_environment, file_regression: FileRegressionFixture, standlone_contrib, ): demo_environment.globals["standalone_contrib_guide"] = standlone_contrib assert make_docs_contributing( tmp_pathplus, demo_environment) == ["doc-source/contributing.rst"] assert (tmp_pathplus / "doc-source/contributing.rst").is_file() check_file_output(tmp_pathplus / "doc-source/contributing.rst", file_regression)
def test_make_conf(tmp_pathplus, demo_environment, file_regression, theme): demo_environment.globals["sphinx_html_theme"] = theme # TODO: with values for these demo_environment.globals["html_theme_options"] = {} demo_environment.globals["sphinx_conf_preamble"] = [] demo_environment.globals["sphinx_conf_epilogue"] = [] demo_environment.globals["intersphinx_mapping"] = {} demo_environment.globals["html_context"] = {} managed_files = make_conf(tmp_pathplus, demo_environment) assert managed_files == ["doc-source/conf.py"] check_file_output(tmp_pathplus / managed_files[0], file_regression)
def test_check_file_regression(tmp_pathplus: PathPlus, file_regression: FileRegressionFixture): with pytest.raises(FileNotFoundError, match=no_such_file_pattern): check_file_output(tmp_pathplus / "file.txt", file_regression) check_file_regression("Success!\n\nThis is a test.", file_regression) result = StringList("Success!") result.blankline() result.blankline(ensure_single=True) result.append("This is a test.") check_file_regression(result, file_regression)
def test_copy_docs_styling(tmp_pathplus, demo_environment, file_regression, theme): demo_environment.globals["sphinx_html_theme"] = theme managed_files = copy_docs_styling(tmp_pathplus, demo_environment) assert managed_files == [ "doc-source/_static/style.css", "doc-source/_templates/layout.html", "doc-source/_templates/base.html", "doc-source/_templates/sidebar/navigation.html", ] for file in managed_files: if (tmp_pathplus / file).exists(): check_file_output(tmp_pathplus / file, file_regression, (tmp_pathplus / file).name) assert not (tmp_pathplus / "doc-source/_templates/sidebar/navigation.html").is_file()
def test_make_contributing(tmp_pathplus, demo_environment, file_regression: FileRegressionFixture): assert make_contributing(tmp_pathplus, demo_environment) == [ "CONTRIBUTING.rst", "CONTRIBUTING.md" ] assert not (tmp_pathplus / "CONTRIBUTING.md").is_file() assert (tmp_pathplus / "CONTRIBUTING.rst").is_file() check_file_output(tmp_pathplus / "CONTRIBUTING.rst", file_regression) (tmp_pathplus / "CONTRIBUTING.md").touch() assert (tmp_pathplus / "CONTRIBUTING.md").is_file() assert make_contributing(tmp_pathplus, demo_environment) == [ "CONTRIBUTING.rst", "CONTRIBUTING.md" ] assert not (tmp_pathplus / "CONTRIBUTING.md").is_file() assert (tmp_pathplus / "CONTRIBUTING.rst").is_file() rendered = render((tmp_pathplus / "CONTRIBUTING.rst").read_text(), stream=sys.stderr) check_file_regression(rendered, file_regression, extension=".html")
def test_conda_recipe( tmp_pathplus, file_regression: FileRegressionFixture, example_config, ): config = example_config.replace("repo_helper_demo", "repo_helper").replace("0.0.1", "2021.3.8") (tmp_pathplus / "repo_helper.yml").write_text(config) (tmp_pathplus / "requirements.txt").write_lines([ "apeye>=0.3.0", "attrs>=20.2.0", "click==7.1.2", "domdf-python-tools>=1.1.0", "dulwich>=0.19.16", "email_validator==1.1.1", "isort>=5.0.0", "jinja2>=2.11.2", "packaging>=20.4", "pre-commit>=2.7.1", "ruamel.yaml>=0.16.12", "tomlkit>=0.7.0", "typing_extensions>=3.7.4.3", ]) with in_directory(tmp_pathplus): runner = CliRunner() result: Result = runner.invoke(make_recipe, catch_exceptions=False) assert result.exit_code == 0 if os.sep == '/': assert re.match(r"Wrote recipe to .*/conda/meta\.yaml", result.stdout) elif os.sep == '\\': assert re.match(r"Wrote recipe to .*(\\)?conda\\meta\.yaml", result.stdout.splitlines()[0]) else: raise NotImplementedError(os.sep) check_file_output(tmp_pathplus / "conda/meta.yaml", file_regression)
def test_check_file_output(tmp_pathplus: PathPlus, file_regression: FileRegressionFixture): with pytest.raises(FileNotFoundError, match=no_such_file_pattern): check_file_output(tmp_pathplus / "file.txt", file_regression) (tmp_pathplus / "file.txt").write_text("Success!") check_file_output(tmp_pathplus / "file.txt", file_regression) (tmp_pathplus / "file.py").write_text("print('Success!')") check_file_output(tmp_pathplus / "file.py", file_regression)
def test_make_rtfd_case_1(tmp_pathplus, demo_environment, file_regression: FileRegressionFixture): demo_environment.globals["tox_testenv_extras"] = "all" managed_files = make_rtfd(tmp_pathplus, demo_environment) assert managed_files == [".readthedocs.yml"] check_file_output(tmp_pathplus / managed_files[0], file_regression)
def test_make_docutils_conf(tmp_pathplus, demo_environment, file_regression): managed_files = make_docutils_conf(tmp_pathplus, demo_environment) assert managed_files == ["doc-source/docutils.conf"] check_file_output(tmp_pathplus / managed_files[0], file_regression)
def test_make_gitignore(tmp_pathplus, demo_environment, file_regression: FileRegressionFixture): managed_files = make_gitignore(tmp_pathplus, demo_environment) assert managed_files == [".gitignore"] check_file_output(tmp_pathplus / managed_files[0], file_regression)
def test_init_repo( temp_empty_repo, demo_environment, file_regression, data_regression, fixed_date, ): demo_environment.globals["copyright_years"] = "2020-2021" demo_environment.globals["author"] = "Joe Bloggs" demo_environment.globals["email"] = "*****@*****.**" demo_environment.globals["license"] = "MIT License" demo_environment.globals["version"] = "1.2.3" demo_environment.globals["enable_docs"] = True demo_environment.globals["docker_shields"] = False demo_environment.globals["docker_name"] = '' demo_environment.globals["enable_pre_commit"] = True managed_files = init_repo(temp_empty_repo.path, demo_environment) for file in managed_files: assert (temp_empty_repo.path / file).exists(), file listing = [] for path in temp_empty_repo.path.rglob("*.*"): path = path.relative_to(temp_empty_repo.path) if not path.parts[0] == ".git": listing.append(path.as_posix()) listing.sort() data_regression.check(listing) # assert set(listing) == set(managed_files) assert (temp_empty_repo.path / "requirements.txt").read_text() == '' check_file_output(temp_empty_repo.path / "README.rst", file_regression, extension=".README.rst") check_file_output(temp_empty_repo.path / "LICENSE", file_regression, extension=".LICENSE.txt") assert (temp_empty_repo.path / "hello_world").is_dir() check_file_output( temp_empty_repo.path / "hello_world" / "__init__.py", file_regression, extension=".init._py_", ) assert (temp_empty_repo.path / "tests").is_dir() assert (temp_empty_repo.path / "tests/requirements.txt").read_text() == '' assert (temp_empty_repo.path / "tests" / "__init__.py").read_text() == '' assert (temp_empty_repo.path / "doc-source").is_dir() check_file_output( temp_empty_repo.path / "doc-source/index.rst", file_regression, extension=".docs_index.rst", ) assert (temp_empty_repo.path / "doc-source" / "api").is_dir() check_file_output( temp_empty_repo.path / "doc-source/api/hello-world.rst", file_regression, extension=".docs_hello-world.rst", )