Skip to content

Commit

Permalink
Bug fixes due to testing
Browse files Browse the repository at this point in the history
__str__ function was implemented for some classes, to be better able to
debug/trace failing test cases.
Additionally in reader comments now get the right viewpoint reference
assigned in a second step inside `buildMarkup()`.
Bug fixes in reader.py
reader.getViewpointRefByGuid() was added for the second step in
buildMarkup() in which the comments get assigned the right reference to
the viewpoints. Before this step is executed only a temporary
ViewpointReference object exists that holds just the Viewpoint Guid.
  • Loading branch information
podestplatz committed Jun 3, 2019
1 parent c94d812 commit 7a31462
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 34 deletions.
39 changes: 39 additions & 0 deletions src/bcf/markup.py
Expand Up @@ -72,12 +72,22 @@ def __eq__(self, other):
Returns true if every variable member of both classes are the same
"""

if other is None:
return False

return (self.id == other.id and
self.file == other.file and
self.snapshot == other.snapshot and
self.index == other.index)


def __str__(self):
ret_str = ("ViewpointReference(id='{}', file='{}', snapshot='{}',"\
" index='{}'").format(self.id, self.file, self.snapshot,
self.index)
return ret_str


class Comment:

""" Class holding all data about a comment """
Expand All @@ -102,12 +112,23 @@ def __eq__(self, other):
Returns true if every variable member of both classes are the same
"""

if other is None:
return False

return (self.creation == other.creation and
self.comment == other.comment and
self.viewpoint == other.viewpoint and
self.lastModification == other.lastModification)


def __str__(self):

ret_str = ("Comment(\n\tcreation='{}', \n\tcomment='{}', \n\tviewpoint='{}',"\
"\n\tlastModification='{}')").format(self.creation, self.comment,
str(self.viewpoint), self.lastModification)
return ret_str


class Markup:

""" Every topic folder has exactly one markup.bcf file. This forms the
Expand Down Expand Up @@ -139,6 +160,24 @@ def __eq__(self, other):
self.viewpoints == other.viewpoints)


def getViewpointRefByGuid(self, guid: UUID):

"""
Searches in the list of viewpoints for one whose id matches `guid` and
returns the first one found if more than one were found (wich should not
happen btw). If none were found or the viewpoints list is `None` then
`None` is returned.
"""

if self.viewpoints is None:
return None

resultList = list(filter(lambda item: item.id == guid, self.viewpoints))
if len(resultList) >= 1:
return resultList[0]
return None


def getViewpointFileList(self):

"""
Expand Down
7 changes: 7 additions & 0 deletions src/bcf/modification.py
Expand Up @@ -25,3 +25,10 @@ def __eq__(self, other):
"""

return self.author == other.author and self.date == other.date


def __str__(self):

ret_str = "Modification(author='{}', datetime='{}')".format(self.author,
self.date)
return ret_str
54 changes: 28 additions & 26 deletions src/bcf/reader.py
Expand Up @@ -10,7 +10,7 @@
from bcf import util
from bcf.uri import Uri as Uri
from bcf.modification import Modification
from bcf.markup import (Comment, Header, ViewpointReference)
from bcf.markup import (Comment, Header, ViewpointReference, Markup)
from bcf.topic import (Topic, BimSnippet, DocumentReference)
from bcf.viewpoint import (Viewpoint, Component, Components, ViewSetupHints,
ComponentColour, PerspectiveCamera, OrthogonalCamera, BitmapFormat,
Expand Down Expand Up @@ -71,8 +71,6 @@ def schemaValidate(schemaPath: str, xmlFile: str):


def extractFileToTmp(zipFilePath: str):
<<<<<<< HEAD
=======

"""
Extracts the zipFile to the temporary directory of the system.
Expand All @@ -92,8 +90,8 @@ def extractFileToTmp(zipFilePath: str):
zipFile.extractall(extractionPath)
return extractionPath


def extractMemberToTmp(zipFile: ZipFile, memberName: str):
>>>>>>> reader.py: refactor buildProject, uses path instead of ZipFile

