Skip to content

Commit

Permalink
Added ServerWarning class and its base class Warning
Browse files Browse the repository at this point in the history
Details:

* There are cases when pywbem needs to tolerate incorrect WBEM server
  behavior, but still needs to surface it. This change adds a ServerWarning
  class for this purpose. It is derived from a new base class Warning.

* The new base class Warning is derived from both pywbem.Error and the
  built-in Python Warning class, in order to pick up both behaviors.

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Nov 24, 2018
1 parent e5c797c commit 2a8075c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ This version contains all fixes up to pywbem 0.12.4.
* Improved the quality of any `ParseError` exception messages when the SAX
parser detects errors in CIM-XML responses. See issue #1438.

* Added a `ServerWarning` class and its base class `Warning`. The new
`ServerWarning` is raised in cases when the WBEM server exhibits some
incorrect behavior that is tolerated by pywbem.

**Cleanup:**

* Moved class `NocaseDict` into its own module (Issue #848).
Expand Down
20 changes: 19 additions & 1 deletion pywbem/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
the WBEM client library API.
"""

import six

from .cim_constants import _statuscode2name, _statuscode2string

# This module is meant to be safe for 'import *'.

__all__ = ['Error', 'ConnectionError', 'AuthError', 'HTTPError', 'TimeoutError',
'VersionError', 'ParseError', 'CIMError']
'VersionError', 'ParseError', 'CIMError', 'Warning',
'ServerWarning']


class Error(Exception):
Expand Down Expand Up @@ -352,3 +355,18 @@ def __str__(self):
self.status_code, self.status_code_name, self.status_description,
inst_str, self.conn_str)
return ret_str


class Warning(Error, six.moves.builtins.Warning):
"""
Base class for pywbem specific warnings.
"""
pass


class ServerWarning(Warning):
"""
This warning indicates an issue with the WBEM server that has been
tolerated by pywbem.
"""
pass
19 changes: 13 additions & 6 deletions testsuite/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest

from pywbem import Error, ConnectionError, AuthError, HTTPError, TimeoutError,\
ParseError, VersionError, CIMError, CIMInstance
ParseError, VersionError, CIMError, Warning, ServerWarning, CIMInstance

# Test connection ID used for showing connection information in exception
# messages
Expand Down Expand Up @@ -68,12 +68,15 @@ def _assert_connection(exc, conn_id_kwarg, exp_conn_str):
TimeoutError,
ParseError,
VersionError,
Warning,
ServerWarning,
], scope='module')
def simple_class(request):
"""
Fixture representing variations of the simple exception classes.
Fixture representing variations of the simple exception and warning
classes.
Returns the exception class.
Returns the exception or warning class.
"""
return request.param

Expand All @@ -88,7 +91,7 @@ def simple_class(request):
def simple_args(request):
"""
Fixture representing variations of positional init arguments for the simple
exception classes.
exception or warning classes.
Returns a tuple of positional arguments for initializing an exception
object.
Expand All @@ -105,7 +108,8 @@ def simple_args(request):
def conn_info(request):
"""
Fixture representing variations for the conn_id keyword argument for all
exception classes, and the corresponding expected connection info string.
exception and warning classes, and the corresponding expected connection
info string.
Returns a tuple of:
* conn_id_kwarg: dict with the 'conn_id' keyword argument. May be empty.
Expand All @@ -117,7 +121,10 @@ def conn_info(request):
def test_simple(simple_class, simple_args, conn_info):
# pylint: disable=redefined-outer-name
"""
Test the simple exception classes.
Test the simple exception and warning classes.
Note, the Python `Warning` class is derived from the `Exception` class and
thus can be treated like exception classes.
"""

conn_id_kwarg, exp_conn_str = conn_info
Expand Down

0 comments on commit 2a8075c

Please sign in to comment.