コード例 #1
0
    def test_list_of_committed_files(self, temp_repo_dir):
        """Test commit_hook._get_list_of_committed_files"""

        # Test empty tree
        assert commit_hook._get_list_of_committed_files() == []

        # Create file "a"
        test_file = write_file(temp_repo_dir, "a", "foo")
        assert commit_hook._get_list_of_committed_files() == []

        # Add "a"
        cmd(temp_repo_dir, "git add " + test_file)
        assert commit_hook._get_list_of_committed_files() == [test_file]

        # Commit "a"
        cmd(temp_repo_dir, "git commit -m msg")
        assert commit_hook._get_list_of_committed_files() == []

        # Edit "a"
        write_file(temp_repo_dir, "a", "bar")
        assert commit_hook._get_list_of_committed_files() == []

        # Add "a"
        cmd(temp_repo_dir, "git add " + test_file)
        assert commit_hook._get_list_of_committed_files() == [test_file]
コード例 #2
0
    def test_is_python_file(self, temp_repo_dir):
        """Test commit_hook._is_python_file"""

        # Extension (py)
        test_file = write_file(temp_repo_dir, "a.py", "")
        assert commit_hook._is_python_file(test_file)

        # Extension (txt)
        test_file = write_file(temp_repo_dir, "a.txt", "")
        assert commit_hook._is_python_file(test_file) is False

        # Empty
        test_file = write_file(temp_repo_dir, "b", "")
        assert commit_hook._is_python_file(test_file) is False

        # Shebang
        write_file(temp_repo_dir, "b", "#!/usr/bin/env python")
        assert commit_hook._is_python_file(test_file)