Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement and test loading of default tasks
  • Loading branch information
bitprophet committed Jul 11, 2011
1 parent ea1f9be commit 459dd3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fabfile/docs.py
Expand Up @@ -8,7 +8,7 @@
docs_host = 'jforcier@fabfile.org'


@task
@task(default=True)
def build(clean='no', browse_='no'):
"""
Generate the Sphinx documentation.
Expand Down
6 changes: 5 additions & 1 deletion fabric/main.py
Expand Up @@ -368,7 +368,11 @@ def _crawl(name, mapping):

def crawl(name, mapping):
try:
return _crawl(name, mapping)
result = _crawl(name, mapping)
# Handle default tasks
if isinstance(result, _Dict) and getattr(result, 'default', False):
result = result.default
return result
except (KeyError, TypeError):
return None

Expand Down
10 changes: 9 additions & 1 deletion tests/test_main.py
Expand Up @@ -523,7 +523,7 @@ def test_mapping_task_classes():
mapping_task""")


def test_default_tasks():
def test_default_task_listings():
"""
@task(default=True) should cause task to also load under module's name
"""
Expand All @@ -540,3 +540,11 @@ def test_default_tasks():
list_output.description = "Default task --list output: %s" % format_
yield list_output, 'default_tasks', format_, expected
del list_output.description


def test_default_task_loading():
"""
crawl() should return default tasks where found, instead of module objs
"""
docs, tasks = load_fabfile(fabfile('default_tasks'))
ok_(isinstance(crawl('mymodule', tasks), Task))

0 comments on commit 459dd3a

Please sign in to comment.