예제 #1
0
    def get_filenames_from_paths(self):
        """Find all files to measure for docstring coverage."""
        filenames = []
        for path in self.paths:
            if os.path.isfile(path):
                if not path.endswith(".py"):
                    msg = (
                        "E: Invalid file '{}'. Unable interrogate non-Python "
                        "files.".format(path)
                    )
                    click.echo(msg, err=True)
                    return sys.exit(1)
                filenames.append(path)
                continue
            for root, dirs, fs in os.walk(path):
                full_paths = [os.path.join(root, f) for f in fs]
                filenames.extend(self._filter_files(full_paths))

        if not filenames:
            p = ", ".join(self.paths)
            msg = "E: No Python files found to interrogate in '{}'.".format(p)
            click.echo(msg, err=True)
            return sys.exit(1)

        self.common_base = utils.get_common_base(filenames)
        return filenames
예제 #2
0
def test_get_common_base_windows(files, side_effect, expected, mocker,
                                 monkeypatch):
    """Return common base of a set of files/directories, if any."""
    mock_exists = mocker.Mock(side_effect=side_effect)
    monkeypatch.setattr(utils.pathlib.Path, "exists", mock_exists)
    actual = utils.get_common_base(files)
    assert expected == actual
예제 #3
0
def test_get_common_base(files, expected):
    """Return common base of a set of files/directories, if any."""
    actual = utils.get_common_base(files)
    assert expected == actual