Пример #1
0
    def testFillPage(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-FillPage'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram: PdfDiagram = PdfDiagram(fileName=f'{fileName}', dpi=TestConstants.TEST_DPI)

        widthInterval:  int = TestPdfDiagram.CELL_WIDTH // 10
        heightInterval: int = TestPdfDiagram.CELL_HEIGHT // 10

        for x in range(0, TestPdfDiagram.TEST_LAST_X_POSITION):
            scrX: int = (x * TestPdfDiagram.CELL_WIDTH) + (widthInterval * x)

            for y in range(0, TestPdfDiagram.TEST_LAST_Y_POSITION):

                scrY: int = (y * TestPdfDiagram.CELL_HEIGHT) + (y * heightInterval)
                classDef: ClassDefinition = ClassDefinition(name=f'{TestPdfDiagram.BASE_TEST_CLASS_NAME}{x}{y}',
                                                            position=Position(scrX, scrY),
                                                            size=Size(width=TestPdfDiagram.CELL_WIDTH, height=TestPdfDiagram.CELL_HEIGHT))
                diagram.drawClass(classDef)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='FillPage should be identical')
Пример #2
0
    def __init__(self, imageOptions: ImageOptions, dpi: int = 0, pyutVersion: str = '', pluginVersion: str = ''):
        """

        Args:
            imageOptions: Lots of information on how to draw the diagram

            dpi:  Dots per inch;  Only used in PDF generation;  Image generation is in pixels

            pyutVersion:  Information for header

            pluginVersion:  Information for header
        """

        self.logger:              Logger             = getLogger(__name__)
        self._classDefinitions:   ClassDefinitions   = []
        self._umlLineDefinitions: UmlLineDefinitions = []

        today: str = strftime("%d %b %Y %H:%M:%S", localtime())
        headerText: str = f'Pyut Version {pyutVersion} Plugin Version {pluginVersion} - {today}'

        fqFileName:  str         = imageOptions.outputFileName
        imageFormat: ImageFormat = imageOptions.imageFormat
        if imageFormat == ImageFormat.PDF:
            self._diagram: PdfDiagram = PdfDiagram(fileName=fqFileName, dpi=dpi, headerText=headerText)
        else:
            self._diagram: ImageDiagram = ImageDiagram(fileName=fqFileName,
                                                       headerText=headerText   # TODO use image size from new method signature
                                                       )
Пример #3
0
    def testBasicMethod(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-BasicMethod'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram: PdfDiagram = PdfDiagram(fileName=f'{fileName}', dpi=TestConstants.TEST_DPI)

        position: Position = Position(107, 30)
        size:     Size     = Size(width=266, height=100)

        car: ClassDefinition = ClassDefinition(name='Car', position=position, size=size)

        car.displayMethodParameters = DisplayMethodParameters.DISPLAY
        initMethodDef: MethodDefinition = MethodDefinition(name='__init__', visibility=DefinitionType.Public)

        initParam: ParameterDefinition = ParameterDefinition(name='make', parameterType='str', defaultValue='')
        initMethodDef.parameters = [initParam]
        car.methods = [initMethodDef]

        diagram.drawClass(car)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='Basic Method should be identical')
Пример #4
0
    def testSophisticatedLayout(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-SophisticatedLayout'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram: PdfDiagram = PdfDiagram(fileName=f'{fileName}', dpi=TestConstants.TEST_DPI)

        classDefinitions: ClassDefinitions = [
            self._buildCar(),
            self._buildCat(),
            self._buildOpie(),
            self._buildNameTestCase(),
            self._buildElectricCar()
        ]
        for classDefinition in classDefinitions:
            classDefinition = cast(ClassDefinition, classDefinition)
            diagram.drawClass(classDefinition=classDefinition)

        lineDefinitions: UmlLineDefinitions = self._buildSophisticatedLineDefinitions()
        for lineDefinition in lineDefinitions:
            diagram.drawUmlLine(lineDefinition=lineDefinition)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()
        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='SophisticatedLayout should be identical')
Пример #5
0
    def testBuildMethods(self):

        diagram: PdfDiagram = PdfDiagram(fileName=cast(str, None), dpi=cast(int, None))

        car: ClassDefinition = self._buildCar()

        reprs: PdfDiagram.MethodsRepr = diagram._buildMethods(car.methods, DisplayMethodParameters.DISPLAY)

        self.assertEqual(5, len(reprs), 'Generated incorrect number of method representations')
Пример #6
0
    def testBuildMethod(self):

        diagram: PdfDiagram = PdfDiagram(fileName=cast(str, None), dpi=cast(int, None))

        initMethodDef: MethodDefinition = self._buildInitMethod()

        actualRepr:    str = diagram._buildMethod(initMethodDef, DisplayMethodParameters.DISPLAY)
        expectedRepr:  str = '+ __init__(make: str, model: str, year: int=1957)'

        self.assertEqual(expectedRepr, actualRepr, 'Method building is incorrect')
