コード例 #1
0
ファイル: test_snakefmt.py プロジェクト: ctb/snakefmt
    def test_includeOnlySnakefiles_returnsOnlySnakefiles(
            self, mock_gitignore: mock.MagicMock):
        mock_gitignore.match_file.return_value = False
        include = re.compile(r"(\.smk$|^Snakefile)")
        exclude = re.compile(r"")

        with tempfile.TemporaryDirectory() as tmpdir:
            abs_tmpdir = Path(tmpdir).resolve()
            self.create_temp_filesystem_in(abs_tmpdir)
            snakefiles = get_snakefiles_in_dir(
                path=Path(tmpdir),
                root=abs_tmpdir,
                include=include,
                exclude=exclude,
                gitignore=mock_gitignore,
            )

            actual = Counter(snakefiles)
            expected = Counter(abs_tmpdir / p for p in [
                "Snakefile",
                "Snakefile-dev",
                "rules/map.smk",
                "rules/test/test.smk",
            ])

            assert actual == expected
コード例 #2
0
ファイル: test_snakefmt.py プロジェクト: pascal-git/snakefmt
    def test_includeAllFiles_returnAll(self, mock_gitignore: mock.MagicMock):
        mock_gitignore.match_file.return_value = False
        include = re.compile(r".*")
        exclude = re.compile(r"")

        with tempfile.TemporaryDirectory() as tmpdir:
            abs_tmpdir = Path(tmpdir).resolve()
            self.create_temp_filesystem_in(abs_tmpdir)
            snakefiles = get_snakefiles_in_dir(
                path=Path(tmpdir),
                include=include,
                exclude=exclude,
                gitignore=mock_gitignore,
            )

            actual = Counter(snakefiles)
            expected = Counter(Path(tmpdir) / p for p in self.filesystem)

            assert actual == expected
コード例 #3
0
 def find_files_to_format(self,
                          include,
                          exclude,
                          gitignore,
                          gitignored: Optional[str] = None):
     with tempfile.TemporaryDirectory() as tmpdir:
         abs_tmpdir = Path(tmpdir).resolve()
         self.create_temp_filesystem_in(abs_tmpdir)
         if gitignored is not None:
             with (abs_tmpdir / ".gitignore").open("w") as fout:
                 fout.write(gitignored)
             gitignore = get_gitignore(abs_tmpdir)
         snakefiles = get_snakefiles_in_dir(
             path=abs_tmpdir,
             include=include,
             exclude=exclude,
             gitignore=gitignore,
         )
         snakefiles = list(
             map(lambda p: str(p.relative_to(abs_tmpdir)), snakefiles))
     return Counter(snakefiles)