Skip to content

Commit

Permalink
<Update>[OglClass]: <Process new Class attributes>
Browse files Browse the repository at this point in the history
[
* Put in non-functional place holder for V10
* Keep it DRY
* Remember updated version string]

[#73]
  • Loading branch information
Humberto Sanchez II committed Jan 15, 2024
1 parent 4ced4f8 commit 9970fec
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 21 deletions.
52 changes: 37 additions & 15 deletions src/untanglepyut/UnTanglePyut.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from pyutmodelv2.enumerations.PyutVisibility import PyutVisibility
from pyutmodelv2.enumerations.PyutDisplayParameters import PyutDisplayParameters
from pyutmodelv2.enumerations.PyutLinkType import PyutLinkType
from pyutmodelv2.enumerations.PyutDisplayMethods import PyutDisplayMethods

from untanglepyut import XmlConstants

Expand Down Expand Up @@ -79,6 +80,10 @@ def __init__(self, xmlVersion: XmlVersion):
self._attrId: str = XmlConstants.V10_ATTR_ID
self._attrStereoType: str = XmlConstants.V10_ATTR_STEREOTYPE
self._attrDisplayMethods: str = XmlConstants.V10_ATTR_DISPLAY_METHODS

self._attrDisplayConstructor = XmlConstants.V11_ATTR_DISPLAY_CONSTRUCTOR # V10 never had these
self._attrDisplayDunderMethods = XmlConstants.V11_ATTR_DISPLAY_DUNDER_METHODS # and will never have them

self._attrDisplayParameters: str = XmlConstants.V10_ATTR_DISPLAY_PARAMETERS
self._attrDisplayFields: str = XmlConstants.V10_ATTR_DISPLAY_FIELDS
self._attrDisplayStereoType: str = XmlConstants.V10_ATTR_DISPLAY_STEREOTYPE
Expand All @@ -100,12 +105,14 @@ def __init__(self, xmlVersion: XmlVersion):
self._elementMethod = XmlConstants.V11_ELEMENT_METHOD
self._elementField = XmlConstants.V11_ELEMENT_FIELD

self._attrId = XmlConstants.V11_ATTR_ID
self._attrStereoType = XmlConstants.V11_ATTR_STEREOTYPE
self._attrDisplayMethods = XmlConstants.V11_ATTR_DISPLAY_METHODS
self._attrDisplayParameters = XmlConstants.V11_ATTR_DISPLAY_PARAMETERS
self._attrDisplayFields = XmlConstants.V11_ATTR_DISPLAY_FIELDS
self._attrDisplayStereoType = XmlConstants.V11_ATTR_DISPLAY_STEREOTYPE
self._attrId = XmlConstants.V11_ATTR_ID
self._attrStereoType = XmlConstants.V11_ATTR_STEREOTYPE
self._attrDisplayMethods = XmlConstants.V11_ATTR_DISPLAY_METHODS
self._attrDisplayParameters = XmlConstants.V11_ATTR_DISPLAY_PARAMETERS
self._attrDisplayConstructor = XmlConstants.V11_ATTR_DISPLAY_CONSTRUCTOR
self._attrDisplayDunderMethods = XmlConstants.V11_ATTR_DISPLAY_DUNDER_METHODS
self._attrDisplayFields = XmlConstants.V11_ATTR_DISPLAY_FIELDS
self._attrDisplayStereoType = XmlConstants.V11_ATTR_DISPLAY_STEREOTYPE

self._attrCardinalitySource = XmlConstants.V11_ATTR_CARDINALITY_SOURCE
self._attrCardinalityDestination = XmlConstants.V11_ATTR_CARDINALITY_DESTINATION
Expand All @@ -132,17 +139,23 @@ def classToPyutClass(self, graphicClass: Element) -> PyutClass:

pyutClass = cast(PyutClass, self._addPyutObjectAttributes(pyutElement=classElement, pyutObject=pyutClass))

# displayParameters: PyutDisplayParameters = PyutDisplayParameters.toEnum(classElement[self._attrDisplayParameters])
displayStr: str = classElement[self._attrDisplayParameters]
displayParameters: PyutDisplayParameters = PyutDisplayParameters(displayStr)
displayStr: str = classElement[self._attrDisplayParameters]
displayParameters: PyutDisplayParameters = PyutDisplayParameters(displayStr)
displayConstructorStr: str = classElement[self._attrDisplayConstructor]
displayDunderMethodsStr: str = classElement[self._attrDisplayDunderMethods]

showStereotype: bool = bool(classElement[self._attrDisplayStereoType])
showFields: bool = bool(classElement[self._attrDisplayFields])
showMethods: bool = bool(classElement[self._attrDisplayMethods])
stereotypeStr: str = classElement[self._attrStereoType]
fileName: str = classElement[self._attrFileName]
displayConstructor: PyutDisplayMethods = self._securePyutDisplayMethods(displayStr=displayConstructorStr)
displayDunderMethods: PyutDisplayMethods = self._securePyutDisplayMethods(displayStr=displayDunderMethodsStr)

pyutClass.displayParameters = displayParameters
showStereotype: bool = bool(classElement[self._attrDisplayStereoType])
showFields: bool = bool(classElement[self._attrDisplayFields])
showMethods: bool = bool(classElement[self._attrDisplayMethods])
stereotypeStr: str = classElement[self._attrStereoType]
fileName: str = classElement[self._attrFileName]

pyutClass.displayParameters = displayParameters
pyutClass.displayConstructor = displayConstructor
pyutClass.displayDunderMethods = displayDunderMethods

pyutClass.displayStereoType = showStereotype
pyutClass.showFields = showFields
Expand Down Expand Up @@ -477,3 +490,12 @@ def _addPyutObjectAttributes(self, pyutElement: Element, pyutObject: PyutObject)
pyutObject.fileName = pyutElement[self._attrFileName]

return pyutObject

def _securePyutDisplayMethods(self, displayStr: str) -> PyutDisplayMethods:

if displayStr is not None:
pyutDisplayMethods: PyutDisplayMethods = PyutDisplayMethods(displayStr)
else:
pyutDisplayMethods = PyutDisplayMethods.UNSPECIFIED

return pyutDisplayMethods
12 changes: 7 additions & 5 deletions src/untanglepyut/XmlConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
V11_ELEMENT_TEXT: str = 'OglText'


V11_ATTR_STEREOTYPE: str = 'stereotype'
V11_ATTR_DISPLAY_STEREOTYPE: str = 'displayStereotype'
V11_ATTR_DISPLAY_METHODS: str = 'displayMethods'
V11_ATTR_DISPLAY_FIELDS: str = 'displayFields'
V11_ATTR_DISPLAY_PARAMETERS: str = 'displayParameters'
V11_ATTR_STEREOTYPE: str = 'stereotype'
V11_ATTR_DISPLAY_STEREOTYPE: str = 'displayStereotype'
V11_ATTR_DISPLAY_METHODS: str = 'displayMethods'
V11_ATTR_DISPLAY_FIELDS: str = 'displayFields'
V11_ATTR_DISPLAY_PARAMETERS: str = 'displayParameters'
V11_ATTR_DISPLAY_CONSTRUCTOR: str = 'displayConstructor'
V11_ATTR_DISPLAY_DUNDER_METHODS: str = 'displayDunderMethods'

V11_ATTR_ID: str = V10_ATTR_ID
V11_ATTR_NAME: str = 'name'
Expand Down
2 changes: 1 addition & 1 deletion src/untanglepyut/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = '2.0.5'
__version__: str = '2.1.0'
47 changes: 47 additions & 0 deletions tests/untanglepyut/TestUnTangleOglClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest import TestSuite
from unittest import main as unitTestMain

from pyutmodelv2.enumerations.PyutDisplayMethods import PyutDisplayMethods
from untangle import Element
from untangle import parse

Expand Down Expand Up @@ -70,6 +71,23 @@
</PyutDocument>
"""

V11_OGL_CLASS_NO_DISPLAY_ATTRIBUTES_DOCUMENT: str = """
<PyutDocument type="CLASS_DIAGRAM" title="SingleClassDiagram" scrollPositionX="0" scrollPositionY="0" pixelsPerUnitX="20" pixelsPerUnitY="20">
<OglClass width="429" height="145" x="300" y="175">
<PyutClass id="1" name="SingleClass" stereotype="noStereotype" displayMethods="True" displayParameters="DisplayParameters" displayFields="True" displayStereotype="True" description="">
</PyutClass>
</OglClass>
</PyutDocument>
"""

V11_OGL_CLASS_WITH_DISPLAY_ATTRIBUTES_DOCUMENT: str = """
<PyutDocument type="CLASS_DIAGRAM" title="SingleClassDiagram" scrollPositionX="0" scrollPositionY="0" pixelsPerUnitX="20" pixelsPerUnitY="20">
<OglClass width="429" height="145" x="300" y="175">
<PyutClass id="1" name="SingleClass" stereotype="noStereotype" displayMethods="True" displayParameters="DisplayParameters" displayFields="True" displayStereotype="True" displayConstructor="Display" displayDunderMethods="Do Not Display" description=""/>
</OglClass>
</PyutDocument>
"""

V10_OGL_CLASS_DOCUMENT: str = """
<PyutDocument type="CLASS_DIAGRAM" title="UnitTest" scrollPositionX="100" scrollPositionY="100" pixelsPerUnitX="1" pixelsPerUnitY="1">
<GraphicClass width="120" height="140" x="175" y="100">
Expand Down Expand Up @@ -137,6 +155,35 @@ def testV10OglClass(self):
self.assertEqual(175, x, '')
self.assertEqual(100, y, '')

def testV11OglClassNoDisplayAttributes(self):

root: Element = parse(V11_OGL_CLASS_NO_DISPLAY_ATTRIBUTES_DOCUMENT)
classDocument: Element = root.PyutDocument

unTangleOglClass: UnTangleOglClasses = UnTangleOglClasses(xmlVersion=XmlVersion.V11)
unTangledOglClasses: UntangledOglClasses = unTangleOglClass.unTangle(pyutDocument=classDocument)

oglClass: OglClass = unTangledOglClasses[0]
pyutClass: PyutClass = oglClass.pyutObject
"""
If they are not in the XML we should default them to UnSpecified
"""
self.assertEqual(PyutDisplayMethods.UNSPECIFIED, pyutClass.displayConstructor, 'Constructor display attribute is incorrect')
self.assertEqual(PyutDisplayMethods.UNSPECIFIED, pyutClass.displayDunderMethods, 'Dunder method display attribute is incorrect')

def testV11OglClassWithDisplayAttributes(self):
root: Element = parse(V11_OGL_CLASS_WITH_DISPLAY_ATTRIBUTES_DOCUMENT)
classDocument: Element = root.PyutDocument

unTangleOglClass: UnTangleOglClasses = UnTangleOglClasses(xmlVersion=XmlVersion.V11)
unTangledOglClasses: UntangledOglClasses = unTangleOglClass.unTangle(pyutDocument=classDocument)

oglClass: OglClass = unTangledOglClasses[0]
pyutClass: PyutClass = oglClass.pyutObject

self.assertEqual(PyutDisplayMethods.DISPLAY, pyutClass.displayConstructor, 'Constructor display attribute is incorrect')
self.assertEqual(PyutDisplayMethods.DO_NOT_DISPLAY, pyutClass.displayDunderMethods, 'Dunder method display attribute is incorrect')

def testV11OglClass(self):

root: Element = parse(V11_OGL_CLASS_DOCUMENT)
Expand Down

0 comments on commit 9970fec

Please sign in to comment.