-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_doit_yaml.py
106 lines (87 loc) · 2.45 KB
/
test_doit_yaml.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
104
105
import itertools
import yaml
from doit.task import Task
from doit.action import CmdAction
from doit_yaml import YAML_Loader
def convert(yaml_str):
data = yaml.load(yaml_str)
loader = YAML_Loader()
return list(itertools.chain.from_iterable(loader.entry2tasks(data)))
class TestTask(object):
def test_dict(self):
got = convert("""
task:
name: simple
cmd: echo hi
""")
assert 1 == len(got)
task = got[0]
assert isinstance(task, Task)
assert task.name == 'simple'
assert 1 == len(task.actions)
assert isinstance(task.actions[0], CmdAction)
assert task.actions[0]._action == 'echo hi'
def test_str(self):
got = convert("""task: echo hi""")
assert 1 == len(got)
task = got[0]
assert task.name == 'echo hi'
assert isinstance(task.actions[0], CmdAction)
assert task.actions[0]._action == 'echo hi'
def test_list_dict(self):
got = convert("""
task:
- name: one
cmd: echo hi
- name: two
cmd: echo hello
""")
assert 2 == len(got)
assert got[0].name == 'one'
assert got[0].actions[0]._action == 'echo hi'
assert got[1].name == 'two'
def test_list_str(self):
got = convert("""
task:
- echo hi
- echo hello
""")
assert 2 == len(got)
assert got[0].name == 'echo hi'
assert got[0].actions[0]._action == 'echo hi'
assert got[1].name == 'echo hello'
def test_multi_cmd(self):
got = convert("""
task:
name: one
cmd:
- echo foo
- echo bar
""")
assert 1 == len(got)
task = got[0]
assert task.name == 'one'
assert 2 == len(task.actions)
assert task.actions[0]._action == 'echo foo'
assert task.actions[1]._action == 'echo bar'
class TestPyflakes(object):
def test_dict(self):
got = convert("""
pyflakes:
file: foo.py
""")
assert 1 == len(got)
task = got[0]
assert task.name == 'pyflakes:foo.py'
def test_str(self):
got = convert("""pyflakes: foo.py""")
assert 1 == len(got)
task = got[0]
assert task.name == 'pyflakes:foo.py'
def test_str_pattern(self):
got = convert('''pyflakes: "*.py"''')
assert 3 == len(got)
expected = ['pyflakes:doit_yaml.py',
'pyflakes:setup.py',
'pyflakes:test_doit_yaml.py']
assert expected == sorted([t.name for t in got])