Debian Codegraph @

tests/test_cmd_info.py

raw symbols SCIP
1 from io import StringIO
2
3 import pytest
4
5 from doit.exceptions import InvalidCommand
6 from doit.task import Task
7 from doit.cmd_info import Info
8 from .conftest import CmdFactory
9
10
11 class TestCmdInfo(object):
12
13 def test_info_basic_attrs(self, dep_manager):
14 output = StringIO()
15 task = Task("t1", [], file_dep=['tests/data/dependency1'],
16 doc="task doc", getargs={'a': ('x', 'y')}, verbosity=2,
17 meta={'a': ['b', 'c']})
18 cmd = CmdFactory(Info, outstream=output,
19 dep_file=dep_manager.name, task_list=[task])
20 cmd._execute(['t1'], hide_status=True)
21 assert "t1" in output.getvalue()
22 assert "task doc" in output.getvalue()
23 assert "- tests/data/dependency1" in output.getvalue()
24 assert "verbosity : 2" in output.getvalue()
25 assert "getargs : {'a': ('x', 'y')}" in output.getvalue()
26 assert "meta : {'a': ['b', 'c']}" in output.getvalue()
27
28 def test_invalid_command_args(self, dep_manager):
29 output = StringIO()
30 task = Task("t1", [], file_dep=['tests/data/dependency1'])
31 cmd = CmdFactory(Info, outstream=output,
32 dep_file=dep_manager.name, task_list=[task])
33 # fails if number of args != 1
34 pytest.raises(InvalidCommand, cmd._execute, [])
35 pytest.raises(InvalidCommand, cmd._execute, ['t1', 't2'])
36
37 def test_execute_status_run(self, dep_manager, dependency1):
38 output = StringIO()
39 task = Task("t1", [], file_dep=['tests/data/dependency1'])
40 cmd = CmdFactory(Info, outstream=output,
41 dep_file=dep_manager.name, task_list=[task],
42 dep_manager=dep_manager)
43 return_val = cmd._execute(['t1'])
44 assert "t1" in output.getvalue()
45 assert return_val == 1 # indicates task is not up-to-date
46 assert "status" in output.getvalue()
47 assert ": run" in output.getvalue()
48 assert " - tests/data/dependency1" in output.getvalue()
49
50 def test_hide_execute_status(self, dep_manager, dependency1):
51 output = StringIO()
52 task = Task("t1", [], file_dep=['tests/data/dependency1'])
53 cmd = CmdFactory(Info, outstream=output,
54 dep_manager=dep_manager, task_list=[task])
55 return_val = cmd._execute(['t1'], hide_status=True)
56 assert "t1" in output.getvalue()
57 assert return_val == 0 # always zero if not showing status
58 assert "status" not in output.getvalue()
59 assert ": run" not in output.getvalue()
60
61 def test_execute_status_uptodate(self, dep_manager, dependency1):
62 output = StringIO()
63 task = Task("t1", [], file_dep=['tests/data/dependency1'])
64 cmd = CmdFactory(Info, outstream=output,
65 dep_manager=dep_manager, task_list=[task])
66 cmd.dep_manager.save_success(task)
67 return_val = cmd._execute(['t1'])
68 assert "t1" in output.getvalue()
69 assert return_val == 0 # indicates task is not up-to-date
70 assert ": up-to-date" in output.getvalue()
71
72
73 def test_get_reasons_str(self):
74 reasons = {
75 'has_no_dependencies': True,
76 'uptodate_false': [('func', 'arg', 'kwarg')],
77 'checker_changed': ['foo', 'bar'],
78 'missing_target': ['f1', 'f2'],
79 }
80
81 got = Info.get_reasons(reasons).splitlines()
82 assert len(got) == 7
83 assert got[0] == ' * The task has no dependencies.'
84 assert got[1] == ' * The following uptodate objects evaluate to false:'
85 assert got[2] == ' - func (args=arg, kwargs=kwarg)'
86 assert got[3] == ' * The file_dep checker changed from foo to bar.'
87 assert got[4] == ' * The following targets do not exist:'
88 assert got[5] == ' - f1'
89 assert got[6] == ' - f2'