tests.test_cli   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 7

4 Functions

Rating   Name   Duplication   Size   Complexity  
A location() 0 7 2
A config() 0 6 1
A describe_show() 0 18 2
A describe_edit() 0 12 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
7
from expecter import expect
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
    @patch('gitman.common.show')
31
    def it_prints_location_by_default(show, location):
32
        cli.main(['show'])
33
34
        expect(show.mock_calls) == [call(location, color='path')]
35
36
    @patch('gitman.common.show')
37
    def it_can_print_a_depenendcy_path(show, location):
38
        cli.main(['show', 'bar'])
39
40
        expect(show.mock_calls) == [call(os.path.join(location, "bar"), color='path')]
41
42
    def it_exits_when_no_config_found(tmpdir):
43
        tmpdir.chdir()
44
45
        with expect.raises(SystemExit):
46
            cli.main(['show'])
47
48
49
def describe_edit():
50
    @patch('gitman.system.launch')
51
    def it_launches_the_config(launch, config):
52
        cli.main(['edit'])
53
54
        expect(launch.mock_calls) == [call(config), call().__bool__()]
55
56
    def it_exits_when_no_config_found(tmpdir):
57
        tmpdir.chdir()
58
59
        with expect.raises(SystemExit):
60
            cli.main(['edit'])
61