forked from psss/did
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cli.py
62 lines (50 loc) · 1.83 KB
/
test_cli.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
# coding: utf-8
""" Tests for the command line script """
import os
import re
import pytest
import did.cli
import did.base
import did.utils
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Constants
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Prepare path and config examples
PATH = os.path.dirname(os.path.realpath(__file__))
MINIMAL = did.base.Config.example()
EXAMPLE = "".join(open(PATH + "/../examples/config").readlines())
# Substitute example git paths for real life directories
EXAMPLE = re.sub(r"\S+/git/[a-z]+", PATH, EXAMPLE)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Tests
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def test_help_minimal():
""" Help message with minimal config """
did.base.Config(config=MINIMAL)
with pytest.raises(SystemExit):
did.cli.main(["--help"])
def test_help_example():
""" Help message with example config """
did.base.Config(config=EXAMPLE)
with pytest.raises(SystemExit):
did.cli.main(["--help"])
def test_debug():
""" Check the debug mode """
did.base.Config(config=EXAMPLE)
with pytest.raises(SystemExit):
did.cli.main("--help --debug")
def test_smoke():
""" Run the smoke test """
did.cli.main("--test")
def test_invalid_arguments():
""" Complain about invalid arguments """
did.base.Config(config=MINIMAL)
for argument in ["a", "b", "c", "something"]:
with pytest.raises(did.base.OptionError):
did.cli.main(argument)
def test_invalid_date():
""" Complain about invalid arguments """
did.base.Config(config=MINIMAL)
for argument in ["--since x", "--since 2015-16-17"]:
with pytest.raises(did.base.OptionError):
did.cli.main(argument)