Example #1
0
def test_double_teardown():
    """Test teardown twice"""
    from Cauldron.api import use, install, teardown

    use("local")
    from Cauldron import ktl

    del ktl

    from Cauldron import DFW

    del DFW

    install()
    teardown()
    teardown()

    with pytest.raises(ImportError):
        from Cauldron import ktl
    with pytest.raises(ImportError):
        from Cauldron import DFW

    assert "DFW" not in sys.modules
    assert "ktl" not in sys.modules

    use("local")
    from Cauldron import ktl, DFW
Example #2
0
def test_dangling_imports():
    """Test imports which are dangling."""
    from Cauldron.api import use
    use("local")
    from Cauldron import ktl, DFW
    assert hasattr(ktl.Keyword, 'Keyword')
    assert hasattr(DFW.Keyword, 'Keyword')
Example #3
0
def test_custom_type_nobackend(servicename, keyword_name):
    """Test custom type with no backend set up."""
    from Cauldron.types import DispatcherKeywordType

    class CustomKeyword(DispatcherKeywordType):
        """A custom keyword type"""
        counter = 0

        def __init__(self, *args, **kwargs):
            print("__init__")
            self.counter += 1
            super(CustomKeyword, self).__init__(*args, **kwargs)

    with pytest.raises(RuntimeError):
        CustomKeyword(keyword_name, "")

    from Cauldron.api import use, teardown
    try:
        use("mock")
        from Cauldron.DFW import Service
        service = Service(servicename,
                          setup=lambda s: CustomKeyword(keyword_name, s),
                          config=None)
        keyword = service[keyword_name]
        assert isinstance(keyword, CustomKeyword)
        assert keyword.counter == 1
    finally:
        teardown()
Example #4
0
def test_reuse():
    """Test calling use twice."""
    from Cauldron.api import use, teardown

    use("local")
    with pytest.raises(RuntimeError):
        use("local")
Example #5
0
def test_dangling_imports():
    """Test imports which are dangling."""
    from Cauldron.api import use

    use("local")
    from Cauldron import ktl, DFW

    assert hasattr(ktl.Keyword, "Keyword")
    assert hasattr(DFW.Keyword, "Keyword")
Example #6
0
def test_import_duplicates():
    """Test importing Cauldron modules in different ways."""
    from Cauldron.api import use
    use("local")
    from Cauldron import ktl, DFW

    from Cauldron.base.client import Keyword
    assert issubclass(ktl.Keyword.Keyword, Keyword)

    from Cauldron.base.dispatcher import Keyword
    assert issubclass(DFW.Keyword.Keyword, Keyword)
Example #7
0
def backend(request, config):
    """The backend name."""
    from Cauldron.api import use, teardown, CAULDRON_SETUP
    use(request.param)
    request.addfinalizer(fail_if_not_teardown)

    if request.param == 'zmq':
        from Cauldron.zmq.broker import ZMQBroker
        b = ZMQBroker.setup(config=config, timeout=0.01)
        if b:
            request.addfinalizer(b.stop)
    return request.param
Example #8
0
def backend(request, config):
    """The backend name."""
    from Cauldron.api import use, teardown, CAULDRON_SETUP
    use(request.param)
    request.addfinalizer(fail_if_not_teardown)
    
    if request.param == 'zmq':
        from Cauldron.zmq.broker import ZMQBroker
        b = ZMQBroker.setup(config=config, timeout=0.01)
        if b:
            request.addfinalizer(b.stop)
    return request.param
Example #9
0
def test_import_duplicates():
    """Test importing Cauldron modules in different ways."""
    from Cauldron.api import use

    use("local")
    from Cauldron import ktl, DFW

    from Cauldron.base.client import Keyword

    assert issubclass(ktl.Keyword.Keyword, Keyword)

    from Cauldron.base.dispatcher import Keyword

    assert issubclass(DFW.Keyword.Keyword, Keyword)
Example #10
0
def test_teardown(servicename, teardown_cauldron, keyword_name2, servicename2):
    """Check that teardown really does tear things down, in local mode."""
    from Cauldron.api import teardown, use
    use("local")
    from Cauldron.DFW import Service
    svc = Service(servicename2, None)
    svc[keyword_name2].modify('10')
    teardown()
    del svc

    use("local")
    from Cauldron.DFW import Service
    svc2 = Service(servicename2, None)
    assert svc2[keyword_name2].read() == None
