-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding unit tests for current_build.
- Loading branch information
1 parent
ab62486
commit a25b5ec
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
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,53 @@ | ||
import pytest | ||
from uranium.lib.context import Proxy, ContextStack, ContextUnavailable | ||
|
||
|
||
@pytest.fixture | ||
def context_stack(): | ||
return ContextStack() | ||
|
||
|
||
@pytest.fixture | ||
def proxy(context_stack): | ||
return Proxy(context_stack) | ||
|
||
|
||
def test_context_stack(context_stack): | ||
obj1 = object() | ||
obj2 = object() | ||
|
||
with pytest.raises(ContextUnavailable): | ||
context_stack.obj | ||
|
||
context_stack.push(obj1) | ||
assert context_stack.obj is obj1 | ||
|
||
context_stack.push(obj2) | ||
assert context_stack.obj is obj2 | ||
|
||
context_stack.pop() | ||
assert context_stack.obj is obj1 | ||
|
||
with context_stack.create_context(obj2): | ||
assert context_stack.obj is obj2 | ||
|
||
assert context_stack.pop() is obj1 | ||
|
||
with pytest.raises(ContextUnavailable): | ||
context_stack.obj | ||
|
||
|
||
def test_context_proxy(context_stack, proxy): | ||
|
||
class TestObj(object): | ||
pass | ||
|
||
obj = TestObj() | ||
obj.foo = 3 | ||
obj.bar = 6 | ||
|
||
with context_stack.create_context(obj): | ||
assert proxy.foo == 3 | ||
assert proxy.bar == 6 | ||
proxy.bar = 7 | ||
assert obj.bar == 7 |
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,17 @@ | ||
from uranium import current_build | ||
|
||
|
||
def test_build_global(build): | ||
|
||
g = [] | ||
|
||
with build.as_current_build(): | ||
|
||
@current_build.task | ||
def main(build): | ||
current_build.config["foo"] = "bar" | ||
g.append("foo") | ||
|
||
build.run_task("main") | ||
assert "foo" in g | ||
assert build.config.get("foo") == "bar" |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .lib.proxy import ContextStack, Proxy | ||
from .lib.context import ContextStack, Proxy | ||
|
||
_build_proxy = ContextStack() | ||
current_build = Proxy(_build_proxy) |