Пример #7
0
    def testBasicMethods(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-BasicMethods'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram: PdfDiagram = PdfDiagram(fileName=f'{fileName}', dpi=TestConstants.TEST_DPI)

        classDef: ClassDefinition = self._buildCar()

        diagram.drawClass(classDef)
        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='Basic Methods should be identical')
Пример #8
0
    def testBasic(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-Basic'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram:  PdfDiagram      = PdfDiagram(fileName=fileName, dpi=TestConstants.TEST_DPI)
        classDef: ClassDefinition = ClassDefinition(name=TestDiagramParent.BASE_TEST_CLASS_NAME,
                                                    size=Size(width=TestPdfDiagram.CELL_WIDTH, height=TestPdfDiagram.CELL_HEIGHT))

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.drawClass(classDef)
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='Basic should be identical')
Пример #9
0
    def testCaptureShowMethodsFalse(self):

        toClassDefinition: ToClassDefinition = self._buildNoMethodDisplayClassFromXml()

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-CaptureShowMethodsFalse'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram:  PdfDiagram = PdfDiagram(fileName=fileName, dpi=TestConstants.TEST_DPI)
        classDefinitions: ClassDefinitions = toClassDefinition.classDefinitions
        for bigClass in classDefinitions:
            diagram.drawClass(classDefinition=bigClass)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='CaptureShowMethodsFalse should be identical')
Пример #10
0
    def testBigClass(self):

        toClassDefinition: ToClassDefinition = self._buildBigClassFromXml()

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-BigClass'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram:  PdfDiagram = PdfDiagram(fileName=fileName, dpi=TestConstants.TEST_DPI)

        classDefinitions: ClassDefinitions = toClassDefinition.classDefinitions
        for bigClass in classDefinitions:
            diagram.drawClass(classDefinition=bigClass)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='Bends from XML Input should be identical')
Пример #11
0
    def testSophisticatedHeader(self):

        today = self.unitTestTimeStamp.strftime("%d %b %Y %H:%M:%S")

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-SophisticatedHeader'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram: PdfDiagram = PdfDiagram(fileName=fileName,
                                         dpi=TestConstants.TEST_DPI,
                                         headerText=f'{TestDiagramParent.UNIT_TEST_SOPHISTICATED_HEADER} - {today}')
        classDef: ClassDefinition = self._buildCar()

        diagram.drawClass(classDef)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='SophisticatedHeader should be identical')
Пример #12
0
    def testDiagonalCompositionLines(self):
        diagram: PdfDiagram = PdfDiagram(
            fileName=
            f'{TestConstants.TEST_FILE_NAME}-DiagonalCompositionLines{TestConstants.TEST_SUFFIX}',
            dpi=TestConstants.TEST_DPI)
        self.__drawEllipseForDiagonalLines(diagram)

        lineDrawer: PdfLine = PdfLine(pdf=diagram._pdf,
                                      diagramPadding=diagram._diagramPadding,
                                      dpi=diagram._dpi)

        northEast, northWest, southEast, southWest = self.__createDiagonalLines(
            LineType.Composition)
        definitions: UmlLineDefinitions = [
            northEast, northWest, southEast, southWest
        ]
        for definition in definitions:
            lineDrawer.draw(definition)
        diagram.write()
Пример #13
0
    def testOrthogonalAssociationLines(self):
        diagram: PdfDiagram = PdfDiagram(
            fileName=
            f'{TestConstants.TEST_FILE_NAME}-OrthogonalAssociationLines{TestConstants.TEST_SUFFIX}',
            dpi=TestConstants.TEST_DPI)

        self.__drawHorizontalBoundaries(diagram)
        self.__drawVerticalBoundaries(diagram)

        lineDrawer: PdfLine = PdfLine(pdf=diagram._pdf,
                                      diagramPadding=diagram._diagramPadding,
                                      dpi=diagram._dpi)

        north, south, east, west = self.__createOrthogonalLines(
            LineType.Association)
        lineDefinitions: UmlLineDefinitions = [north, south, east, west]
        for lineDefinition in lineDefinitions:
            lineDrawer.draw(lineDefinition)

        diagram.write()
