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
|
|
|
|