Skip to content

Commit

Permalink
adding unit tests for current_build.
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Jan 25, 2016
1 parent ab62486 commit a25b5ec
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Empty file added tests/lib/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions tests/lib/test_context.py
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
17 changes: 17 additions & 0 deletions tests/test_app_globals.py
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"
2 changes: 1 addition & 1 deletion uranium/app_globals.py
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)

0 comments on commit a25b5ec

Please sign in to comment.