def test_deleteViewpointReference(self):
        """
        Tests the deletion of a viewpoint reference while preserving the
        underlying viewpoint object
        """

        srcFilePath = os.path.join(self.testFileDir, self.testFiles[0])
        testFile = setupBCFFile(srcFilePath, self.testFileDir,
                                self.testTopicDir, self.testBCFName)
        if pI.openProject(testFile) == pI.OperationResults.FAILURE:
            print("Could not open file")
            self.assertTrue(False)

        objectToDelete = pI.curProject.topicList[0].viewpoints[0]
        objectToDelete.state = s.State.States.DELETED
        pI.deleteObject(objectToDelete)
        newProject = pI.curProject

        vpList = newProject.topicList[0].viewpoints
        searchResult = newProject.searchObject(objectToDelete)
        vpFilePath = os.path.join(util.getSystemTmp(), self.testBCFName,
                                  self.testTopicDir, "viewpoint.bcfv")
        vpFileExists = os.path.exists(vpFilePath)

        self.assertTrue(
            len(vpList) == 0 and searchResult == None and vpFileExists)
 def setUp(self):
     self.testFileDir = "./interface_tests"
     self.testTopicDir = "2e92784b-80fc-4e0e-ac02-b424dfd8e664"
     self.testBCFName = "Issues-Example.bcf"
     self.markupDestDir = os.path.join(util.getSystemTmp(),
                                       self.testBCFName, self.testTopicDir)
     self.testFiles = ["markup_interface_test.bcf"]
    def test_deleteViewpoint(self):
        """
        Tests whether the referenced viewpoint file gets deleted if the
        viewpoint reference is deleted AND the state of viewpoint is also
        DELETED.
        """

        srcFilePath = os.path.join(self.testFileDir, self.testFiles[4])
        testFile = setupBCFFile(srcFilePath, self.testFileDir,
                                self.testTopicDir, self.testBCFName)
        p = reader.readBcfFile(testFile)

        vpRefToDelete = p.topicList[0].viewpoints[0]
        vpRefToDelete.state = s.State.States.DELETED
        vpRefToDelete.viewpoint.state = s.State.States.DELETED
        writer.deleteElement(vpRefToDelete)

        vpFilePath = os.path.join(util.getSystemTmp(), self.testBCFName,
                                  self.testTopicDir, "viewpoint.bcfv")
        stillExists = os.path.exists(vpFilePath)
        equal = handleFileCheck(self.checkFiles[4], "markup.bcf",
                                self.testFileDir, self.testTopicDir,
                                self.testBCFName)

        if not equal or stillExists:
            printVimDiffCommand(self.testFileDir, self.checkFiles[4])

        self.assertTrue((not stillExists) and equal, "Failed to delete the "\
                "viewpoint and the accompanying file"\
                " {}".format(vpRefToDelete.viewpoint))
