-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
171 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
"""global docstring""" | ||
from __future__ import division, print_function, unicode_literals | ||
|
||
import pytest | ||
|
||
from sacred.dependencies import Source | ||
from sacred.experiment import Ingredient | ||
|
||
|
||
@pytest.fixture | ||
def ing(): | ||
return Ingredient('tickle') | ||
|
||
|
||
def test_create_ingredient(ing): | ||
assert ing.path == 'tickle' | ||
assert ing.doc == __doc__ | ||
assert Source.create(__file__) in ing.sources | ||
|
||
|
||
def test_capture_function(ing): | ||
@ing.capture | ||
def foo(something): | ||
pass | ||
assert foo in ing.captured_functions | ||
assert foo.prefix is None | ||
|
||
|
||
def test_capture_function_with_prefix(ing): | ||
@ing.capture(prefix='bar') | ||
def foo(something): | ||
pass | ||
assert foo in ing.captured_functions | ||
assert foo.prefix == 'bar' | ||
|
||
|
||
def test_capture_function_twice(ing): | ||
@ing.capture | ||
def foo(something): | ||
pass | ||
|
||
assert ing.captured_functions == [foo] | ||
ing.capture(foo) | ||
assert ing.captured_functions == [foo] | ||
|
||
|
||
|
||
def test_add_pre_run_hook(ing): | ||
@ing.pre_run_hook | ||
def foo(something): | ||
pass | ||
assert foo in ing.pre_run_hooks | ||
assert foo in ing.captured_functions | ||
assert foo.prefix is None | ||
|
||
|
||
def test_add_pre_run_hook_with_prefix(ing): | ||
@ing.pre_run_hook(prefix='bar') | ||
def foo(something): | ||
pass | ||
assert foo in ing.pre_run_hooks | ||
assert foo in ing.captured_functions | ||
assert foo.prefix == 'bar' | ||
|
||
|
||
def test_add_post_run_hook(ing): | ||
@ing.post_run_hook | ||
def foo(something): | ||
pass | ||
assert foo in ing.post_run_hooks | ||
assert foo in ing.captured_functions | ||
assert foo.prefix is None | ||
|
||
|
||
def test_add_post_run_hook_with_prefix(ing): | ||
@ing.post_run_hook(prefix='bar') | ||
def foo(something): | ||
pass | ||
assert foo in ing.post_run_hooks | ||
assert foo in ing.captured_functions | ||
assert foo.prefix == 'bar' | ||
|
||
|
||
def test_add_command(ing): | ||
@ing.command | ||
def foo(a, b): | ||
pass | ||
|
||
assert 'foo' in ing.commands | ||
assert ing.commands['foo'] == foo | ||
assert foo.prefix is None | ||
|
||
|
||
def test_add_command_with_prefix(ing): | ||
@ing.command(prefix='bar') | ||
def foo(a, b): | ||
pass | ||
|
||
assert 'foo' in ing.commands | ||
assert ing.commands['foo'] == foo | ||
assert foo.prefix == 'bar' | ||
|
||
|
||
def test_add_config_hook(ing): | ||
def foo(config, command_name, logger): | ||
pass | ||
ch = ing.config_hook(foo) | ||
assert ch == foo | ||
assert foo in ing.config_hooks | ||
|
||
|
||
def test_add_config_hook_with_invalid_signature_raises(ing): | ||
with pytest.raises(ValueError): | ||
@ing.config_hook | ||
def foo(wrong, signature): | ||
pass |