Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved sort_cimobjects() and converted its tests to pytest
Details: * Converted the unit tests for sort_cimobjects() from unittest to pytest, using parametrization. There is now a single test function for all object types. * Added some test cases for sort_cimobjects(), including test cases for invalid input types. * sort_cimobjects() returned the input list if it contained less than 2 items. That is correct from a sorting perspectivem, but does not meet the promise from its documentation to return a *new* list. In fact, there was one testcase that verified the prior behavior by appending an object to the input list and checking that the output list was also appended. Removed that testcase. Also, this approach bypasses the type checks for lists with only one item. Changed that to return an empty list for empty input sequences, and to go through the sort processing also for seqwuences with a single item in order to get the type checks. * sort_cimobjects() used a dictionary for sorting in some cases. That prevented providing input objects that have equal sort keys, and reduced them to a single object in the result. Since providing objects with equal sort keys is valid and not excluded in the documentation, this was improved to always use sorted() with an appropriate key. sorted() invokes the key function on each item only once, so for expensive key functions this is not worse as before. Added testcases to verify that objects with equal keys now work. * Changed the exception that is raised when a tuple does not contain the required CIMClassName, CIMClass items from AssertionError to TypeError, for consistency with the other TypeError that is raised. * Changed the exception that is raised when a CIMInstance object does not have its path set, from AttributeError to ValueError. Added testcase for that. * Updated the docstring of sort_cimobjects() to describe the sorting for each object type more precisely. Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
- Loading branch information