def test_objectstore(testcase, init_args, cls_kwargs, inst_kwargs, qual_kwargs): # pylint: disable=unused-argument """ Simple test inserts one inst of defined type and tests retrievail methods. """ namespace = "root/cimv2" # Setup the ObjectStore xxx_repo = InMemoryObjectStore(*init_args) if cls_kwargs: cls = CIMClass(**cls_kwargs) if inst_kwargs: inst = CIMInstance(**inst_kwargs) inst.path = CIMInstanceName.from_instance( cls, inst, namespace=namespace, host='me', strict=True) if qual_kwargs: qual = CIMQualifierDeclaration(**qual_kwargs) # Is this instance or class test if inst_kwargs: name = inst.path obj = inst elif qual_kwargs: name = qual.name obj = qual else: name = cls.classname obj = cls # The code to be tested. The test include adding , getting, and deleting # with the various inspection methods and testing for # correct returns # Create the object in the object store xxx_repo.create(name, obj) # confirm that exists works assert xxx_repo.object_exists(name) # Test repository object count; len() assert xxx_repo.len() == 1 # Test get the object and test for same object rtn_obj = xxx_repo.get(name) # Test that the properties have changed indicating the deepcopy # Uses only class and instance because we they have properties if isinstance(obj, (CIMClass, CIMInstance)): for prop in obj.properties: assert rtn_obj.properties[prop] is not \ obj.properties[prop] # Test same object return on two gets rtn_obj2 = xxx_repo.get(name) assert rtn_obj2 == rtn_obj # Test that return with copy gets same object. rtn_obj3 = xxx_repo.get(name, copy=True) assert rtn_obj3 == obj # Test that with copy=True the property ids have changed between the # two gets indicating that the deepcopy was executed. if isinstance(obj, (CIMClass, CIMInstance)): for prop in obj.properties: assert rtn_obj.properties[prop] is not \ rtn_obj3.properties[prop] names = list(xxx_repo.iter_names()) assert len(names) == 1 assert names[0] == name objs = list(xxx_repo.iter_values()) assert len(objs) == 1 assert objs[0] == obj objs = list(xxx_repo.iter_values(copy=True)) assert len(objs) == 1 assert objs[0] == obj if isinstance(obj, (CIMClass, CIMInstance)): for prop in obj.properties: assert objs[0].properties[prop] is not \ obj.properties[prop] # Test update # Test update; should work. Note that this test does not modify the # object before creating the copy. obj2 = obj.copy() xxx_repo.update(name, obj2) assert xxx_repo.get(name) == obj2 # Test valid delete of object xxx_repo.delete(name) assert not xxx_repo.object_exists(name) assert xxx_repo.len() == 0 # Test errors # Test update with unknown object; should fail try: xxx_repo.update(name, obj) except KeyError: pass # Test delete nonexistent entity; should fail try: xxx_repo.delete(name) assert False except KeyError: pass # Test get non existent entity; should fail try: xxx_repo.get(name) assert False except KeyError: pass # Test exists; entity should not exist assert not xxx_repo.object_exists(name) # Test create with existing object xxx_repo.create(name, obj) # Test duplicate create; should fail try: xxx_repo.create(name, obj) assert False except ValueError: pass
repo.remove_namespace(test_ns) print(exec_info) TEST_OBJECTS = [ CIMClass('Foo', properties=[ CIMProperty('P1', None, type='string', qualifiers=[CIMQualifier('Key', value=True)])]), CIMClass('Bar', properties=[ CIMProperty('P2', None, type='string', qualifiers=[CIMQualifier('Key', value=True)])]), CIMInstance('Foo', path=CIMInstanceName('Foo', keybindings=NocaseDict(P1="P1"))), CIMInstance('Bar', path=CIMInstanceName('Bar', keybindings=NocaseDict(P2="P2"))), CIMQualifierDeclaration('Qual1', type='string'), CIMQualifierDeclaration('Qual2', type='string'), ] TEST_OBJECTS2 = [ CIMClass('Foo', properties=[ CIMProperty('P2', None, type='string', qualifiers=[CIMQualifier('Key', value=True)])]), CIMInstance('Foo', path=CIMInstanceName('Foo', keybindings=NocaseDict(P2="P2"))), ] @pytest.mark.parametrize( # Testcases for Inmemory repository object management tests # Each list item is a testcase tuple with these items:
def test_leaks_CIMQualifierDeclaration_minimal(): """ Test function with a minimal CIMQualifierDeclaration object (i.e. no scopes). """ _ = CIMQualifierDeclaration('Q1', type='string')
("Non-existing top level namespace", dict( namespace='abc', namespace_content={}, exp_namespace=None, ), CIMError, None, True), ("Non-empty top level namespace containing a class", dict( namespace='abc', namespace_content={'abc': [CIMClass('Foo')]}, exp_namespace=None, ), CIMError, None, True), ("Non-empty top level namespace containing a qualifier type", dict( namespace='abc', namespace_content={'abc': [CIMQualifierDeclaration('Foo', 'string')]}, exp_namespace=None, ), CIMError, None, True), ("Existing Interop namespace", dict( namespace='interop', namespace_content={}, exp_namespace=None, ), CIMError, None, True), ("Second non-existing Interop namespace", dict( namespace='root/interop', namespace_content={}, exp_namespace=None, ), CIMError, None, True), ]
def test_objectstore(testcase, init_args, cls_kwargs, inst_kwargs, qual_kwargs): # pylint: disable=unused-argument """ Simple test inserts one inst of defined type and tests retrievail methods. """ namespace = "root/cimv2" # Setup the ObjectStore xxx_repo = InMemoryObjectStore(*init_args) if cls_kwargs: cls = CIMClass(**cls_kwargs) if inst_kwargs: inst = CIMInstance(**inst_kwargs) inst.path = CIMInstanceName.from_instance( cls, inst, namespace=namespace, host='me', strict=True) if qual_kwargs: qual = CIMQualifierDeclaration(**qual_kwargs) # is this instance or class test if inst_kwargs: name = inst.path obj = inst elif qual_kwargs: name = qual.name obj = qual else: name = cls.classname obj = cls # The code to be tested. The test include adding and testing the # various inspection methods for correct returns # Create the object in the object store xxx_repo.create(name, obj) # confirm that exists works assert xxx_repo.exists(name) # Test len() assert xxx_repo.len() == 1 # Test get the object and test for same object rtn_obj = xxx_repo.get(name) assert rtn_obj == obj names = [n for n in xxx_repo.iter_names()] assert len(names) == 1 assert names[0] == name objs = [x for x in xxx_repo.iter_values()] assert len(objs) == 1 assert objs[0] == obj # Test update # Test update; should work obj2 = obj.copy() xxx_repo.update(name, obj2) assert xxx_repo.get(name) == obj2 # Test valid delete of object xxx_repo.delete(name) assert not xxx_repo.exists(name) assert xxx_repo.len() == 0 # Test errors # Test update with unknown object; should fail try: xxx_repo.update(name, obj) except KeyError: pass # Test delete nonexistent entity; should fail try: xxx_repo.delete(name) assert False except KeyError: pass # Test get non existent entity; should fail try: xxx_repo.get(name) assert False except KeyError: pass # Test exists; entity should not exist assert not xxx_repo.exists(name) # Test create with existing object xxx_repo.create(name, obj) # Test duplicate create; should fail try: xxx_repo.create(name, obj) assert False except ValueError: pass