Example #11
0
def test_guard():
    """Test that imports are guarded."""
    from Cauldron.api import use, teardown

    with pytest.raises(ImportError):
        from Cauldron import ktl
    with pytest.raises(ImportError):
        from Cauldron import DFW
    use("local")
    from Cauldron import DFW, ktl
    del DFW, ktl
    teardown()
    with pytest.raises(ImportError):
        from Cauldron import ktl
    with pytest.raises(ImportError):
        from Cauldron import DFW
Example #12
0
def test_teardown(servicename, teardown_cauldron, keyword_name2, servicename2):
    """Check that teardown really does tear things down, in local mode."""
    from Cauldron.api import teardown, use

    use("local")
    from Cauldron.DFW import Service

    svc = Service(servicename2, None)
    svc[keyword_name2].modify("10")
    teardown()
    del svc

    use("local")
    from Cauldron.DFW import Service

    svc2 = Service(servicename2, None)
    assert svc2[keyword_name2].read() == None
Example #13
0
def test_guard():
    """Test that imports are guarded."""
    from Cauldron.api import use, teardown

    with pytest.raises(ImportError):
        from Cauldron import ktl
    with pytest.raises(ImportError):
        from Cauldron import DFW
    use("local")
    from Cauldron import DFW, ktl

    del DFW, ktl
    teardown()
    with pytest.raises(ImportError):
        from Cauldron import ktl
    with pytest.raises(ImportError):
        from Cauldron import DFW
Example #14
0
def test_install():
    """Test the install feature."""
    from Cauldron.api import use, install

    with pytest.raises(RuntimeError):
        install()

    use("local")
    install()

    import ktl
    import Cauldron.ktl
    assert ktl == Cauldron.ktl

    import DFW
    import Cauldron.DFW
    assert DFW == Cauldron.DFW
Example #15
0
def test_teardown():
    """Test that imports are guarded after calling .teardown()"""
    from Cauldron.api import use, install, teardown
    use("local")
    from Cauldron import ktl
    del ktl

    from Cauldron import DFW
    del DFW

    install()
    teardown()
    with pytest.raises(ImportError):
        from Cauldron import ktl
    with pytest.raises(ImportError):
        from Cauldron import DFW

    assert "DFW" not in sys.modules
    assert "ktl" not in sys.modules
Example #16
0
def test_install():
    """Test the install feature."""
    from Cauldron.api import use, install

    with pytest.raises(RuntimeError):
        install()

    use("local")
    install()

    import ktl
    import Cauldron.ktl

    assert ktl == Cauldron.ktl

    import DFW
    import Cauldron.DFW

    assert DFW == Cauldron.DFW
Example #17
0
def test_teardown():
    """Test that imports are guarded after calling .teardown()"""
    from Cauldron.api import use, install, teardown

    use("local")
    from Cauldron import ktl

    del ktl

    from Cauldron import DFW

    del DFW

    install()
    teardown()
    with pytest.raises(ImportError):
        from Cauldron import ktl
    with pytest.raises(ImportError):
        from Cauldron import DFW

    assert "DFW" not in sys.modules
    assert "ktl" not in sys.modules
Example #18
0
def test_custom_type_nobackend(servicename, keyword_name):
    """Test custom type with no backend set up."""
    from Cauldron.types import DispatcherKeywordType
    class CustomKeyword(DispatcherKeywordType):
        """A custom keyword type"""
        counter = 0
        def __init__(self, *args, **kwargs):
            print("__init__")
            self.counter += 1
            super(CustomKeyword, self).__init__(*args, **kwargs)
            
    with pytest.raises(RuntimeError):
        CustomKeyword(keyword_name, "")
        
    from Cauldron.api import use, teardown
    try:
        use("mock")
        from Cauldron.DFW import Service
        service = Service(servicename, setup=lambda s : CustomKeyword(keyword_name, s), config=None)
        keyword = service[keyword_name]
        assert isinstance(keyword, CustomKeyword)
        assert keyword.counter == 1
    finally:
        teardown()