"""
Extracts the zipFile to the temporary directory of the system.
Expand Down Expand Up @@ -144,14 +142,10 @@ def extractMemberToTmp(zipFile: ZipFile, memberName: str):

def getVersion(extrBcfPath: str, versionSchemaPath: str):

<<<<<<< HEAD
"""
Tries to open `extrBcfPath`/bcf.version. If successful it parses it
into a python dictonary and returns the content of the attribute
`VersionId` of the element `Version`.
=======
def buildProject(projectFilePath: str, projectSchema: str):
>>>>>>> reader.py: refactor buildProject, uses path instead of ZipFile
If `bcf.version` was not found a ValueError is raised. If `bcf.version`
does not parse against versionSchema then `None` is returned.
Expand Down Expand Up @@ -181,7 +175,6 @@ def getFileListByExtension(topDir: str, extension: str):
Returns a list of files in the `topDir` directory that end with `extension`
"""

<<<<<<< HEAD
fileList = [ f for f in os.listdir(topDir)
if os.path.isfile(os.path.join(topDir, f)) ]
return list(filter(lambda f: f.endswith(extension), fileList))
Expand Down Expand Up @@ -245,8 +238,6 @@ def getOptionalFromDict(d: Dict, desiredValue: str, empty):

def buildProject(projectFilePath: str, projectSchema: str):

=======
>>>>>>> reader.py: refactor buildProject, uses path instead of ZipFile
if projectFilePath is None or projectSchema is None:
return None
if not os.path.exists(projectFilePath):
Expand Down Expand Up @@ -288,11 +279,9 @@ def buildComment(commentDict: Dict):

commentString = commentDict["Comment"]

viewpointRef = None
""" TODO: Refactor viewpoint situation.
if "Viewpoint" in commentDict:
viewpointUUID = UUID(commentDict["Viewpoint"])
"""
viewpointRef = getOptionalFromDict(commentDict, "Viewpoint", None)
if viewpointRef:
viewpointRef = ViewpointReference(id=UUID(viewpointRef["@Guid"]))

comment = Comment(creationData, commentString, viewpointRef, modifiedData)
return comment
Expand Down Expand Up @@ -341,6 +330,7 @@ def buildTopic(topicDict: Dict):
modifiedAuthor = getOptionalFromDict(topicDict, "ModifiedAuthor", None)
modifiedData = None
if not (modifiedDate is None or modifiedAuthor is None):
modifiedDate = dateutil.parser.parse(modifiedDate)
modifiedData = Modification(modifiedAuthor, modifiedDate)

index = getOptionalFromDict(topicDict, "Index", 0)
Expand All @@ -349,19 +339,19 @@ def buildTopic(topicDict: Dict):
dueDate = dateutil.parser.parse(dueDate)

assignee = getOptionalFromDict(topicDict, "AssignedTo", "")
stage = getOptionalFromDict(topicDict, "State", "")
stage = getOptionalFromDict(topicDict, "Stage", "")
description = getOptionalFromDict(topicDict, "Description", "")

bimSnippet = None
if "BimSnippet" in topicDict:
bimSnippet = buildBimSnippet(topicDict["BimSnippet"])

labelList = getOptionalFromDict(topicDict, "Labels", list())
labelList = getOptionalFromDict(topicDict, "Labels", [])

docRefList = getOptionalFromDict(topicDict, "DocumentReference", list())
docRefList = getOptionalFromDict(topicDict, "DocumentReference", [])
docRefs = [ buildDocRef(docRef) for docRef in docRefList ]

relatedList = getOptionalFromDict(topicDict, "RelatedTopic", list())
relatedList = getOptionalFromDict(topicDict, "RelatedTopic", [])
relatedTopics = [ UUID(relTopic["@Guid"]) for relTopic in relatedList ]

topic = Topic(id, title, creationData,
Expand Down Expand Up @@ -422,12 +412,11 @@ def buildMarkup(markupFilePath: str, markupSchemaPath: str):
markupSchema = XMLSchema(markupSchemaPath)
markupDict = markupSchema.to_dict(markupFilePath)

pprint.pprint(markupDict)
if "Comment" in markupDict:
comments = list()
for commentDict in markupDict["Comment"]:
comment = buildComment(commentDict)
comments.append(comment)
if DEBUG:
pprint.pprint(markupDict)

commentList = getOptionalFromDict(markupDict, "Comment", list())
comments = [ buildComment(comment) for comment in commentList ]

topicDict = markupDict["Topic"]
topic = buildTopic(topicDict)
Expand All @@ -443,6 +432,19 @@ def buildMarkup(markupFilePath: str, markupSchemaPath: str):
for vpDict in viewpointList ]

markup = Markup(header, topic, comments, viewpoints)

# Add the right viewpoint references to each comment
for comment in comments:
if DEBUG:
print("comment with viewpoint {}".format(comment.viewpoint))
if comment.viewpoint:
cViewpointRefGuid = comment.viewpoint.id
viewpointRef = markup.getViewpointRefByGuid(cViewpointRefGuid)
if DEBUG:
print("Comment references to {}, found"\
" {}".format(cViewpointRefGuid, viewpointRef))
comment.viewpoint = viewpointRef

return markup


Expand Down
90 changes: 82 additions & 8 deletions src/bcf/topic.py
Expand Up @@ -175,6 +175,14 @@ def __eq__(self, other):
self.description == other.description)


def __str__(self):
str_ret = ("DocumentReference(id={}, external={}, reference={},"\
" description={})").format(self.id, self.external, self.reference,
self.description)

return str_ret


class BimSnippet:
def __init__(self,
type: SnippetType = None,
Expand Down Expand Up @@ -210,18 +218,18 @@ def __init__(self,
id: UUID,
title: str,
creation: Modification,
type: str = None,
status: str = None,
type: str = "",
status: str = "",
refs: List[DocumentReference] = list(),
priority: str = None,
priority: str = "",
index: int = 0,
labels: List[str] = list(),
lastModification: Modification = None,
dueDate: date = None,
assignee: str = "",
description: str = "",
stage: str = None,
relatedTopics: List[UUID] = None):
stage: str = "",
relatedTopics: List[UUID] = []):

""" Initialisation function of Topic """

Expand All @@ -242,25 +250,91 @@ def __init__(self,
self.relatedTopics = relatedTopics


def __checkNone(self, this, that):

equal = False
if this and that:
equal = this == that
elif (this is None and that is None):
equal = True
return equal


def __printEquality(self, equal, name):

if not equal:
print("{} is not equal".format(name))


def __eq__(self, other):

"""
Returns true if every variable member of both classes are the same
"""

self.__printEquality(self.id == other.id, "id")
self.__printEquality(self.title == other.title, "title")
self.__printEquality(self.__checkNone(self.creation, other.creation),
"creation")
self.__printEquality(self.type == other.type, "type")
self.__printEquality(self.status == other.status, "status")
self.__printEquality(self.refs == other.refs, "refs")
self.__printEquality(self.priority == other.priority, "priority")
self.__printEquality(self.index == other.index, "index")
self.__printEquality(self.labels == other.labels, "labels")
self.__printEquality(self.assignee == other.assignee, "assignee")
self.__printEquality(self.description == other.description, "description")
self.__printEquality(self.stage == other.stage, "stage")
self.__printEquality(self.relatedTopics == other.relatedTopics,
"relatedTopics")
self.__printEquality(self.__checkNone(self.lastModification,
other.lastModification), "lastModification")
self.__printEquality(self.__checkNone(self.dueDate,
other.dueDate), "dueDate")

return (self.id == other.id and
self.title == other.title and
self.creation == other.creation and
self.__checkNone(self.creation, other.creation) and
self.type == other.type and
self.status == other.status and
self.refs == other.refs and
self.priority == other.priority and
self.index == other.index and
self.labels == other.labels and
self.lastModification == other.lastModification and
self.dueDate == other.dueDate and
self.__checkNone(self.lastModification, other.lastModification) and
self.__checkNone(self.dueDate, other.dueDate) and
self.assignee == other.assignee and
self.description == other.description and
self.stage == other.stage and
self.relatedTopics == other.relatedTopics)

def __str__(self):
import pprint
doc_ref_str = "None"
if self.refs:
doc_ref_str = "["
for doc_ref in self.refs:
doc_ref_str += str(doc_ref)
doc_ref_str += "]"

str_ret = """---- Topic ----
ID: {},
Title: {},
Creation: {}
Type: {},
Status: {},
Priority: {},
Index: {},
Modification: {},
DueDate: {},
AssignedTo: {},
Description: {},
Stage: {},
RelatedTopics: {},
Labels: {},
DocumentReferences: {}""".format(self.id, self.title, str(self.creation),
self.type, self.status, self.priority, self.index,
str(self.lastModification), self.dueDate,
self.assignee, self.description, self.stage, self.relatedTopics,
self.labels, doc_ref_str)
return str_ret
4 changes: 4 additions & 0 deletions src/bcf/uri.py
Expand Up @@ -14,3 +14,7 @@ def __eq__(self, other):
"""

return self.uri == other.uri

def __str__(self):
ret_str = "Uri({})".format(self.uri)
return ret_str

0 comments on commit 7a31462

Please sign in to comment.