Exemplo n.º 1
0
def test_context_manager():
    """
    Opaque.initialize should act as a context manager and resets state properly.

    """
    opaque = Opaque()

    opaque[THIS] = VALUE
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))

    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER,
                                                                OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to({
            THIS: OTHER,
            THAT: OTHER
        })))

    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER,
                                                                OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to({
            THIS: OTHER,
            THAT: OTHER
        })))

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
Exemplo n.º 2
0
def test_composition():
    """
    Opaque.initialize should compose (within reason).

    """
    opaque = Opaque()
    opaque[THIS] = VALUE

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
        with opaque.initialize(example_func, ALSO, OTHER):
            assert_that(opaque.as_dict(), is_(equal_to(example_func(ALSO, OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
Exemplo n.º 3
0
def test_composition():
    """
    Opaque.initialize should compose (within reason).

    """
    opaque = Opaque()
    opaque[THIS] = VALUE

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
        with opaque.initialize(example_func, ALSO, OTHER):
            assert_that(opaque.as_dict(), is_(equal_to(example_func(ALSO, OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
Exemplo n.º 4
0
def test_context_manager():
    """
    Opaque.initialize should act as a context manager and resets state properly.

    """
    opaque = Opaque()

    opaque[THIS] = VALUE
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))

    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to({THIS: OTHER, THAT: OTHER})))

    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to({THIS: OTHER, THAT: OTHER})))

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))