def testNoConflicts(self): """Test combination with valid values and no overlap, except COMMENT and HISTORY, which are combined """ md1 = PropertyList() md1.set("int1", [1, 2]) md1.set("float1", 1.23) md1.set("string1", "md1 string1 value") md1.set("COMMENT", "md1 comment") md1.set("HISTORY", "md1 history") md1Copy = md1.deepCopy() md2 = PropertyList() md2.set("int2", 2) md2.set("float2", [2.34, -3.45]) md2.set("string2", "md2 string2 value") md2.set("COMMENT", "md2 comment") md2.set("HISTORY", "md2 history") md2Copy = md2.deepCopy() result = combineMetadata(md1, md2) self.assertEqual(result.getOrderedNames(), [ "int1", "float1", "string1", "COMMENT", "HISTORY", "int2", "float2", "string2" ]) self.assertEqual(result.get("COMMENT"), ["md1 comment", "md2 comment"]) self.assertEqual(result.get("HISTORY"), ["md1 history", "md2 history"]) for name in md1.getOrderedNames(): if name in ("COMMENT", "HISTORY"): continue self.assertEqual(result.get(name), getLast(md1.get(name))) for name in md2.getOrderedNames(): if name in ("COMMENT", "HISTORY"): continue self.assertEqual(result.get(name), getLast(md2.get(name))) # input should be unchanged self.assertMetadataEqual(md1, md1Copy) self.assertMetadataEqual(md2, md2Copy)
def testNoConflicts(self): """Test combination with valid values and no overlap, except COMMENT and HISTORY, which are combined """ md1 = PropertyList() md1.set("int1", [1, 2]) md1.set("float1", 1.23) md1.set("string1", "md1 string1 value") md1.set("COMMENT", "md1 comment") md1.set("HISTORY", "md1 history") md1Copy = md1.deepCopy() md2 = PropertyList() md2.set("int2", 2) md2.set("float2", [2.34, -3.45]) md2.set("string2", "md2 string2 value") md2.set("COMMENT", "md2 comment") md2.set("HISTORY", "md2 history") md2Copy = md2.deepCopy() result = combineMetadata(md1, md2) self.assertEqual(result.getOrderedNames(), ["int1", "float1", "string1", "COMMENT", "HISTORY", "int2", "float2", "string2"]) self.assertEqual(result.getArray("COMMENT"), ["md1 comment", "md2 comment"]) self.assertEqual(result.getArray("HISTORY"), ["md1 history", "md2 history"]) for name in md1.getOrderedNames(): if name in ("COMMENT", "HISTORY"): continue self.assertEqual(result.getScalar(name), md1.getArray(name)[-1]) for name in md2.getOrderedNames(): if name in ("COMMENT", "HISTORY"): continue self.assertEqual(result.getScalar(name), md2.getArray(name)[-1]) # input should be unchanged self.assertMetadataEqual(md1, md1Copy) self.assertMetadataEqual(md2, md2Copy)
def testIgnoreInvalid(self): """Test that invalid items in the either argument are ignored """ md1 = PropertyList() # Set COMMENT and HISTORY to invalid values -- anything other than string # (regardless if it is a scalar or an array); # for md1 use arrays and md2 use scalars, just to try both md1.set("COMMENT", [5, 6]) md1.set("HISTORY", [3.5, 6.1]) md1Copy = md1.deepCopy() md2 = PropertyList() # Set COMMENT and HISTORY to invalid values; see comment above md1.set("COMMENT", ...) md2.set("COMMENT", 7) md2.set("HISTORY", 1.06) md2Copy = md2.deepCopy() result = combineMetadata(md1, md2) resultNames = result.getOrderedNames() self.assertEqual(resultNames, []) # input should be unchanged self.assertMetadataEqual(md1, md1Copy) self.assertMetadataEqual(md2, md2Copy)
def testReplaceDuplicates(self): """Test that names in `second` override those in `first`, regardless of type """ # names that start with "item" appear in both sets of metadata md1 = PropertyList() md1.set("int1", 5) md1.set("itema", [1, 2]) md1.set("float1", 3.1) md1.set("itemb", 1.23) md1.set("string1", "md1 string1 value") md1.set("itemc", "md1 string value") md1Copy = md1.deepCopy() md2 = PropertyList() md2.set("itemc", 2) md2.set("int2", 2) md2.set("itemb", ["some data", "more data"]) md2.set("float2", 2.34) md2.set("itema", 5.27) md2.set("string2", "md2 string value") md2Names = md2.getOrderedNames() md2Copy = md2.deepCopy() result = combineMetadata(md1, md2) expectedNames = ["int1", "float1", "string1"] + list(md2Names) self.assertEqual(result.getOrderedNames(), expectedNames) md2NameSet = set(md2Names) for name in result.getOrderedNames(): if name in md2NameSet: self.assertEqual(result.get(name), getLast(md2.get(name))) else: self.assertEqual(result.get(name), getLast(md1.get(name))) # input should be unchanged self.assertMetadataEqual(md1, md1Copy) self.assertMetadataEqual(md2, md2Copy)
def testReplaceDuplicates(self): """Test that names in `second` override those in `first`, regardless of type """ # names that start with "item" appear in both sets of metadata md1 = PropertyList() md1.set("int1", 5) md1.set("itema", [1, 2]) md1.set("float1", 3.1) md1.set("itemb", 1.23) md1.set("string1", "md1 string1 value") md1.set("itemc", "md1 string value") md1Copy = md1.deepCopy() md2 = PropertyList() md2.set("itemc", 2) md2.set("int2", 2) md2.set("itemb", ["some data", "more data"]) md2.set("float2", 2.34) md2.set("itema", 5.27) md2.set("string2", "md2 string value") md2Names = md2.getOrderedNames() md2Copy = md2.deepCopy() result = combineMetadata(md1, md2) expectedNames = ["int1", "float1", "string1"] + list(md2Names) self.assertEqual(result.getOrderedNames(), expectedNames) md2NameSet = set(md2Names) for name in result.getOrderedNames(): if name in md2NameSet: self.assertEqual(result.getScalar(name), md2.getArray(name)[-1]) else: self.assertEqual(result.getScalar(name), md1.getArray(name)[-1]) # input should be unchanged self.assertMetadataEqual(md1, md1Copy) self.assertMetadataEqual(md2, md2Copy)