Exemplo n.º 1
0
    def test_should_return_command_that_list_all_changed_files(self):
        mode = Branch([])
        command = mode.command()

        assert isinstance(command, list)
        assert mode.command() == [
            "git", "diff", "--name-only", "--relative", "master"
        ]
Exemplo n.º 2
0
    def test_should_return_command_that_list_all_changed_files_for_different_branch(
        self,
    ):
        mode = Branch([], "main")
        command = mode.command()

        assert isinstance(command, list)
        assert mode.command() == ["git", "diff", "--name-status", "--relative", "main"]
Exemplo n.º 3
0
    def test_should_only_list_pytest_root_changed_files(self, git_repository, testdir):
        git_repository.join("test_gitroot").new(ext="py").write(b"", "wb")
        pytestroot = git_repository.mkdir("pytestroot")
        pytestroot.join("test_pytestroot").new(ext="py").write(b"", "wb")
        assert testdir.run("git", "add", ".").ret == 0

        output = set(Branch([]).git_output().splitlines())
        assert output == {
            "A       test_gitroot.py",
            "A       pytestroot/test_pytestroot.py",
        }

        pytestroot.chdir()
        output = set(Branch([]).git_output().splitlines())
        assert output == {"A       test_pytestroot.py"}
Exemplo n.º 4
0
    def test_should_list_branch_changed_files_as_affected_tests(self):
        raw_output = (b"pytest_picked.py\n" +
                      b"tests/test_pytest_picked.py\n" +
                      b"tests/test_other_module.py")
        test_file_convention = ["test_*.py", "*_test.py"]

        with patch("pytest_picked.modes.subprocess.run") as subprocess_mock:
            subprocess_mock.return_value.stdout = raw_output
            mode = Branch(test_file_convention)
            files, folders = mode.affected_tests()

        expected_files = [
            "tests/test_pytest_picked.py", "tests/test_other_module.py"
        ]
        expected_folders = []

        assert files == expected_files
        assert folders == expected_folders
Exemplo n.º 5
0
    def test_should_only_list_pytestroot_changed_files(self, email, testdir):
        gitroot = testdir.mkdir("gitroot")
        gitroot.chdir()
        try:
            assert testdir.run("git", "init").ret == 0
        except FileNotFoundError:
            pytest.skip("required executable 'git' not found")
        assert testdir.run("git", "commit", "--allow-empty", "-m_").ret == 0

        gitroot.join("test_gitroot").new(ext="py").write(b"", "wb")
        pytestroot = gitroot.mkdir("pytestroot")
        pytestroot.join("test_pytestroot").new(ext="py").write(b"", "wb")
        assert testdir.run("git", "add", ".").ret == 0

        output = set(Branch([]).git_output().splitlines())
        assert output == {"test_gitroot.py", "pytestroot/test_pytestroot.py"}

        pytestroot.chdir()
        output = set(Branch([]).git_output().splitlines())
        assert output == {"test_pytestroot.py"}
Exemplo n.º 6
0
    def test_parser_should_return_the_candidate_itself(self):
        mode = Branch([])
        line = "tests/test_pytest_picked.py\n"
        parsed_line = mode.parser(line)

        assert parsed_line == line
Exemplo n.º 7
0
    def test_should_list_changed_files(self, testdir, git_repository):
        git_repository.join("test_gitroot").new(ext="py").write(b"", "wb")
        assert testdir.run("git", "add", ".").ret == 0

        output = set(Branch([]).git_output().splitlines())
        assert output == {"A       test_gitroot.py"}
Exemplo n.º 8
0
    def test_parser_should_ignore_no_paths_characters(self, line, expected_line):
        mode = Branch([])
        parsed_line = mode.parser(line)

        assert parsed_line == expected_line