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_no_line_wrapping( self, advanced_file_regression: AdvancedFileRegressionFixture): r""" Validate behavior when a \b character is present. https://click.palletsprojects.com/en/7.x/documentation/#preventing-rewrapping """ @click.group() def cli(): """ A sample command group. \b This is a paragraph without rewrapping. And this is a paragraph that will be rewrapped again. """ ctx = click.Context(cli, info_name="cli") output = list( sphinx_click._format_command(ctx, nested=sphinx_click.NESTED_SHORT)) advanced_file_regression.check('\n'.join(output), extension=".rst")
def test_basic_parameters( self, advanced_file_regression: AdvancedFileRegressionFixture): """ Validate a combination of parameters. This exercises the code paths for a command with arguments, options and environment variables. """ @click.command() @click.option("--param", envvar="PARAM", help="A sample option") @click.option("--another", metavar="[FOO]", help="Another option") @click.option( "--choice", help="A sample option with choices", type=click.Choice(["Option1", "Option2"]), ) @click.argument("ARG", envvar="ARG") def foobar(bar): """ A sample command. """ ctx = click.Context(foobar, info_name="foobar") output = list( sphinx_click._format_command(ctx, nested=sphinx_click.NESTED_SHORT)) advanced_file_regression.check('\n'.join(output), extension=".rst")
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_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_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])
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_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_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_get_fact( date: Tuple, advanced_file_regression: AdvancedFileRegressionFixture, monkeypatched_requests, monkeypatch, ) -> None: with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=UserWarning) clear_cache() class MockedDate(datetime.date): @classmethod def today(cls): return datetime.date(2020, 12, 28) monkeypatch.setattr(datetime, "date", MockedDate) add = lambda args: '\n'.join(args) advanced_file_regression.check(add(get_fact(*date))) # Subsequent runs to test cache advanced_file_regression.check(add(get_fact(*date))) advanced_file_regression.check(add(get_fact(*date))) assert RequestsURL.get.call_count == 1 # type: ignore[attr-defined]
def test_titles(self, advanced_file_regression: AdvancedFileRegressionFixture): """ Validate a `click.Command` with nested titles. """ @click.command() @click.option("--name", help="Name to say hello to.", required=True, type=str) def hello(name): """ Prints hello to name given. Examples -------- .. code:: bash my_cli hello --name "Jack" """ ctx = click.Context(hello, info_name="hello") output = list( sphinx_click._format_command(ctx, nested=sphinx_click.NESTED_SHORT)) advanced_file_regression.check('\n'.join(output), extension=".rst")
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_click_event_handler( peak_list, capsys, advanced_file_regression: AdvancedFileRegressionFixture, ): fig, ax = plt.subplots() # Setup up the ClickEventHandler handler = ClickEventHandler(peak_list, fig, ax) assert handler.fig is fig assert handler.ax is ax assert handler.cid is not None callbacks: CallbackRegistry = fig.canvas.callbacks assert "button_press_event" in callbacks.callbacks event = MouseEvent("button_press_event", fig.canvas, peak_list[0].rt, 100, button=1) event.xdata = peak_list[0].rt # FIXME callbacks.process("button_press_event", event) advanced_file_regression.check(capsys.readouterr().out)
def test_chainmap(self, advanced_file_regression: AdvancedFileRegressionFixture): d: collections.ChainMap = collections.ChainMap() assert FancyPrinter(width=1).pformat(d) == "ChainMap({})" words = "the quick brown fox jumped over a lazy dog".split() items = list(zip(words, itertools.count())) d = collections.ChainMap(dict(items)) advanced_file_regression.check(FancyPrinter().pformat(d))
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_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_ordered_dict(self, advanced_file_regression: AdvancedFileRegressionFixture): d: collections.OrderedDict = collections.OrderedDict() assert FancyPrinter(width=1).pformat(d) == "OrderedDict()" d = collections.OrderedDict([]) assert FancyPrinter(width=1).pformat(d) == "OrderedDict()" words = "the quick brown fox jumped over a lazy dog".split() d = collections.OrderedDict(zip(words, itertools.count())) advanced_file_regression.check(FancyPrinter().pformat(d))
def test_main_help(capsys, advanced_file_regression: AdvancedFileRegressionFixture): runner = CliRunner() result: Result = runner.invoke(main, catch_exceptions=False, args=["-h"]) advanced_file_regression.check(result.stdout) result = runner.invoke(main, catch_exceptions=False, args=["--help"]) advanced_file_regression.check(result.stdout)
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_rate_limit( github_manager, capsys, advanced_file_regression: AdvancedFileRegressionFixture, ): with echo_rate_limit(github_manager.github): pass advanced_file_regression.check(capsys.readouterr().out)
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_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_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_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_simple_repr(advanced_file_regression: AdvancedFileRegressionFixture): @simple_repr('a', 'b', 'c', 'd', width=10) class F: a = "apple" b = "banana" c = "cherry" d = list(range(100)) advanced_file_regression.check(repr(F()))
def test_isort_stubs(advanced_file_regression: AdvancedFileRegressionFixture): source = StringList([ 'from natsort.natsort import as_ascii as as_ascii, as_utf8 as as_utf8, decoder as decoder, humansorted as ' 'humansorted, index_humansorted as index_humansorted, index_natsorted as index_natsorted, index_realsorted as ' 'index_realsorted, natsort_key as natsort_key, natsort_keygen as natsort_keygen, natsorted as natsorted, ns as ns, ' 'numeric_regex_chooser as numeric_regex_chooser, order_by_index as order_by_index, os_sort_key as os_sort_key, ' 'os_sort_keygen as os_sort_keygen, os_sorted as os_sorted, realsorted as realsorted', "from natsort.utils import chain_functions as chain_functions", '', ]) advanced_file_regression.check(isort_hook(str(source), "utils.pyi"))
def test_create_readme_install_block( advanced_file_regression: AdvancedFileRegressionFixture, kwargs): result = create_readme_install_block(**kwargs) advanced_file_regression.check(result, extension=".rst") with pytest.raises( ValueError, match= "Please supply a list of 'conda_channels' if Conda builds are supported" ): create_readme_install_block(modname="hello_world", username="******")
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")