Beispiel #1
0
    def flake8(self, offline=False, file_index: int = 0) -> "ProjectMock":
        """Simulate a manual flake8 run.

        - Recreate the global app.
        - Change the working dir to the mocked project root.
        - Lint one of the project files. If no index is provided, use the default file that's always created.
        """
        os.chdir(str(self.root_dir))
        NitpickApp.create_app(offline)

        npc = NitpickExtension(filename=str(self.files_to_lint[file_index]))
        self._original_errors = list(npc.run())

        self._errors = set()
        for flake8_error in self._original_errors:
            line, col, message, class_ = flake8_error
            if not (line == 0 and col == 0 and message.startswith(ERROR_PREFIX)
                    and class_ is NitpickExtension):
                raise AssertionError()
            self._errors.add(message)
        return self
Beispiel #2
0
    "package-json.toml": "package.json_",
    "poetry.toml": "Poetry_",
    "pre-commit/bash.toml": "Bash_",
    "pre-commit/commitlint.toml": "commitlint_",
    "pre-commit/general.toml": "pre-commit_ (hooks)",
    "pre-commit/main.toml": "pre-commit_ (main)",
    "pre-commit/python.toml": "pre-commit_ (Python hooks)",
    "pylint.toml": "Pylint_",
    "pytest.toml": "pytest_",
    "python35-36-37.toml": "Python 3.5, 3.6 or 3.7",
    "python35-36-37-38.toml": "Python 3.5, 3.6, 3.7 to 3.8",
    "python36-37.toml": "Python 3.6 or 3.7",
    "python36.toml": "Python 3.6",
    "python37.toml": "Python 3.7",
})
app = NitpickApp.create_app()

divider = ".. auto-generated-from-here"
docs_dir = Path(__file__).parent.absolute()  # type: Path
styles_dir = docs_dir.parent / "styles"  # type: Path


def write_rst(rst_file: Path, blocks: List[str]):
    """Write content to the .rst file."""
    old_content = rst_file.read_text()
    cut_position = old_content.index(divider)
    new_content = old_content[:cut_position + len(divider) + 1]
    new_content += "\n".join(blocks)
    rst_file.write_text(new_content.strip() + "\n")
    click.secho("{} generated".format(rst_file), fg="green")