Пример #14
0
    def __drawEllipseForDiagonalLines(self, diagram: PdfDiagram):

        eDef: EllipseDefinition = EllipseDefinition()
        pos: Position = Position(TestPdfLine.ELLIPSE_X, TestPdfLine.ELLIPSE_Y)
        size: Size = Size(width=TestPdfLine.ELLIPSE_WIDTH,
                          height=TestPdfLine.ELLIPSE_HEIGHT)

        eDef.position = pos
        eDef.size = size
        diagram.drawEllipse(eDef)
        diagram.drawRectangle(eDef)

        center: Position = self.__computeEllipseCenter(pos)

        diagram.drawText(center, text=f'({int(center.x)},{int(center.y)})')
Пример #15
0
    def testBasicFields(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-BasicFields'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram:  PdfDiagram = PdfDiagram(fileName=fileName, dpi=TestConstants.TEST_DPI)

        fieldsTestClass: ClassDefinition = ClassDefinition(name='FieldsTestClass', position=Position(226, 102), size=Size(height=156, width=230))

        fieldsTestClass.fields = self._buildFields()

        initMethodDef: MethodDefinition = MethodDefinition(name='__init__', visibility=DefinitionType.Public)

        fieldsTestClass.methods = [initMethodDef]

        diagram.drawClass(classDefinition=fieldsTestClass)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='Basic Fields should be identical')
Пример #16
0
    def testMinimalInheritance(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-MinimalInheritance'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram: PdfDiagram = PdfDiagram(fileName=f'{fileName}', dpi=75)

        cat:  ClassDefinition = ClassDefinition(name='Gato', position=Position(536, 19), size=Size(height=74, width=113))
        opie: ClassDefinition = ClassDefinition(name='Opie', position=Position(495, 208), size=Size(width=216, height=87))

        diagram.drawClass(classDefinition=cat)
        diagram.drawClass(classDefinition=opie)

        linePositions: LinePositions = [Position(600, 208), Position(600, 93)]
        opieToCat: UmlLineDefinition = UmlLineDefinition(lineType=LineType.Inheritance, linePositions=linePositions)

        diagram.drawUmlLine(lineDefinition=opieToCat)
        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='SophisticatedLayout should be identical')
Пример #17
0
    def testMethodReprRegression(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-MethodReprRegression'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram: PdfDiagram = PdfDiagram(fileName=fileName, dpi=TestConstants.TEST_DPI)

        position: Position = Position(107, 30)
        size:     Size     = Size(width=266, height=100)

        car: ClassDefinition = ClassDefinition(name='Car', position=position, size=size)

        initMethodDef: MethodDefinition = MethodDefinition(name='__init__', visibility=cast(DefinitionType, None))

        car.methods = [initMethodDef]

        diagram.drawClass(car)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='MethodReprRegression should be identical')
Пример #18
0
    def testBends(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-Bends'
        fileName: str  = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram:  PdfDiagram = PdfDiagram(fileName=fileName, dpi=TestConstants.TEST_DPI)

        top:   ClassDefinition = self._buildTopClass()
        left:  ClassDefinition = self._buildLeftClass()
        right: ClassDefinition = self._buildRightClass()

        bentClasses: List[ClassDefinition] = [top, left, right]
        for bentClass in bentClasses:
            diagram.drawClass(classDefinition=bentClass)

        bentLineDefinitions: UmlLineDefinitions = self._buildBendTest()

        for bentLine in bentLineDefinitions:
            diagram.drawUmlLine(bentLine)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName, failMessage='Bends should be identical')
Пример #19
0
    def testMethodParametersDisplay(self):

        toClassDefinition: ToClassDefinition = self._buildDisplayMethodParametersTest()

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-MethodParametersDisplay'
        fileName: str = f'{baseName}{TestConstants.TEST_SUFFIX}'

        diagram:  PdfDiagram = PdfDiagram(fileName=fileName, docDisplayMethodParameters=DisplayMethodParameters.UNSPECIFIED,
                                          dpi=TestConstants.TEST_DPI)

        classDefinitions: ClassDefinitions = toClassDefinition.classDefinitions
        for testClass in classDefinitions:
            diagram.drawClass(classDefinition=testClass)

        testLineDefinitions: UmlLineDefinitions = toClassDefinition.umlLineDefinitions

        for testLine in testLineDefinitions:
            diagram.drawUmlLine(testLine)

        diagram.docTimeStamp = self.unitTestTimeStamp
        diagram.write()

        self._assertIdenticalFiles(baseName=baseName, generatedFileName=fileName,
                                   failMessage='MethodParametersDisplay should be identical', removeTestFile=False)
Пример #20
0
    def testConstruction(self):

        diagram: PdfDiagram = PdfDiagram(fileName=TestConstants.TEST_FILE_NAME, dpi=TestConstants.TEST_DPI)
        self.assertIsNotNone(diagram, 'Construction failed')

        self.assertEqual(PdfDiagram.DEFAULT_FONT_SIZE, diagram.fontSize, 'Default font size changed')