def handleFileCheck(expectedFile, fileName, testFileDir, testTopicDir,
                    testBCFName):
    """
    Compares the working file with `expectedFile`. If they are different then
    the working file is copied to `testFileDir/error.bcf` for human
    inspection. True is returned if both files are equal, false otherwise.
    """

    (equal, diff) = compareFiles(expectedFile, testFileDir, testTopicDir,
                                 testBCFName)
    if not equal:
        wrongFileDestination = os.path.join(testFileDir, "error.bcf")
        testFilePath = os.path.join(util.getSystemTmp(), testBCFName,
                                    testTopicDir, fileName)
        copyfile(testFilePath, wrongFileDestination)
        print("writer_tests.{}(): copied erroneous file to"\
                " {}".format(handleFileCheck.__name__,
                    wrongFileDestination))
        print("writer_tests.{}(): Following is the diff between the file that was generated"\
            " and the prepared file:".format(
                handleFileCheck.__name__,
                wrongFileDestination))
        pprint.pprint(diff)

    return 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 setUp(self):

        self.testFileDir = "./writer_tests"
        self.testTopicDir = "2e92784b-80fc-4e0e-ac02-b424dfd8e664"
        self.testBCFName = "Issues-Example.bcf"
        self.markupDestDir = os.path.join(util.getSystemTmp(),
                                          self.testBCFName, self.testTopicDir)
        self.testFiles = ["markup_modify_comment_test.bcf"]
        self.checkFiles = ["markup_modify_comment_check.bcf"]
 def setUp(self):
     self.testFileDir = "./writer_tests"
     self.testTopicDir = "2e92784b-80fc-4e0e-ac02-b424dfd8e664"
     self.testBCFName = "Issues-Example.bcf"
     self.markupDestDir = os.path.join(util.getSystemTmp(),
                                       self.testBCFName, self.testTopicDir)
     self.testFiles = [
         "markup_find_comment_test.bcf", "markup_find_comment2_test.bcf",
         "markup_find_label_by_text_test.bcf",
         "markup_find_file_by_attribute_test.bcf"
     ]
     self.checkFiles = ["markup_find_comment_check.bcf"]
     self.testFileDestinations = [
         os.path.join(self.markupDestDir, "markup.bcf"),
         os.path.join(self.markupDestDir, "viewpoint.bcfv"),
         os.path.join(self.markupDestDir, "viewpoint2.bcfv")
     ]
    def setUp(self):
        self.fileDirectory = "./reader_tests/"
        self.bcfFile = "Issues-Example.bcf"

        self.topicGuid = "0a36e3d6-97e9-47d6-ab4f-227990429f52"
        self.extractionPath = reader.extractFileToTmp(self.fileDirectory +
                                                      self.bcfFile)
        self.markupFiles = [
            "topic_complete.bcf", "topic_13_comments.bcf",
            "topic_original.bcf", "topic_minimal.bcf"
        ]
        self.markupFilePaths = map(
            lambda item: os.path.join(self.extractionPath, self.topicGuid, item
                                      ), self.markupFiles)
        self.markupDestinationPath = os.path.join(util.getSystemTmp(),
                                                  self.extractionPath,
                                                  self.topicGuid, "markup.bcf")
        self.markupSchemaPath = self.fileDirectory + "markup.xsd"
    def setUp(self):

        self.fileDirectory = "./reader_tests/"
        self.bcfFile = "Issues-Example.bcf"

        # comments are contained in markup.bcf
        self.topicGuid = "0a36e3d6-97e9-47d6-ab4f-227990429f52"
        self.extractionPath = reader.extractFileToTmp(self.fileDirectory +
                                                      self.bcfFile)
        self.viewpointFiles = [
            "viewpoint_complete.bcfv", "viewpoint_minimal.bcfv",
            "viewpoint_original.bcfv"
        ]
        self.viewpointFilePath = map(
            lambda item: os.path.join(self.extractionPath, self.topicGuid, item
                                      ), self.viewpointFiles)
        self.viewpointDestinationPath = os.path.join(util.getSystemTmp(),
                                                     self.extractionPath,
                                                     self.topicGuid,
                                                     "viewpoint.bcfv")
        self.viewpointSchemaPath = self.fileDirectory + "visinfo.xsd"
 def setUp(self):
     self.testFileDir = "./writer_tests"
     self.testTopicDir = "2e92784b-80fc-4e0e-ac02-b424dfd8e664"
     self.testBCFName = "Issues-Example.bcf"
     self.markupDestDir = os.path.join(util.getSystemTmp(),
                                       self.testBCFName, self.testTopicDir)
     self.testFiles = [
         "markup_add_comment_test.bcf",
         "markup_add_comment_modification_test.bcf",
         "markup_add_lone_viewpoint_test.bcf",
         "markup_add_full_viewpoint_test.bcf",
         "",  # dummy element to keep both lists equal in length
         "markup_add_file_test.bcf",
         "markup_add_file_attribute_test.bcf",
         "markup_add_file_attribute2_test.bcf",
         "markup_add_doc_ref_attribute_test.bcf",
         "markup_add_bim_snippet_attribute_test.bcf",
         "markup_add_label_test.bcf",
         "markup_add_assigned_to_test.bcf"
     ]
     self.checkFiles = [
         "markup_add_comment_check.bcf",
         "markup_add_comment_modification_check.bcf",
         "markup_add_lone_viewpoint_check.bcf",
         "markup_add_full_viewpoint_check.bcf",
         "viewpoint_add_full_viewpoint_check.bcfv",
         "markup_add_file_check.bcf", "markup_add_file_attribute_check.bcf",
         "markup_add_file_attribute2_check.bcf",
         "markup_add_doc_ref_attribute_check.bcf",
         "markup_add_bim_snippet_attribute_check.bcf",
         "markup_add_label_check.bcf", "markup_add_assigned_to_check.bcf"
     ]
     self.testFileDestinations = [
         os.path.join(self.markupDestDir, "markup.bcf"),
         os.path.join(self.markupDestDir, "viewpoint.bcfv"),
         os.path.join(self.markupDestDir, "viewpoint2.bcfv")
     ]
def compareFiles(checkFile, testFileDir, testTopicDir, testBCFName):

    testFilePath = os.path.join(util.getSystemTmp(), testBCFName, testTopicDir)
    if checkFile.startswith("markup"):
        testFilePath = os.path.join(testFilePath, "markup.bcf")
    elif checkFile.startswith("viewpoint"):
        testFilePath = os.path.join(testFilePath, "viewpoint.bcfv")

    checkFilePath = os.path.join(testFileDir, checkFile)

    with open(testFilePath, 'r') as testFile:
        with open(checkFilePath, 'r') as checkFile:
            testFileText = testFile.readlines()
            if testFileText[-1][-1] != "\n":
                testFileText[-1] += "\n"
            checkFileText = checkFile.readlines()
            differ = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK)
            resultDiffText = list(differ.compare(testFileText, checkFileText))
            resultList = [False for item in resultDiffText if item[0] != ' ']

            if len(resultList) > 0:
                return (False, resultDiffText)
            else:
                return (True, None)
 def tearDown(self):
     dirPath = os.path.join(util.getSystemTmp(), self.testBCFName)
     rmtree(dirPath)