-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
test_vcs.py
103 lines (78 loc) · 2.79 KB
/
test_vcs.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#
"""
Tests for vcs.py
"""
# Standard library imports
import os
import os.path as osp
import sys
# Test library imports
from spyder.utils import programs
import pytest
# Local imports
from spyder.utils.vcs import (ActionToolNotFound, get_git_refs,
get_git_remotes, get_git_revision, get_vcs_root,
remote_to_url, run_vcs_tool)
HERE = os.path.abspath(os.path.dirname(__file__))
skipnogit = pytest.mark.skipif(not(get_vcs_root(HERE)),
reason="Not running from a git repo")
@skipnogit
@pytest.mark.skipif(os.environ.get('CI', None) is None,
reason="Not to be run outside of CIs")
def test_vcs_tool():
if not os.name == 'nt':
with pytest.raises(ActionToolNotFound):
run_vcs_tool(osp.dirname(__file__), 'browse')
else:
assert run_vcs_tool(osp.dirname(__file__), 'browse')
assert run_vcs_tool(osp.dirname(__file__), 'commit')
@skipnogit
def test_vcs_root(tmpdir):
directory = tmpdir.mkdir('foo')
assert get_vcs_root(str(directory)) == None
assert get_vcs_root(osp.dirname(__file__)) != None
@skipnogit
@pytest.mark.skipif(os.name == 'nt' and os.environ.get('AZURE') is not None,
reason="Fails on Windows/Azure")
def test_git_revision():
root = get_vcs_root(osp.dirname(__file__))
assert get_git_revision(osp.dirname(__file__)) == (None, None)
assert all([isinstance(x, str) for x in get_git_revision(root)])
def test_no_git(monkeypatch):
def mockreturn(program_name):
return None
monkeypatch.setattr(programs, 'find_program', mockreturn)
branch_tags, branch, files_modified = get_git_refs(__file__)
assert len(branch_tags) == 0
assert branch == ''
assert len(files_modified) == 0
@skipnogit
def test_get_git_refs():
branch_tags, branch, files_modified = get_git_refs(__file__)
assert bool(branch) # This must always return a branch_name
assert len(files_modified) >= 0
assert any([('master' in b or '4.x' in b) for b in branch_tags])
@skipnogit
def test_get_git_remotes():
remotes = get_git_remotes(HERE)
assert 'origin' in remotes
@pytest.mark.parametrize(
'input_text, expected_output',
[
('https://github.com/neophnx/spyder.git',
'https://github.com/neophnx/spyder'),
('http://github.com/neophnx/spyder.git',
'http://github.com/neophnx/spyder'),
('git@github.com:goanpeca/spyder.git',
'https://github.com/goanpeca/spyder'),
]
)
def test_remote_to_url(input_text, expected_output):
output = remote_to_url(input_text)
assert expected_output == output
if __name__ == "__main__":
pytest.main()