Passed
Push — develop ( 4d6495...2dddb7 )
by Jace
03:19
created

tests.test_cli   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 7

4 Functions

Rating   Name   Duplication   Size   Complexity  
A location() 0 7 2
A describe_show() 0 21 2
A config() 0 6 1
A describe_edit() 0 13 2
1
# pylint: disable=unused-variable,redefined-outer-name,expression-not-assigned
2
3
import os
4
from unittest.mock import call, patch
5
6
import pytest
0 ignored issues
show
introduced by
Unable to import 'pytest'
Loading history...
7
from expecter import expect
0 ignored issues
show
introduced by
Unable to import 'expecter'
Loading history...
8
9
from gitman import cli
10
11
12
@pytest.fixture
13
def config(tmpdir):
14
    tmpdir.chdir()
15
    path = str(tmpdir.join("gdm.yml"))
16
    open(path, 'w').close()
17
    return path
18
19
20
@pytest.fixture
21
def location(tmpdir):
22
    tmpdir.chdir()
23
    path = str(tmpdir.join("gdm.yml"))
24
    with open(path, 'w') as outfile:
25
        outfile.write("location: foo")
26
    return str(tmpdir.join("foo"))
27
28
29
def describe_show():
30
31
    @patch('gitman.common.show')
32
    def it_prints_location_by_default(show, location):
33
        cli.main(['show'])
34
35
        expect(show.mock_calls) == [call(location, color='path')]
36
37
    @patch('gitman.common.show')
38
    def it_can_print_a_depenendcy_path(show, location):
39
        cli.main(['show', 'bar'])
40
41
        expect(show.mock_calls) == [
42
            call(os.path.join(location, "bar"), color='path'),
43
        ]
44
45
    def it_exits_when_no_config_found(tmpdir):
46
        tmpdir.chdir()
47
48
        with expect.raises(SystemExit):
49
            cli.main(['show'])
50
51
52
def describe_edit():
53
54
    @patch('gitman.system.launch')
55
    def it_launches_the_config(launch, config):
56
        cli.main(['edit'])
57
58
        expect(launch.mock_calls) == [call(config), call().__bool__()]
59
60
    def it_exits_when_no_config_found(tmpdir):
61
        tmpdir.chdir()
62
63
        with expect.raises(SystemExit):
64
            cli.main(['edit'])
65