Skip to content

Commit

Permalink
<Refactor>[Unit tests]: <Keep Unit Tests DRY>
Browse files Browse the repository at this point in the history
[]

[#24]
  • Loading branch information
Humberto Sanchez II committed Mar 31, 2023
1 parent accb33e commit 4317479
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 176 deletions.
11 changes: 6 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ jobs:
pip install setuptools
pip install six==1.16.0
pip install html-testRunner~=1.2.1
pip install attrdict3
pip install attrdict3~=2.0.2
pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04 wxPython
pip install hasiicommon~=0.0.7
pip install pyutmodel~=1.4.0
pip install ogl~=0.70.20
pip install untanglepyut==0.6.40
pip install hasiihelper~=0.1.0
pip install hasiicommon~=0.2.1
pip install pyutmodel~=1.4.2
pip install ogl~=0.70.22
pip install untanglepyut==0.6.41
- run:
name: run tests
command: |
Expand Down
2 changes: 1 addition & 1 deletion oglio/toXmlV10/BaseToDom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict
from typing import Union

from hasiicommon.Singleton import Singleton
from hasiihelper.Singleton import Singleton


class IDFactory(Singleton):
Expand Down
4 changes: 2 additions & 2 deletions oglio/toXmlV10/OglLinksToDom.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _oglLinkToDom(self, oglLink: OglLink, xmlDoc: Document):
root.appendChild(elt)

# save control points (not anchors!)
for x, y in oglLink.GetSegments()[1:-1]:
for x, y in oglLink.segments[1:-1]:
item = xmlDoc.createElement(XmlConstants.ELEMENT_MODEL_CONTROL_POINT)
item.setAttribute(XmlConstants.ATTR_X, str(x))
item.setAttribute(XmlConstants.ATTR_Y, str(y))
Expand All @@ -135,7 +135,7 @@ def __createAssocLabelElement(self, eltText: str, xmlDoc: Document, oglLabel: Og
e.g.
```html
`<LabelCenter x="1811.0" y="1137.5"/>`
`<LabelCenter x="1811" y="1137"/>`
```
Args:
Expand Down
19 changes: 11 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
wheel==0.38.4
setuptools==67.4.0
wheel==0.40.0
setuptools==67.6.1
twine==4.0.2
build==0.10.0
html-testRunner~=1.2.1

mypy==1.0.1
mypy==1.1.1
mypy-extensions==1.0.0
typing_extensions==4.5.0
types-setuptools==67.4.0.1
types-setuptools==67.6.0.6

attrdict3~=2.0.2

wxpython~=4.2.0

hasiicommon~=0.0.7
pyutmodel==1.4.0
ogl==0.70.20
untanglepyut==0.6.40
hasiihelper~=0.1.0
hasiicommon~=0.2.1
pyutmodel==1.4.2
ogl==0.70.22
untanglepyut==0.6.41
5 changes: 5 additions & 0 deletions scripts/query.slg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hasii2011/hasiihelper
hasii2011/hasiicommon
hasii2011/pyutmodel
hasii2011/ogl
hasii2011/untanglepyut
2 changes: 0 additions & 2 deletions scripts/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ function changeToProjectRoot {

changeToProjectRoot

echo "Travis Build directory: ${TRAVIS_BUILD_DIR}"

python3 -Wdefault -m tests.TestAll
status=$?

Expand Down
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="oglio",
version="0.5.80",
version="0.6.0",
author_email='Humberto.A.Sanchez.II@gmail.com',
maintainer='Humberto A. Sanchez II',
maintainer_email='humberto.a.sanchez.ii@gmail.com',
Expand All @@ -27,9 +27,10 @@
},
install_requires=[
'wxPython==4.2.0',
'hasiicommon~=0.0.7',
'pyutmodel~=1.4.0',
'ogl~=0.70.20',
'untanglepyut~=0.6.40',
'hasiihelper~=0.1.0',
'hasiicommon~=0.2.1',
'pyutmodel~=1.4.2',
'ogl~=0.70.22',
'untanglepyut~=0.6.41',
],
)
65 changes: 8 additions & 57 deletions tests/TestBase.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,34 @@

import json

import logging
import logging.config

from os import system as osSystem
from os import sep as osSep

from pkg_resources import resource_filename
from hasiihelper.UnitTestBase import UnitTestBase
from hasiicommon.ui.UnitTestBaseW import UnitTestBaseW

from miniogl.DiagramFrame import DiagramFrame
from pyutmodel.PyutObject import PyutObject

from wx import App
from wx import Frame
from wx import ID_ANY

from unittest import TestCase

from oglio.toXmlV10.BaseToDom import IDFactory

JSON_LOGGING_CONFIG_FILENAME: str = "testLoggingConfig.json"
TEST_DIRECTORY: str = 'tests'


class BogusApp(App):
def OnInit(self) -> bool:
return True


class TestBase(TestCase):
class TestBase(UnitTestBaseW):

RESOURCES_PACKAGE_NAME: str = 'tests.resources'
RESOURCES_TEST_CLASSES_PACKAGE_NAME: str = f'{RESOURCES_PACKAGE_NAME}.testclasses'
RESOURCES_TEST_DATA_PACKAGE_NAME: str = f'{RESOURCES_PACKAGE_NAME}.testdata'
RESOURCES_TEST_CLASSES_PACKAGE_NAME: str = f'{UnitTestBase.RESOURCES_PACKAGE_NAME}.testclasses'
RESOURCES_TEST_DATA_PACKAGE_NAME: str = f'{UnitTestBase.RESOURCES_PACKAGE_NAME}.testdata'

EXTERNAL_DIFF: str = '/usr/bin/diff -w '
EXTERNAL_CLEAN_UP_TMP: str = 'rm -rf'

def setUp(self):
"""
Test classes that need to instantiate a wxPython App should super().setUp()
"""
self._app: BogusApp = BogusApp()
baseFrame: Frame = Frame(None, ID_ANY, "", size=(10, 10))
# noinspection PyTypeChecker
umlFrame = DiagramFrame(baseFrame)
umlFrame.Show(True)
super().setUp()
PyutObject.nextId = 0 # reset to match sequence diagram
IDFactory.nextID = 1

def tearDown(self):
self._app.OnExit()

"""
A base unit test class to initialize some logging stuff we need
"""
@classmethod
def setUpLogging(cls):
""""""
loggingConfigFilename: str = cls.findLoggingConfig()

with open(loggingConfigFilename, 'r') as loggingConfigurationFile:
configurationDictionary = json.load(loggingConfigurationFile)

logging.config.dictConfig(configurationDictionary)
logging.logProcesses = False
logging.logThreads = False

@classmethod
def findLoggingConfig(cls) -> str:

fqFileName: str = resource_filename(TestBase.RESOURCES_PACKAGE_NAME, JSON_LOGGING_CONFIG_FILENAME)

return fqFileName
super().tearDown()

def _runDiff(self, fileName: str) -> int:

baseFileName: str = resource_filename(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, fileName)
baseFileName: str = TestBase.getFullyQualifiedResourceFileName(package=TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, fileName=fileName)
generatedFileName: str = self._constructGeneratedName(fileName=fileName)

status: int = osSystem(f'{TestBase.EXTERNAL_DIFF} {baseFileName} {generatedFileName}')
Expand Down
29 changes: 7 additions & 22 deletions tests/oglio/TestReader.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@

from typing import cast

from logging import Logger
from logging import getLogger

from unittest import TestSuite
from unittest import main as unitTestMain

from pkg_resources import resource_filename

from oglio import OglVersion
from oglio.Reader import Reader

Expand All @@ -30,34 +23,26 @@ class TestReader(TestBase):
TEST_DOCUMENT_NAME_1: OglDocumentTitle = OglDocumentTitle('Diagram-1')
TEST_DOCUMENT_NAME_2: OglDocumentTitle = OglDocumentTitle('Diagram-2')

clsLogger: Logger = cast(Logger, None)

@classmethod
def setUpClass(cls):
TestBase.setUpLogging()
TestReader.clsLogger = getLogger(__name__)

def setUp(self):
super().setUp()
self.logger: Logger = TestReader.clsLogger
self._reader: Reader = Reader()

def tearDown(self):
super().tearDown()

def testProjectInformation(self):
fqFileName: str = resource_filename(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestReader.TEST_FILE_NAME)

oglProject: OglProject = self._reader.readXmlFile(fqFileName=fqFileName)
fqFileName: str = TestBase.getFullyQualifiedResourceFileName(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestReader.TEST_FILE_NAME)
oglProject: OglProject = self._reader.readXmlFile(fqFileName=fqFileName)

self.assertEqual(fqFileName, oglProject.fileName, 'Where is my file name')
expectedVersion: str = OglVersion.version
actualVersion: str = oglProject.version
actualVersion: str = oglProject.version
self.assertEqual(expectedVersion, actualVersion, 'Mismatch in support Ogl Xml versions')

def testMultiDocumentRead(self):

fqFileName: str = resource_filename(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestReader.TEST_FILE_NAME)
fqFileName: str = TestBase.getFullyQualifiedResourceFileName(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestReader.TEST_FILE_NAME)

oglProject: OglProject = self._reader.readXmlFile(fqFileName=fqFileName)
oglDocuments: OglDocuments = oglProject.oglDocuments
Expand All @@ -66,7 +51,7 @@ def testMultiDocumentRead(self):

def testCorrectNumberOfOglObjectsDocumentOne(self):

fqFileName: str = resource_filename(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestReader.TEST_FILE_NAME)
fqFileName: str = TestBase.getFullyQualifiedResourceFileName(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestReader.TEST_FILE_NAME)

oglProject: OglProject = self._reader.readXmlFile(fqFileName=fqFileName)
oglDocuments: OglDocuments = oglProject.oglDocuments
Expand All @@ -79,7 +64,7 @@ def testCorrectNumberOfOglObjectsDocumentOne(self):

def testCorrectNumberOfOglObjectsDocumentTwo(self):

fqFileName: str = resource_filename(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestReader.TEST_FILE_NAME)
fqFileName: str = TestBase.getFullyQualifiedResourceFileName(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestReader.TEST_FILE_NAME)

oglProject: OglProject = self._reader.readXmlFile(fqFileName=fqFileName)

Expand All @@ -98,7 +83,7 @@ def testIncorrectPutSuffix(self):
self.assertRaises(UnsupportedFileTypeException, self._reader.readXmlFile, 'HokeyPutFileName.ozzee')

def testReadCompressedFile(self):
fqFileName: str = resource_filename(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, 'SimpleMultipleDocument.put')
fqFileName: str = TestBase.getFullyQualifiedResourceFileName(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, 'SimpleMultipleDocument.put')

oglProject: OglProject = self._reader.readFile(fqFileName=fqFileName)
oglDocuments: OglDocuments = oglProject.oglDocuments
Expand Down
18 changes: 4 additions & 14 deletions tests/oglio/TestWriter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

from typing import cast

from logging import Logger
from logging import getLogger

from unittest import TestSuite
from unittest import main as unitTestMain

from pkg_resources import resource_filename

from untanglepyut.UnTangler import Documents
from untanglepyut.UnTangler import UnTangler

Expand All @@ -26,6 +23,7 @@
from oglio.Types import createOglDocumentsFactory
from oglio.Writer import Writer
from oglio.toXmlV10.OglToDom import OglToDom

from tests.TestBase import TestBase


Expand All @@ -35,16 +33,7 @@ class TestWriter(TestBase):
"""
MULTI_DOCUMENT_FILENAME: str = 'SimpleMultipleDocument.xml'

clsLogger: Logger = cast(Logger, None)

@classmethod
def setUpClass(cls):
TestBase.setUpLogging()
TestWriter.clsLogger = getLogger(__name__)

def setUp(self):
self.logger: Logger = TestWriter.clsLogger

super().setUp()

def tearDown(self):
Expand Down Expand Up @@ -76,7 +65,8 @@ def _getTestOglProject(self) -> OglProject:
Returns: An OglProject
"""
fqFileName: str = resource_filename(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestWriter.MULTI_DOCUMENT_FILENAME)
fqFileName: str = TestBase.getFullyQualifiedResourceFileName(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestWriter.MULTI_DOCUMENT_FILENAME)

untangler: UnTangler = UnTangler()

untangler.untangleFile(fqFileName=fqFileName)
Expand Down
16 changes: 2 additions & 14 deletions tests/oglio/toXmlV10/TestNotesDiagram.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@

from typing import cast

from logging import Logger
from logging import getLogger

from unittest import TestSuite
from unittest import main as unitTestMain

from pkg_resources import resource_filename

from untanglepyut.UnTangler import Document
from untanglepyut.UnTangler import DocumentTitle
from untanglepyut.UnTangler import UnTangler
Expand All @@ -30,16 +25,8 @@ class TestNotesDiagram(TestBase):
"""
"""
NOTES_DIAGRAM_FILENAME: str = 'ManyNotes.xml'
clsLogger: Logger = cast(Logger, None)

@classmethod
def setUpClass(cls):
TestBase.setUpLogging()
TestNotesDiagram.clsLogger = getLogger(__name__)

def setUp(self):
self.logger: Logger = TestNotesDiagram.clsLogger

super().setUp()

def tearDown(self):
Expand All @@ -51,7 +38,8 @@ def testNotesSerialization(self):
#
self._cleanupGenerated(TestNotesDiagram.NOTES_DIAGRAM_FILENAME)

fqFileName: str = resource_filename(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestNotesDiagram.NOTES_DIAGRAM_FILENAME)
fqFileName: str = TestBase.getFullyQualifiedResourceFileName(TestBase.RESOURCES_TEST_DATA_PACKAGE_NAME, TestNotesDiagram.NOTES_DIAGRAM_FILENAME)

untangler: UnTangler = UnTangler()

untangler.untangleFile(fqFileName=fqFileName)
Expand Down
Loading

0 comments on commit 4317479

Please sign in to comment.