def test_add_requirement( tmp_pathplus: PathPlus, requirement: str, cassette, advanced_file_regression: AdvancedFileRegressionFixture): (tmp_pathplus / "repo_helper.yml").touch() (tmp_pathplus / "requirements.txt").touch() (tmp_pathplus / "tests").mkdir() (tmp_pathplus / "tests" / "requirements.txt").touch() result: Result with in_directory(tmp_pathplus): runner = CliRunner() result = runner.invoke(add.requirement, args=requirement) assert result.exit_code == 0 advanced_file_regression.check_file(tmp_pathplus / "requirements.txt") with in_directory(tmp_pathplus): runner = CliRunner() result = runner.invoke( add.requirement, args=[requirement, "--file", "tests/requirements.txt"]) assert result.exit_code == 0 advanced_file_regression.check_file(tmp_pathplus / "tests" / "requirements.txt")
def test_make_github_docs_test( tmp_pathplus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, fail_on_warning, enable_tests: bool, ): demo_environment.globals["docs_fail_on_warning"] = fail_on_warning demo_environment.globals["enable_tests"] = enable_tests assert make_github_docs_test(tmp_pathplus, demo_environment) == [ ".github/workflows/docs_test_action.yml" ] advanced_file_regression.check_file( tmp_pathplus / ".github/workflows/docs_test_action.yml") demo_environment.globals["enable_docs"] = False assert make_github_docs_test(tmp_pathplus, demo_environment) == [ ".github/workflows/docs_test_action.yml" ] assert not (tmp_pathplus / ".github/workflows/docs_test_action.yml").is_file() assert not (tmp_pathplus / ".github/workflows/docs_test_action.yml").exists() demo_environment.globals["enable_docs"] = True assert make_github_docs_test(tmp_pathplus, demo_environment) == [ ".github/workflows/docs_test_action.yml" ] advanced_file_regression.check_file( tmp_pathplus / ".github/workflows/docs_test_action.yml")
def test_suggest_classifiers_add_existing(tmp_pathplus, advanced_file_regression: AdvancedFileRegressionFixture): (tmp_pathplus / "repo_helper.yml").write_lines([ "modname: repo_helper", 'copyright_years: "2020"', 'author: "Dominic Davis-Foster"', 'email: "*****@*****.**"', 'version: "0.0.1"', 'username: "******"', "license: 'LGPLv3+'", "short_desc: 'Update multiple configuration files, build scripts etc. from a single location.'", '', "classifiers:", " - 'Framework :: Flake8'", " - 'Intended Audience :: Developers'", ]) (tmp_pathplus / "requirements.txt").touch() (tmp_pathplus / "repo_helper").mkdir() with in_directory(tmp_pathplus): runner = CliRunner() result: Result = runner.invoke( suggest.classifiers, catch_exceptions=False, args=["-s", '4', "-l", "--add"] ) assert result.exit_code == 0 advanced_file_regression.check_file(tmp_pathplus / "repo_helper.yml")
def test_github_ci_windows_38( tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, ): demo_environment.globals["github_ci_requirements"] = { "macOS": { "pre": [], "post": [] } } demo_environment.globals["travis_additional_requirements"] = [ "isort", "black" ] demo_environment.globals["platforms"] = ["macOS"] demo_environment.globals["pure_python"] = False demo_environment.globals["py_versions"] = ["3.6", "3.7", "3.8"] managed_files = make_github_ci(tmp_pathplus, demo_environment) advanced_file_regression.check_file(tmp_pathplus / managed_files[1]) demo_environment.globals["py_versions"] = ["3.6", "3.7"] managed_files = make_github_ci(tmp_pathplus, demo_environment) advanced_file_regression.check_file(tmp_pathplus / managed_files[1])
def test_make_github_manylinux( tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, platforms, py_versions, ): demo_environment.globals["platforms"] = platforms demo_environment.globals["pure_python"] = False demo_environment.globals["py_versions"] = py_versions assert make_github_manylinux(tmp_pathplus, demo_environment) == [ ".github/workflows/manylinux_build.yml" ] advanced_file_regression.check_file( tmp_pathplus / ".github/workflows/manylinux_build.yml") demo_environment.globals["platforms"] = ["Windows"] assert make_github_manylinux(tmp_pathplus, demo_environment) == [ ".github/workflows/manylinux_build.yml" ] assert not (tmp_pathplus / ".github/workflows/manylinux_build.yml").is_file()
def test_dump_minify(advanced_file_regression: AdvancedFileRegressionFixture, tmp_pathplus: PathPlus): stylesheet: Dict[str, Style] = { ".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" }, } css = dumps(stylesheet, minify=True) advanced_file_regression.check(css, extension=".css") output_file = tmp_pathplus / "style.css" with output_file.open('w') as fp: dump(stylesheet, fp, minify=True) advanced_file_regression.check_file(output_file) dump(stylesheet, output_file, minify=True) advanced_file_regression.check_file(output_file)
def test_write_metadata( builder, advanced_file_regression: AdvancedFileRegressionFixture): (builder.repo_dir / "requirements.txt").write_lines([ "alabaster>=0.7.12", "autodocsumm>=0.2.0", "default-values>=0.2.0", "extras-require>=0.2.0", "seed-intersphinx-mapping>=0.1.1", "sphinx>=3.0.3,<3.4.0", "sphinx-copybutton>=0.2.12", "sphinx-notfound-page>=0.5", "sphinx-prompt>=1.1.0", "sphinx-tabs>=1.1.13", "sphinx-toolbox>=1.7.1", "sphinxcontrib-httpdomain>=1.7.0", "sphinxemoji>=0.1.6", "toctree-plus>=0.0.4", ]) (builder.repo_dir / "README.rst").write_text("""\ ============= Readme ============ This is the readme. """) builder.write_metadata(metadata_file=builder.build_dir / "METADATA") assert (builder.build_dir / "METADATA").exists() assert (builder.build_dir / "METADATA").is_file() advanced_file_regression.check_file(builder.build_dir / "METADATA")
def test_dumps_media(advanced_file_regression: AdvancedFileRegressionFixture, tmp_pathplus: PathPlus): stylesheet: Dict[str, MutableMapping] = { ".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) } }, } css = dumps(stylesheet, trailing_semicolon=True) advanced_file_regression.check(css, extension=".css") output_file = tmp_pathplus / "style.css" with output_file.open('w') as fp: dump(stylesheet, fp, trailing_semicolon=True) advanced_file_regression.check_file(output_file) dump(stylesheet, output_file, trailing_semicolon=True) advanced_file_regression.check_file(output_file)
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])
def test_reformat( tmp_pathplus: PathPlus, toml_string: str, cli_runner: CliRunner, advanced_file_regression: AdvancedFileRegressionFixture, show_diff: bool, ): (tmp_pathplus / "pyproject.toml").write_clean(toml_string) (tmp_pathplus / "README.rst").write_clean("This is the README") (tmp_pathplus / "LICENSE").write_clean("This is the LICENSE") if show_diff: args = ["--no-colour", "--show-diff"] else: args = [] with in_directory(tmp_pathplus): result: Result = cli_runner.invoke(reformat, args=args, catch_exceptions=False) assert result.exit_code == 1 advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml") result.check_stdout(advanced_file_regression, extension=".diff") # Should be no changes with in_directory(tmp_pathplus): result = cli_runner.invoke(reformat, args=args, catch_exceptions=False) assert result.exit_code == 0 advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml") assert result.stdout == "Reformatting 'pyproject.toml'\n"
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_cli_verbose_verbose( tmp_pathplus: PathPlus, advanced_file_regression: AdvancedFileRegressionFixture, advanced_data_regression: AdvancedDataRegressionFixture, demo_environment, ): result: Result with in_directory(tmp_pathplus): runner = CliRunner(mix_stderr=False) result = runner.invoke( main, args=["code.py", "--no-colour", "--diff", "--verbose", "-v"], ) assert result.exit_code == 1 advanced_file_regression.check_file(tmp_pathplus / "code.py") # Calling a second time shouldn't change anything with in_directory(tmp_pathplus): runner = CliRunner(mix_stderr=False) result = runner.invoke( main, args=[ "code.py", "code.c", "--no-colour", "--diff", "--verbose", "-v" ], ) assert result.exit_code == 0 check_out(result, advanced_data_regression)
def test_pylintrc( tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, ): managed_files = make_pylintrc(tmp_pathplus, demo_environment) assert managed_files == [".pylintrc"] advanced_file_regression.check_file(tmp_pathplus / managed_files[0])
def test_imgbot(tmp_pathplus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, ignore): demo_environment.globals["imgbot_ignore"] = ignore managed_files = make_imgbot(tmp_pathplus, demo_environment) assert managed_files == [".imgbotconfig"] advanced_file_regression.check_file(tmp_pathplus / managed_files[0], extension=".json")
def test_write_wheel(builder, advanced_file_regression: AdvancedFileRegressionFixture, data_regression: DataRegressionFixture): builder.write_wheel() advanced_file_regression.check_file(builder.dist_info / "WHEEL") # Check the file can be read by EmailMessage with (builder.dist_info / "WHEEL").open() as fp: data = message_from_file(fp) data_regression.check(dict(data))
def test_tox_mypy_version( self, tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, mypy_version, ): self.set_globals(demo_environment, mypy_version=mypy_version) make_tox(tmp_pathplus, demo_environment) advanced_file_regression.check_file(tmp_pathplus / "tox.ini")
def test_tox_stubs_package( self, tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, stubs_package, ): self.set_globals(demo_environment, stubs_package=stubs_package) make_tox(tmp_pathplus, demo_environment) advanced_file_regression.check_file(tmp_pathplus / "tox.ini")
def test_tox_enable_tests( self, tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, enable_tests, ): self.set_globals(demo_environment, enable_tests=enable_tests) make_tox(tmp_pathplus, demo_environment) advanced_file_regression.check_file(tmp_pathplus / "tox.ini")
def test_make_github_flake8( tmp_pathplus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, ): assert make_github_flake8( tmp_pathplus, demo_environment) == [".github/workflows/flake8.yml"] assert (tmp_pathplus / ".github/workflows/flake8.yml").is_file() advanced_file_regression.check_file(tmp_pathplus / ".github/workflows/flake8.yml")
def test_file2dataframe(tmp_pathplus: PathPlus, advanced_file_regression: AdvancedFileRegressionFixture): area_file = PathPlus(__file__).parent / "area.csv" file2dataframe(area_file).to_csv( tmp_pathplus / "area.csv", index=False, na_rep="NA", float_format=MaxPrecisionFloatFormat(3), ) advanced_file_regression.check_file(tmp_pathplus / "area.csv")
def test_make_github_mypy( tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, platforms, ): demo_environment.globals["platforms"] = platforms assert make_github_mypy( tmp_pathplus, demo_environment) == [".github/workflows/mypy.yml"] assert (tmp_pathplus / ".github/workflows/mypy.yml").is_file() advanced_file_regression.check_file(tmp_pathplus / ".github/workflows/mypy.yml")
def test_write(data, tmp_pathplus, advanced_file_regression: AdvancedFileRegressionFixture, filename): data.write(tmp_pathplus / "jcamp_gcms_data") # Errors for obj in [*test_sequences, test_dict, *test_numbers]: with pytest.raises(TypeError): data.write(obj) # Read file and check values assert (tmp_pathplus / filename).exists() advanced_file_regression.check_file(tmp_pathplus / filename)
def test_dumps( tmp_pathplus: PathPlus, toml_string: str, advanced_file_regression: AdvancedFileRegressionFixture, ): (tmp_pathplus / "pyproject.toml").write_clean(toml_string) config = PyProject.load(filename=tmp_pathplus / "pyproject.toml") config.dump(tmp_pathplus / "pyproject.toml") advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml") advanced_file_regression.check(config.dumps(), extension=".toml")
def test_make_docs_license_rst( tmp_pathplus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, ): demo_environment.globals["license"] = "MIT License" (tmp_pathplus / "doc-source").mkdir() managed_files = make_docs_license_rst(tmp_pathplus, demo_environment) assert managed_files == ["doc-source/license.rst"] assert (tmp_pathplus / managed_files[0]).is_file() advanced_file_regression.check_file(tmp_pathplus / managed_files[0])
def test_make_github_octocheese( tmp_pathplus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture): assert make_github_octocheese(tmp_pathplus, demo_environment) == [ ".github/workflows/octocheese.yml" ] assert (tmp_pathplus / ".github/workflows/octocheese.yml").is_file() advanced_file_regression.check_file(tmp_pathplus / ".github/workflows/octocheese.yml") demo_environment.globals["on_pypi"] = False assert make_github_octocheese(tmp_pathplus, demo_environment) == [ ".github/workflows/octocheese.yml" ] assert not (tmp_pathplus / ".github/workflows/octocheese.yml").exists()
def test_write_intensities_stream( data, tmp_pathplus, advanced_file_regression: AdvancedFileRegressionFixture): filename = "jcamp_intensity_stream.csv" data.write_intensities_stream(tmp_pathplus / "jcamp_intensity_stream.csv") # Errors for obj in [*test_sequences, test_dict, *test_numbers]: with pytest.raises(TypeError): data.write_intensities_stream(obj) # Read file and check values assert (tmp_pathplus / filename).exists() advanced_file_regression.check_file(tmp_pathplus / filename)
def test_make_pcdl_csv( tmp_pathplus: PathPlus, advanced_file_regression: AdvancedFileRegressionFixture, dataframe_regression: DataFrameRegressionFixture, pcdl_cassette, ): df = make_pcdl_csv(target_compounds, tmp_pathplus / "all_compounds_pcdl.csv") advanced_file_regression.check_file(tmp_pathplus / "all_compounds_pcdl.csv", extension="_csv.csv") dataframe_regression.check(df)
def test_make_pre_commit( tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, ): # TODO: permutations to cover all branches demo_environment.globals["yapf_exclude"] = [] demo_environment.globals["pre_commit_exclude"] = "^$" (tmp_pathplus / ".pre-commit-config.yaml").touch() managed_files = make_pre_commit(tmp_pathplus, demo_environment) assert managed_files == [".pre-commit-config.yaml"] advanced_file_regression.check_file(tmp_pathplus / managed_files[0])
def test_reformat( tmp_pathplus: PathPlus, toml_string: str, advanced_file_regression: AdvancedFileRegressionFixture, ): (tmp_pathplus / "pyproject.toml").write_clean(toml_string) (tmp_pathplus / "README.rst").write_clean("This is the README") (tmp_pathplus / "LICENSE").write_clean("This is the LICENSE") PyProject.reformat(tmp_pathplus / "pyproject.toml") advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml") # Should be no changes PyProject.reformat(tmp_pathplus / "pyproject.toml") advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml")
def test_ensure_bumpversion_remove_setup_cfg( tmp_pathplus: PathPlus, demo_environment, advanced_file_regression: AdvancedFileRegressionFixture, ): demo_environment.globals["version"] = "1.2.3" demo_environment.globals["enable_docs"] = True demo_environment.globals["use_whey"] = False ensure_bumpversion(tmp_pathplus, demo_environment) demo_environment.globals["use_whey"] = True ensure_bumpversion(tmp_pathplus, demo_environment) advanced_file_regression.check_file(tmp_pathplus / ".bumpversion.cfg")