Skip to content

Commit

Permalink
Improved and converted more of test_cim_obj to py.test; Fixes in cim_obj
Browse files Browse the repository at this point in the history
Details:
- Converted all test classes for `__str__()` and `__repr__()`
  of CIM object classes to py.test.
- Converted all test classes for `__init__()` of CIM object classes to
  py.test and for those, added tests for the position of init arguments,
  and improved the test cases by adding more cases and asserting the results
  in all cases. Fixed some incorrect tests for <0.12.
- Improved exception message when checking array related things.
- Fixed a bug in cim_obj where setting the `qualifiers` attribute of
  `CIMProperty`, `CIMMethod` and `CIMParameter` did not ensure that the
  items in the input dictionary were converted to `CIMQualifier` objects.
  It now ensures that. Adjusted the test cases accordingly. Note that
  that conversion had already been done for `CIMClass` and `CIMInstance`.
- Fixed a bug in cim_obj where the `DeprecationWarning` when setting the
  deprecated `value` attribute of `CIMParameter` was always issued even
  when the new value was `None` (which is the default value, so the warning
  was issued even when the `value` attribute was not used at all).
  Now, the warning is only issued when the new value is not `None`.
  Adjusted the test cases accordingly.
- The getter method for the deprecated `value` attribute of `CIMParameter`
  also issued a `DeprecationWarning`. Removed that warning because issuing
  it in the setter method is sufficient (the setter method is also used
  when initializing an object). Adjusted the test cases accordingly.

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Dec 22, 2017
1 parent 1e0b880 commit eb32a43
Show file tree
Hide file tree
Showing 2 changed files with 4,642 additions and 1,763 deletions.
43 changes: 30 additions & 13 deletions pywbem/cim_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -3224,8 +3224,13 @@ def qualifiers(self):
@qualifiers.setter
def qualifiers(self, qualifiers):
"""Setter method; for a description see the getter method."""
# We make sure that the dictionary is a NocaseDict object, and that the
# property values are CIMQualifier objects:
# pylint: disable=attribute-defined-outside-init
self._qualifiers = NocaseDict(qualifiers)
self._qualifiers = NocaseDict()
if qualifiers:
for key, value in qualifiers.items():
self._qualifiers[key] = _cim_qualifier(key, value)

def copy(self):
"""
Expand Down Expand Up @@ -3760,8 +3765,13 @@ def qualifiers(self):
@qualifiers.setter
def qualifiers(self, qualifiers):
"""Setter method; for a description see the getter method."""
# We make sure that the dictionary is a NocaseDict object, and that the
# property values are CIMQualifier objects:
# pylint: disable=attribute-defined-outside-init
self._qualifiers = NocaseDict(qualifiers)
self._qualifiers = NocaseDict()
if qualifiers:
for key, value in qualifiers.items():
self._qualifiers[key] = _cim_qualifier(key, value)

def _cmp(self, other):
"""
Expand Down Expand Up @@ -4136,8 +4146,13 @@ def qualifiers(self):
@qualifiers.setter
def qualifiers(self, qualifiers):
"""Setter method; for a description see the getter method."""
# We make sure that the dictionary is a NocaseDict object, and that the
# property values are CIMQualifier objects:
# pylint: disable=attribute-defined-outside-init
self._qualifiers = NocaseDict(qualifiers)
self._qualifiers = NocaseDict()
if qualifiers:
for key, value in qualifiers.items():
self._qualifiers[key] = _cim_qualifier(key, value)

@property
def value(self):
Expand All @@ -4146,17 +4161,16 @@ def value(self):
this attribute does not make any sense. Accessing it will cause a
:term:`DeprecationWarning` to be issued.
"""
warnings.warn(
"The value attribute of CIMParameter is deprecated",
DeprecationWarning)
return self._value

@value.setter
def value(self, value):
"""Setter method; for a description see the getter method."""
warnings.warn(
"The value attribute of CIMParameter is deprecated",
DeprecationWarning)
if value is not None:
warnings.warn(
"The value attribute of CIMParameter (name=%r) is deprecated" %
self.name,
DeprecationWarning)
# pylint: disable=attribute-defined-outside-init
self._value = cimvalue(value, self.type)

Expand Down Expand Up @@ -5861,17 +5875,20 @@ def _check_array_parms(is_array, array_size, value, element_txt):
# _infer_is_array() ensures that, and is supposed to be called

if array_size and not is_array:
raise ValueError("The array_size parameter of %s is not None but "
"the is_array parameter is False." % element_txt)
raise ValueError("The array_size parameter of %s is %r but "
"the is_array parameter is False." %
(element_txt, array_size))

if value is not None:
value_is_array = isinstance(value, (list, tuple))
if not is_array and value_is_array:
raise ValueError("The is_array parameter of %s is False but "
"the value is an array." % element_txt)
"value %r is an array." %
(element_txt, value))
if is_array and not value_is_array:
raise ValueError("The is_array parameter of %s is True but "
"the value is not an array." % element_txt)
"value %r is not an array." %
(element_txt, value))


def _infer_embedded_object(value):
Expand Down
Loading

0 comments on commit eb32a43

Please sign in to comment.