1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
class TestInvalidURI:
def _makeOne(self, *args, **kwargs):
from plaster.exceptions import InvalidURI
return InvalidURI(*args, **kwargs)
def test_it(self):
exc = self._makeOne("foo")
assert isinstance(exc, ValueError)
assert exc.message == 'Unable to parse config_uri "foo".'
assert exc.uri == "foo"
def test_it_overrides_message(self):
exc = self._makeOne("foo", message="bar")
assert isinstance(exc, ValueError)
assert exc.message == "bar"
assert exc.uri == "foo"
class TestLoaderNotFound:
def _makeOne(self, *args, **kwargs):
from plaster.exceptions import LoaderNotFound
return LoaderNotFound(*args, **kwargs)
def test_it(self):
exc = self._makeOne("foo")
assert isinstance(exc, ValueError)
assert exc.scheme == "foo"
assert exc.protocols is None
assert exc.message == ('Could not find a matching loader for the scheme "foo".')
def test_it_with_protocol(self):
exc = self._makeOne("foo", ["wsgi"])
assert isinstance(exc, ValueError)
assert exc.scheme == "foo"
assert exc.protocols == ["wsgi"]
assert exc.message == (
'Could not find a matching loader for the scheme "foo", ' 'protocol "wsgi".'
)
def test_it_with_multiple_protocols(self):
exc = self._makeOne("foo", ["wsgi", "qt"])
assert isinstance(exc, ValueError)
assert exc.scheme == "foo"
assert exc.protocols == ["wsgi", "qt"]
assert exc.message == (
'Could not find a matching loader for the scheme "foo", '
'protocol "wsgi, qt".'
)
def test_it_overrides_message(self):
exc = self._makeOne("foo", message="bar")
assert isinstance(exc, ValueError)
assert exc.scheme == "foo"
assert exc.protocols is None
assert exc.message == "bar"
class TestMultipleLoadersFound:
def _makeOne(self, *args, **kwargs):
from plaster.exceptions import MultipleLoadersFound
return MultipleLoadersFound(*args, **kwargs)
def test_it(self):
dummy1 = DummyLoaderInfo("dummy1")
dummy2 = DummyLoaderInfo("dummy2")
exc = self._makeOne("https", [dummy1, dummy2])
assert isinstance(exc, ValueError)
assert exc.message == (
'Multiple plaster loaders were found for scheme "https". '
"Please specify a more specific config_uri. Matched loaders: "
"dummy1, dummy2"
)
assert exc.scheme == "https"
assert exc.protocols is None
assert exc.loaders == [dummy1, dummy2]
def test_it_with_protocol(self):
dummy1 = DummyLoaderInfo("dummy1")
dummy2 = DummyLoaderInfo("dummy2")
exc = self._makeOne("https", [dummy1, dummy2], protocols=["wsgi"])
assert isinstance(exc, ValueError)
assert exc.message == (
'Multiple plaster loaders were found for scheme "https", '
'protocol "wsgi". Please specify a more specific config_uri. '
"Matched loaders: dummy1, dummy2"
)
assert exc.scheme == "https"
assert exc.protocols == ["wsgi"]
assert exc.loaders == [dummy1, dummy2]
def test_it_with_multiple_protocols(self):
dummy1 = DummyLoaderInfo("dummy1")
dummy2 = DummyLoaderInfo("dummy2")
exc = self._makeOne("https", [dummy1, dummy2], protocols=["wsgi", "qt"])
assert isinstance(exc, ValueError)
assert exc.message == (
'Multiple plaster loaders were found for scheme "https", '
'protocol "wsgi, qt". Please specify a more specific '
"config_uri. Matched loaders: dummy1, dummy2"
)
assert exc.scheme == "https"
assert exc.protocols == ["wsgi", "qt"]
assert exc.loaders == [dummy1, dummy2]
def test_it_overrides_message(self):
dummy = object()
exc = self._makeOne("https", [dummy], message="foo")
assert isinstance(exc, ValueError)
assert exc.message == "foo"
assert exc.scheme == "https"
assert exc.protocols is None
assert exc.loaders == [dummy]
class DummyLoaderInfo:
def __init__(self, scheme):
self.scheme = scheme
|