File: test_gitinfo.py

package info (click to toggle)
scriv 1.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 600 kB
  • sloc: python: 3,880; makefile: 164
file content (80 lines) | stat: -rw-r--r-- 2,632 bytes parent folder | download | duplicates (2)
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
76
77
78
79
80
"""Tests of gitinfo.py"""

import re

from scriv.gitinfo import current_branch_name, get_github_repos, user_nick


def test_user_nick_from_scriv_user_nick(fake_git):
    fake_git.set_config("scriv.user-nick", "joedev")
    assert user_nick() == "joedev"


def test_user_nick_from_github(fake_git):
    fake_git.set_config("github.user", "joedev")
    assert user_nick() == "joedev"


def test_user_nick_from_git(fake_git):
    fake_git.set_config("user.email", "joesomeone@somewhere.org")
    assert user_nick() == "joesomeone"


def test_user_nick_from_env(fake_git, monkeypatch):
    monkeypatch.setenv("USER", "joseph")
    assert user_nick() == "joseph"


def test_user_nick_from_nowhere(fake_git, monkeypatch):
    # With no git information, and no USER env var,
    # we just call the user "somebody"
    monkeypatch.delenv("USER", raising=False)
    assert user_nick() == "somebody"


def test_current_branch_name(fake_git):
    fake_git.set_branch("joedev/feature-123")
    assert current_branch_name() == "joedev/feature-123"


def test_get_github_repos_no_remotes(fake_git):
    assert get_github_repos() == set()


def test_get_github_repos_one_github_remote(fake_git):
    fake_git.add_remote("mygithub", "git@github.com:joe/myproject.git")
    assert get_github_repos() == {"joe/myproject"}


def test_get_github_repos_one_github_remote_no_extension(fake_git):
    fake_git.add_remote("mygithub", "git@github.com:joe/myproject")
    assert get_github_repos() == {"joe/myproject"}


def test_get_github_repos_two_github_remotes(fake_git):
    fake_git.add_remote("mygithub", "git@github.com:joe/myproject.git")
    fake_git.add_remote("upstream", "git@github.com:psf/myproject.git")
    assert get_github_repos() == {"joe/myproject", "psf/myproject"}


def test_get_github_repos_one_github_plus_others(fake_git):
    fake_git.add_remote("mygithub", "git@github.com:joe/myproject.git")
    fake_git.add_remote("upstream", "git@gitlab.com:psf/myproject.git")
    assert get_github_repos() == {"joe/myproject"}


def test_get_github_repos_no_github_remotes(fake_git):
    fake_git.add_remote("mygitlab", "git@gitlab.com:joe/myproject.git")
    fake_git.add_remote("upstream", "git@gitlab.com:psf/myproject.git")
    assert get_github_repos() == set()


def test_real_get_github_repos():
    # Since we don't know the name of this repo (forks could be anything),
    # we can't be sure what we get, except it should be word/word, and not end
    # with .git
    repos = get_github_repos()
    assert len(repos) >= 1
    repo = repos.pop()
    assert re.fullmatch(r"[\w-]+/[\w-]+", repo)
    assert not repo.endswith(".git")