Skip to content

Commit

Permalink
Add tests for class-defined tasks using @create_after decorator.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbdixon committed Jun 30, 2019
1 parent a5b8f99 commit 08c6a2a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,38 @@ def task_zzz3(): # pragma: no cover
assert tasks['bar'].loader is tasks['foo'].loader
assert tasks['foo'].doc == 'not loaded task doc'

def testClassCreateAfterDecorator(self):
'Check that class-defined tasks are loaded as bound methods'
class Tasks:
@create_after('yyy2')
def task_zzz3(): # pragma: no cover
pass

# create_after annotates the function
task_list = load_tasks({'task_zzz3': Tasks().task_zzz3}, allow_delayed=True)
tasks = {t.name:t for t in task_list}
task_zzz3 = tasks['zzz3']
assert isinstance(task_zzz3.loader, DelayedLoader)
assert getattr(task_zzz3.loader.creator, '__self__', None) is not None, 'Class-defined delayed task creating method is not bound'

def testClassInitialLoadDelayedTask_creates(self, dodo):
'Check that class-defined tasks support the creates argument of @create_after'
class Tasks:
@create_after('yyy2', creates=['foo', 'bar'])
def task_zzz3(): # pragma: no cover
'''not loaded task doc'''
raise Exception('Cant be executed on load phase')

# placeholder task is created with `loader` attribute
task_list = load_tasks({'task_zzz3': Tasks().task_zzz3}, allow_delayed=True)
tasks = {t.name:t for t in task_list}
assert 'zzz3' not in tasks
f_task = tasks['foo']
assert f_task.loader.task_dep == 'yyy2'
assert getattr(f_task.loader.creator, '__self__', None) is not None, 'Class-defined delayed task creating method is not bound'
assert tasks['bar'].loader is tasks['foo'].loader
assert tasks['foo'].doc == 'not loaded task doc'

def testNameInBlacklist(self):
dodo_module = {'task_cmd_name': lambda:None}
pytest.raises(InvalidDodoFile, load_tasks, dodo_module, ['cmd_name'])
Expand Down

0 comments on commit 08c6a2a

Please sign in to comment.