File: test_git_archive_file.py

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (75 lines) | stat: -rw-r--r-- 3,045 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import pytest


class TestGitArchiveFile:
    def test_init(self, temp_repo):
        git = temp_repo.get_repo_git()
        tmp_file = temp_repo.get_file(0)
        temp_repo.writefile(tmp_file, "data")
        git.add(".")
        git.commit("-m", "test: add data")
        git.tag("0.1.0", "-m", "bump: 0.1.0")

    def test_archive_file_on_tags_branch(self, temp_repo):
        git = temp_repo.get_repo_git()
        git.checkout("-b", "tags0.1.0")
        temp_repo.invoke_installed_extras_command("archive-file")
        filename = "{0}.{1}.zip".format(temp_repo.get_repo_dirname(), git.describe())
        assert filename in os.listdir()

    def test_archive_file_on_any_not_tags_branch_without_default_branch(
        self, temp_repo
    ):
        git = temp_repo.get_repo_git()
        git.checkout("-b", "not-tags-branch")
        temp_repo.invoke_installed_extras_command("archive-file")
        filename = "{0}.{1}.{2}.zip".format(
            temp_repo.get_repo_dirname(),
            git.describe("--always", "--long"),
            "not-tags-branch",
        )
        assert filename in os.listdir()

    def test_archive_file_on_any_not_tags_branch_with_default_branch(self, temp_repo):
        git = temp_repo.get_repo_git()
        git.checkout("default")
        git.config("git-extras.default-branch", "default")
        temp_repo.invoke_installed_extras_command("archive-file")
        filename = "{0}.{1}.zip".format(
            temp_repo.get_repo_dirname(), git.describe("--always", "--long")
        )
        assert filename in os.listdir()

    def test_archive_file_on_branch_name_has_slash(self, temp_repo):
        git = temp_repo.get_repo_git()
        git.checkout("-b", "feature/slash")
        temp_repo.invoke_installed_extras_command("archive-file")
        filename = "{0}.{1}.{2}.zip".format(
            temp_repo.get_repo_dirname(),
            git.describe("--always", "--long"),
            "feature-slash",
        )
        assert filename in os.listdir()

    @pytest.mark.parametrize("named_temp_repo", ["backslash\\dir"], indirect=True)
    def test_archive_file_on_dirname_has_backslash(self, named_temp_repo):
        named_temp_repo.invoke_installed_extras_command("archive-file")
        git = named_temp_repo.get_repo_git()
        filename = "{0}.{1}.{2}.zip".format(
            "backslash-dir", git.describe("--always", "--long"), "default"
        )
        assert filename in os.listdir()

    def test_archive_file_on_tag_name_has_slash(self, temp_repo):
        temp_repo.switch_cwd_under_repo()
        git = temp_repo.get_repo_git()
        git.checkout("default")
        git.tag("--delete", "0.1.0")
        git.tag("0.1.0/slash", "-m", "bump: 0.1.0")
        temp_repo.invoke_installed_extras_command("archive-file")
        description_include_version = git.describe("--always", "--long")
        filename = "{0}.{1}.zip".format(
            temp_repo.get_repo_dirname(), description_include_version.replace("/", "-")
        )
        assert filename in os.listdir()