Esempio n. 1
0
def test_supplier_can_be_used_multiple_times():
    foo_supplier = Supplier("foo")

    with foo_supplier.use("hello"):
        assert foo_supplier.get() == "hello"

    with foo_supplier.use("hi"):
        assert foo_supplier.get() == "hi"
Esempio n. 2
0
def test_supply_decorator_multiple_suppliers():
    foo_supplier = Supplier("foo")
    bar_supplier = Supplier("bar")

    @supply(foo_supplier, bar_supplier)
    def has_arg(hello, there, friend):
        assert hello == "hello"
        assert there == "there"
        assert friend == "friend"

    with foo_supplier.use("hello"), bar_supplier.use("there"):
        has_arg("friend")
Esempio n. 3
0
def test_supplier_resets():
    blah_supplier = Supplier("blah")

    with blah_supplier.use("hello"):
        pass
    with pytest.raises(Exception):
        blah_supplier.get()
Esempio n. 4
0
def test_supply_decorator():
    foo_supplier = Supplier("foo")

    @supply(foo_supplier)
    def has_arg(hello):
        assert hello == "hello"

    with foo_supplier.use("hello"):
        has_arg()
Esempio n. 5
0
def test_supply_decorator_in_classes():
    foo_supplier = Supplier("foo")
    bar_supplier = Supplier("bar")

    class Baz:
        name = "baz"

        @supply(foo_supplier, bar_supplier)
        def bound_method(self, hello, there, cool, house):
            assert hello == "hello"
            assert there == "there"
            assert self.name == "baz"
            assert cool == "cool"
            assert house == "house"

    baz = Baz()

    with foo_supplier.use("hello"), bar_supplier.use("there"):
        baz.bound_method("cool", "house")
Esempio n. 6
0
def test_supply_decorator_with_arg():
    foo_supplier = Supplier("foo")

    @supply(foo_supplier)
    def has_arg(hello, there):
        assert hello == "hello"
        assert there == "there"

    with foo_supplier.use("hello"):
        has_arg("there")
Esempio n. 7
0
def test_supply_decorator_optional_args():
    foo_supplier = Supplier("foo")

    @supply(foo_supplier)
    def has_arg(hello, there, pal="pal"):
        assert hello == "hello"
        assert there == "there"
        assert pal == "pal"

    with foo_supplier.use("hello"):
        has_arg("there")
        has_arg("there", "pal")
Esempio n. 8
0
def test_supplier_supplies():
    blah_supplier = Supplier("blah")
    with blah_supplier.use("hello"):
        assert blah_supplier.get() == "hello"