def testRowDictInitialization(self): """Test case - Row dictionary initialization of a data category and data block """ try: # rLen = 10 fn = self.__pathOutputFile5 attributeNameList = ["a", "b", "c", "d"] rowList = [{"a": 1, "b": 2, "c": 3, "d": 4} for i in range(rLen)] nameCat = "myCategory" # # curContainer = DataContainer("myblock") aCat = DataCategory(nameCat, attributeNameList, rowList) aCat.append({"a": 1, "b": 2, "c": 3, "d": 4}) aCat.append({"a": 1, "b": 2, "c": 3, "d": 4}) aCat.extend(rowList) curContainer.append(aCat) aCat.renameAttributes({"a": "aa", "b": "bb", "c": "cc", "d": "dd"}) aCat.setName("renamedCategory") # # myContainerList = [] myContainerList.append(curContainer) ofh = open(fn, "w") pdbxW = PdbxWriter(ofh) pdbxW.write(myContainerList) ofh.close() myContainerList = [] ifh = open(fn, "r") pRd = PdbxReader(ifh) pRd.read(myContainerList) ifh.close() for container in myContainerList: for objName in container.getObjNameList(): name, aList, rList = container.getObj(objName).get() logger.debug("Recovered data category %s", name) logger.debug("Attribute list %r", repr(aList)) logger.debug("Row list %r", repr(rList)) self.assertEqual(len(myContainerList), 1) self.assertEqual(len(rList), 2 * rLen + 2) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def test_row_dict_initialization(self, rw_data): rLen = 10 fn = rw_data['pathOutputFile5'] attributeNameList = ['a', 'b', 'c', 'd'] rowList = [{'a': 1, 'b': 2, 'c': 3, 'd': 4} for i in range(rLen)] nameCat = 'myCategory' # # curContainer = DataContainer("myblock") aCat = DataCategory(nameCat, attributeNameList, rowList) aCat.append({'a': 1, 'b': 2, 'c': 3, 'd': 4}) aCat.append({'a': 1, 'b': 2, 'c': 3, 'd': 4}) aCat.extend(rowList) curContainer.append(aCat) aCat.renameAttributes({'a': 'aa', 'b': 'bb', 'c': 'cc', 'd': 'dd'}) aCat.setName('renamedCategory') # # myContainerList = [] myContainerList.append(curContainer) ofh = open(str(fn), "w") pdbxW = PdbxWriter(ofh) pdbxW.write(myContainerList) ofh.close() myContainerList = [] ifh = open(str(fn), "r") pRd = PdbxReader(ifh) pRd.read(myContainerList) ifh.close() for container in myContainerList: for objName in container.getObjNameList(): name, aList, rList = container.getObj(objName).get() print("Recovered data category %s\n" % name) print("Attribute list %r\n" % repr(aList)) print("Row list %r\n" % repr(rList)) assert len(myContainerList) == 1 assert len(rList) == 2 * rLen + 2