Example #19
0
def test_double_teardown():
    """Test teardown twice"""
    from Cauldron.api import use, install, teardown
    use("local")
    from Cauldron import ktl
    del ktl

    from Cauldron import DFW
    del DFW

    install()
    teardown()
    teardown()

    with pytest.raises(ImportError):
        from Cauldron import ktl
    with pytest.raises(ImportError):
        from Cauldron import DFW

    assert "DFW" not in sys.modules
    assert "ktl" not in sys.modules

    use('local')
    from Cauldron import ktl, DFW
Example #20
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Demonstrate REDIS read-write ability.
"""
import time
from lumberjack import setup_logging, setup_warnings_logger
from logging import getLogger

setup_logging(mode='stream', level=5)
setup_warnings_logger("")
log = getLogger("example.zmq")

# Get ready!
from Cauldron.api import use
use("zmq")

from Cauldron import DFW


def setup(service):
    """Setup the service."""
    kwd = DFW.Keyword.Keyword("TEST", service)
    print("Service setup")


disp = DFW.Service("testsvc", setup=setup, config=None)
dtest = disp["TEST"]
log.info("Dispatcher Keyword {0!r}".format(dtest))

VALUE = "SOMEVALUE"
Example #21
0
"""
Demonstrate REDIS read-write ability.
"""
import time
from lumberjack import setup_logging
setup_logging(mode='stream')
from logging import getLogger
from Cauldron.conftest import clear_registry
log = getLogger("example.redis")
# Start up!
from Cauldron.redis.common import configure_pool, REDIS_SERVICES_REGISTRY
configure_pool(host='localhost', port=6379, db=0)
clear_registry()

# Get ready!
from Cauldron.api import use
use("redis")

from Cauldron import DFW
disp = DFW.Service("testsvc", config=None)
dtest = disp["TEST"]
log.info(dtest)

from Cauldron import ktl
svc = ktl.Service("testsvc")
test = svc["TEST"]
log.info("Writing")
test.write("SOMEVALUE")
log.info(test.read())
log.info("Done!")
disp.shutdown()
Example #22
0
def test_api_unknown():
    """docstring for test_api_unknown"""
    from Cauldron.api import use
    with pytest.raises(ValueError):
        use("unknown_backend")
Example #23
0
def test_api_unknown():
    """docstring for test_api_unknown"""
    from Cauldron.api import use
    with pytest.raises(ValueError):
        use("unknown_backend")
Example #24
0
def useredis(request):
    """Use the local backend."""
    from Cauldron.api import use
    use('redis')
Example #25
0
def backend(request):
    """Use the local backend."""
    from Cauldron.api import use
    use('local')
    request.addfinalizer(fail_if_not_teardown)
Example #26
0
def backend(request):
    """Always return the zmq backend."""
    from Cauldron.api import use, teardown, CAULDRON_SETUP
    use("zmq")
    request.addfinalizer(fail_if_not_teardown)
    return "zmq"
Example #27
0
def backend(request):
    """Use the local backend."""
    from Cauldron.api import use
    use('mock')
    request.addfinalizer(fail_if_not_teardown)
Example #28
0
def test_reuse():
    """Test calling use twice."""
    from Cauldron.api import use, teardown
    use("local")
    with pytest.raises(RuntimeError):
        use("local")
Example #29
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Demonstrate REDIS read-write ability.
"""
import time
from lumberjack import setup_logging, setup_warnings_logger
from logging import getLogger

setup_logging(mode='stream', level=5)
setup_warnings_logger("")
log = getLogger("example.zmq")

# Get ready!
from Cauldron.api import use
use("zmq")

from Cauldron import DFW

def setup(service):
    """Setup the service."""
    kwd = DFW.Keyword.Keyword("TEST", service)
    print("Service setup")

disp = DFW.Service("testsvc", setup = setup, config=None)
dtest = disp["TEST"]
log.info("Dispatcher Keyword {0!r}".format(dtest))

VALUE = "SOMEVALUE"
time.sleep(1.0)
log.info("Starting KTL client...")