Skip to content

Commit

Permalink
refs #220. minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
schettino72 committed Nov 11, 2017
1 parent 1f195df commit 6006b54
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions doc/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'check
'choice'
'clean'
'cleanforget'
'command
'command'
'dep
Expand Down Expand Up @@ -159,6 +160,7 @@ callables
cfg
chdir
cid
cleanforget
cloudpickle
cmd
cmp
Expand Down
6 changes: 4 additions & 2 deletions doit/cmd_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Clean(DoitCmdBase):
doc_description = ("If no task is specified clean default tasks and "
"set --clean-dep automatically.")

cmd_options = (opt_clean_cleandep, opt_clean_cleanall, opt_clean_dryrun, opt_clean_forget)
cmd_options = (opt_clean_cleandep, opt_clean_cleanall,
opt_clean_dryrun, opt_clean_forget)


def clean_tasks(self, tasks, dryrun, cleanforget):
Expand All @@ -59,7 +60,8 @@ def clean_tasks(self, tasks, dryrun, cleanforget):

self.dep_manager.close()

def _execute(self, dryrun, cleandep, cleanall, cleanforget, pos_args=None):
def _execute(self, dryrun, cleandep, cleanall, cleanforget,
pos_args=None):
"""Clean tasks
@param task_list (list - L{Task}): list of all tasks from dodo file
@ivar dryrun (bool): if True clean tasks are not executed
Expand Down
30 changes: 20 additions & 10 deletions tests/test_cmd_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def test_clean_all(self, tasks):

def test_clean_default(self, tasks):
output = StringIO()
cmd_clean = CmdFactory(Clean, outstream=output, task_list=tasks,
sel_tasks=['t1'], dep_manager=mock.MagicMock())
cmd_clean = CmdFactory(
Clean, outstream=output, task_list=tasks,
sel_tasks=['t1'], dep_manager=mock.MagicMock())
cmd_clean._execute(False, False, False, False)
# default enable --clean-dep by default
assert ['t2', 't1'] == self.cleaned
Expand All @@ -49,8 +50,9 @@ def test_clean_default_all(self, tasks):
def test_clean_selected(self, tasks):
output = StringIO()
mock_dep_manager = mock.MagicMock()
cmd_clean = CmdFactory(Clean, outstream=output, task_list=tasks,
sel_tasks=['t1'], dep_manager=mock_dep_manager)
cmd_clean = CmdFactory(
Clean, outstream=output, task_list=tasks,
sel_tasks=['t1'], dep_manager=mock_dep_manager)
cmd_clean._execute(False, False, False, False, ['t2'])
assert ['t2'] == self.cleaned
mock_dep_manager.remove.assert_not_called()
Expand Down Expand Up @@ -96,12 +98,17 @@ def test_clean_invalid_task(self, tasks):
def test_clean_forget_selected(self, tasks):
output = StringIO()
mock_dep_manager = mock.MagicMock()
cmd_clean = CmdFactory(Clean, outstream=output, task_list=tasks,
sel_tasks=['t1'], dep_manager=mock_dep_manager)
cmd_clean = CmdFactory(
Clean, outstream=output, task_list=tasks,
sel_tasks=['t1'], dep_manager=mock_dep_manager)
cmd_clean._execute(False, False, False, True, ['t2'])
assert ['t2'] == self.cleaned
mock_dep_manager.assert_has_calls([mock.call.remove(mock.ANY), mock.call.close()]) # order
assert mock_dep_manager.remove.call_args_list == [mock.call('t2')] # exactly t2, not more
# order
mock_dep_manager.assert_has_calls(
[mock.call.remove(mock.ANY), mock.call.close()])
# exactly t2, not more
assert (mock_dep_manager.remove.call_args_list ==
[mock.call('t2')])

def test_clean_forget_taskdep(self, tasks):
output = StringIO()
Expand All @@ -110,5 +117,8 @@ def test_clean_forget_taskdep(self, tasks):
dep_manager=mock_dep_manager)
cmd_clean._execute(False, True, False, True, ['t1'])
assert ['t2', 't1'] == self.cleaned
mock_dep_manager.assert_has_calls([mock.call.remove(mock.ANY), mock.call.close()]) # order
assert mock_dep_manager.remove.call_args_list == [mock.call('t2'), mock.call('t1')]
# order
mock_dep_manager.assert_has_calls(
[mock.call.remove(mock.ANY), mock.call.close()])
assert (mock_dep_manager.remove.call_args_list ==
[mock.call('t2'), mock.call('t1')])

0 comments on commit 6006b54

Please sign in to comment.