Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding missing "warnings" import #16

Merged
merged 1 commit into from May 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions wand/resource.py
Expand Up @@ -8,6 +8,7 @@
import logging
import contextlib
import ctypes
import warnings
from . import exceptions
from .api import library

Expand All @@ -20,7 +21,7 @@ def genesis():
"""Instantiates the MagickWand API.

.. warning::

Don't call this function directly. Use :func:`increment_refcount()` and
:func:`decrement_refcount()` functions instead.

Expand All @@ -32,7 +33,7 @@ def terminus():
"""Cleans up the MagickWand API.

.. warning::

Don't call this function directly. Use :func:`increment_refcount()` and
:func:`decrement_refcount()` functions instead.

Expand Down
27 changes: 27 additions & 0 deletions wandtests/resource.py
Expand Up @@ -43,3 +43,30 @@ def negative_refcount():
with raises(RuntimeError) as error:
resource.decrement_refcount()

@tests.test
def raises_exceptions():
"""Exceptions raise, and warnings warn"""
from wand import resource
exceptions = resource.exceptions
class DummyResource(resource.Resource):

def set_exception_type(self, idx):
self.exception_index = idx

def get_exception(self):
exc_cls = exceptions.TYPE_MAP[self.exception_index]
return exc_cls("Dummy exception")

for code in exceptions.TYPE_MAP.keys():
resource = DummyResource()
resource.set_exception_type(code)
import warnings
with warnings.catch_warnings(record=True) as w:
try:
resource.raise_exception()
assert len(w) == 1
assert w[-1].category.__name__.endswith('Warning')
assert "Dummy exception" in str(w[-1].message)
except exceptions.WandException as e:
assert not e.__class__.__name__.endswith('Warning')
assert e.message == 'Dummy exception'