def test_findFileByAttribute(self): """ Tests whether a file node can be found solely by its specified attributes. """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[3]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) xmlfile = ET.parse(self.testFileDestinations[0]) xmlroot = xmlfile.getroot() headerEt = list(xmlroot)[0] expectedFile = list(headerEt)[3] fileToFind = p.topicList[0].header.files[3] finding = writer.getEtElementFromFile(xmlroot, fileToFind) project.debug("writer_tests.test_findFileByAttribute(): found file:"\ "\n\t{}\nand expected file\n{}"\ "\n=====".format(ET.tostring(finding), ET.tostring(expectedFile))) self.assertEqual(ET.tostring(finding), ET.tostring(expectedFile))
def test_findComment2(self): """ Tests whether the right comment is found if the text of one child differs only by one character """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[1]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) xmlfile = ET.parse(self.testFileDestinations[0]) xmlroot = xmlfile.getroot() expectedComment = list(xmlroot)[3] commentToFind = p.topicList[0].comments[1] finding = writer.getEtElementFromFile(xmlroot, commentToFind) project.debug("writer_tests.test_findComment2(): found comment:"\ "\n\t{}\nand expected comment\n{}"\ "\n=====".format(ET.tostring(finding), ET.tostring(expectedComment))) self.assertEqual(ET.tostring(expectedComment), ET.tostring(finding))
def test_findLabelByText(self): """ Tests whether a label can be found just by the text it contains. """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[2]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) xmlfile = ET.parse(self.testFileDestinations[0]) xmlroot = xmlfile.getroot() topicEt = list(xmlroot)[1] expectedLabel = list(topicEt)[5] labelToFind = p.topicList[0].topic.labels[2] finding = writer.getEtElementFromFile(xmlroot, labelToFind) project.debug("writer_tests.test_findLabelByText(): found label:"\ "\n\t{}\nand expected label\n{}"\ "\n=====".format(ET.tostring(finding), ET.tostring(expectedLabel))) self.assertEqual(ET.tostring(finding), ET.tostring(expectedLabel))
def test_addLabel(self): """ Tests the addition of a label """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[10]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) t = p.topicList[0].topic newLabel = "Hello" t.labels.append(newLabel) writer.addElement(t.labels[-1]) (equal, diff) = compareFiles(self.checkFiles[10], self.testFileDir, self.testTopicDir, self.testBCFName) if not equal: wrongFileDestination = os.path.join(self.testFileDir, "error_files", "markup_add_label.bcf") copyfile(self.testFileDestinations[0], wrongFileDestination) project.debug("copied erroneous file to"\ " {}".format(wrongFileDestination)) project.debug("Following is the diff between the file that was generated"\ " and the prepared file:".format( wrongFileDestination)) pprint.pprint(diff) self.assertTrue(equal)
def test_addAssignedTo(self): """ Tests the addition of the AssignedTo node to a topic """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[11]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) t = p.topicList[0].topic t.assignee = "[email protected]" t._assignee.state = s.State.States.ADDED writer.addElement(t._assignee) (equal, diff) = compareFiles(self.checkFiles[11], self.testFileDir, self.testTopicDir, self.testBCFName) if not equal: wrongFileDestination = os.path.join(self.testFileDir, "error_files", "markup_add_assignedTo.bcf") copyfile(self.testFileDestinations[0], wrongFileDestination) project.debug("copied erroneous file to"\ " {}".format(wrongFileDestination)) project.debug("Following is the diff between the file that was generated"\ " and the prepared file:".format( wrongFileDestination)) pprint.pprint(diff) self.assertTrue(equal)
def test_addBimSnippetAttribute(self): """ Tests the addition of the optional attribute of BimSnippet """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[9]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) bimSnippet = p.topicList[0].topic.bimSnippet bimSnippet.external = True bimSnippet.state = s.State.States.ADDED writer.addElement(bimSnippet._external) (equal, diff) = compareFiles(self.checkFiles[9], self.testFileDir, self.testTopicDir, self.testBCFName) if not equal: wrongFileDestination = os.path.join(self.testFileDir, "error_files", "markup_add_bim_snippet.bcf") copyfile(self.testFileDestinations[0], wrongFileDestination) project.debug("copied erroneous file to"\ " {}".format(wrongFileDestination)) project.debug("Following is the diff between the file that was generated"\ " and the prepared file:".format( wrongFileDestination)) pprint.pprint(diff) self.assertTrue(equal)
def test_addDocumentReferenceAttributes(self): """ Tests the addition of the optional attributes to one of the document reference nodes. """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[8]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) docRef = p.topicList[0].topic.docRefs[0] docRef.guid = "98b5802c-4ca0-4032-9128-b9c606955c4f" docRef._guid.state = s.State.States.ADDED writer.addElement(docRef._guid) (equal, diff) = compareFiles(self.checkFiles[8], self.testFileDir, self.testTopicDir, self.testBCFName) if not equal: wrongFileDestination = os.path.join( self.testFileDir, "error_files", "markup_add_doc_ref_attribute.bcf") copyfile(self.testFileDestinations[0], wrongFileDestination) project.debug("copied erroneous file to"\ " {}".format(wrongFileDestination)) project.debug("Following is the diff between the file that was generated"\ " and the prepared file:".format( wrongFileDestination)) pprint.pprint(diff) self.assertTrue(equal)
def test_addFileAttributes2(self): """ Tests the addition of the optional attributes to one of the file nodes """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[7]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) m = p.topicList[0] file = m.header.files[0] file.ifcSpatialStructureElement = "aaaabbbbcccc" file._ifcSpatialStructureElement.state = s.State.States.ADDED writer.addElement(file._ifcSpatialStructureElement) (equal, diff) = compareFiles(self.checkFiles[7], self.testFileDir, self.testTopicDir, self.testBCFName) if not equal: wrongFileDestination = os.path.join( self.testFileDir, "error_files", "markup_add_file_attribute2.bcf") copyfile(self.testFileDestinations[0], wrongFileDestination) project.debug("copied erroneous file to"\ " {}".format(wrongFileDestination)) project.debug("Following is the diff between the file that was generated"\ " and the prepared file:".format(wrongFileDestination)) pprint.pprint(diff) self.assertTrue(equal)
def test_addMarkup(self): """ Tests the addition of a whole new markup object. This should result in the creation of a new folder as well as a new markup.bcf file and a new viewpoint file. """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[0]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) newMarkup = copy.deepcopy(p.topicList[0]) newMarkup.containingObject = p newMarkup.state = s.State.States.ADDED newMarkup.topic.xmlId = uuid4() # generate random uuid p.topicList.append(newMarkup) writer.addElement(newMarkup) folderPath = os.path.join(util.getSystemTmp(), self.testBCFName, str(newMarkup.topic.xmlId)) folderExists = os.path.exists(folderPath) if not folderExists: project.debug("Folder does not exist") markupFilePath = os.path.join(folderPath, "markup.bcf") markupFileExists = os.path.exists(markupFilePath) if not markupFileExists: project.debug("Markup file does not exist") self.assertTrue(markupFileExists and folderExists)
def setupBCFFile(testFile, testFileDir, testTopicDir, testBCFName): cmd = "cp {} {}/{}/markup.bcf".format(testFile, testFileDir, testTopicDir) project.debug("Executing: {}".format(cmd)) os.system(cmd) cmd = "cd ./writer_tests && zip -q {} {}/markup.bcf".format( testBCFName, testTopicDir) project.debug("Executing: {}".format(cmd)) os.system("cd ./writer_tests && zip -q {} {}/markup.bcf".format( testBCFName, testTopicDir)) return os.path.join(testFileDir, testBCFName)
def test_searchIsExternal(self): srcFilePath = os.path.join(self.testFileDir, self.testFiles[0]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) externalToFind = p.topicList[0].header.files[1]._external searchResult = p.searchObject(externalToFind) if searchResult == None: project.debug("Did not find anything") self.assertTrue(searchResult is not None and externalToFind.id == searchResult.id)
def test_addFile(self): """ Tests the addition of a file element in the header node """ srcFilePath = os.path.join(self.testFileDir, self.testFiles[5]) testFile = setupBCFFile(srcFilePath, self.testFileDir, self.testTopicDir, self.testBCFName) p = reader.readBcfFile(testFile) m = p.topicList[0] header = m.header newFile = markup.HeaderFile( ifcProjectId="abcdefghij", ifcSpatialStructureElement="klmnopqrs", isExternal=False, filename="this is some file name", time=dateutil.parser.parse("2014-10-16T13:10:56+00:00"), reference="/path/to/the/file", containingElement=header, state=s.State.States.ADDED) header.files.append(newFile) project.debug("type of newFile is" " {}".format(type(newFile))) writer.addElement(newFile) (equal, diff) = compareFiles(self.checkFiles[5], self.testFileDir, self.testTopicDir, self.testBCFName) if not equal: wrongFileDestination = os.path.join(self.testFileDir, "error_files", "markup_add_file.bcf") copyfile(self.testFileDestinations[0], wrongFileDestination) project.debug("copied erroneous file to"\ " {}".format(self.test_add_file.__name__, wrongFileDestination)) project.debug("Following is the diff between the file that was generated"\ " and the prepared file:".format( self.test_add_viewpointreference.__name__, wrongFileDestination)) pprint.pprint(diff) self.assertTrue(equal)