예제 #1
0
def test_config_file_already_has_tool_nitpick_section(tmp_path, config_file):
    """Test if both config files already exist."""
    project = ProjectMock(tmp_path, pyproject_toml=False,
                          setup_py=True).save_file(
                              config_file,
                              f"""
        [{TOOL_NITPICK_KEY}]
        style = ['/this/should/not/be/validated-yet.toml']
        """,
                          )
    project.cli_init(
        f"The config file {config_file} already has a [{TOOL_NITPICK_KEY}] section.",
        exit_code=1)
예제 #2
0
def test_create_basic_dot_nitpick_toml(tmp_path):
    """If no config file is found, create a basic .nitpick.toml."""
    project = ProjectMock(tmp_path, pyproject_toml=False, setup_py=True)
    url = StyleManager.get_default_style_url()
    project.cli_init(
        f"A [{TOOL_NITPICK_KEY}] section was created in the config file: {DOT_NITPICK_TOML}"
    ).assert_file_contents(
        DOT_NITPICK_TOML,
        f"""
        [{TOOL_NITPICK_KEY}]
        # Generated by the 'nitpick init' command
        # More info at {READ_THE_DOCS_URL}configuration.html
        style = ['{url}']
        """,
    )
    assert url.scheme == Scheme.PY
예제 #3
0
def test_add_tool_nitpick_section_to_pyproject_toml(tmp_path, styles):
    """Add a [tool.nitpick] section to pyproject.toml."""
    project = ProjectMock(tmp_path).pyproject_toml("""
        [tool.black]
        line-length = 120
        """)
    expected = styles or [StyleManager.get_default_style_url()]

    project.cli_init(
        f"A [{TOOL_NITPICK_KEY}] section was created in the config file: {PYPROJECT_TOML}",
        *styles).assert_file_contents(
            PYPROJECT_TOML,
            f"""
        [tool.black]
        line-length = 120

        [{TOOL_NITPICK_KEY}]
        # Generated by the 'nitpick init' command
        # More info at {READ_THE_DOCS_URL}configuration.html
        style = {tomlkit.array([tomlkit.string(str(url)) for url in expected]).as_string()}
        """,
        )