Ejemplo n.º 1
0
    def _buildCar(self) -> ClassDefinition:

        car: ClassDefinition = ClassDefinition(name='Car',
                                               position=Position(107, 30),
                                               size=Size(width=266,
                                                         height=100))

        initMethodDef: MethodDefinition = self._buildInitMethod()
        descMethodDef: MethodDefinition = MethodDefinition(
            name='getDescriptiveName', visibility=DefinitionType.Public)
        odometerMethodDef: MethodDefinition = MethodDefinition(
            name='readOdometer', visibility=DefinitionType.Public)
        updateOdoMethodDef: MethodDefinition = MethodDefinition(
            name='updateOdometer', visibility=DefinitionType.Public)
        incrementMethodDef: MethodDefinition = MethodDefinition(
            name='incrementOdometer', visibility=DefinitionType.Protected)

        mileageParam: ParameterDefinition = ParameterDefinition(
            name='mileage', defaultValue='1')
        updateOdoMethodDef.parameters = [mileageParam]

        milesParam: ParameterDefinition = ParameterDefinition(
            name='miles', parameterType='int')
        incrementMethodDef.parameters = [milesParam]

        car.methods = [
            initMethodDef, descMethodDef, odometerMethodDef,
            updateOdoMethodDef, incrementMethodDef
        ]

        return car
Ejemplo n.º 2
0
    def _buildCat(self) -> ClassDefinition:

        cat: ClassDefinition = ClassDefinition(name='gato',
                                               position=Position(536, 19),
                                               size=Size(height=74, width=113))

        initMethod: MethodDefinition = MethodDefinition('__init')
        sitMethod: MethodDefinition = MethodDefinition('sit')
        rollOverMethod: MethodDefinition = MethodDefinition('rollOver')

        cat.methods = [initMethod, sitMethod, rollOverMethod]

        return cat
Ejemplo n.º 3
0
    def testBasicFields(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-BasicFields'
        fileName: str = f'{baseName}.{ImageFormat.PNG.value}'

        diagram: ImageDiagram = ImageDiagram(fileName=fileName)
        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.write()

        self._assertIdenticalFiles(
            baseName=baseName,
            generatedFileName=fileName,
            failMessage='Basic Fields image file should be identical')
Ejemplo n.º 4
0
    def testBasicMethod(self):

        baseName: str = f'{TestConstants.TEST_FILE_NAME}-BasicMethod'
        fileName: str = f'{baseName}.{ImageFormat.PNG.value}'

        diagram: ImageDiagram = ImageDiagram(fileName=f'{fileName}')

        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=DefinitionType.Public)

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

        diagram.drawClass(car)
        diagram.write()

        self._assertIdenticalFiles(
            baseName=baseName,
            generatedFileName=fileName,
            failMessage='Basic Method image file should be identical')
Ejemplo n.º 5
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')
Ejemplo n.º 6
0
    def _buildElectricCar(self) -> ClassDefinition:

        electricCar: ClassDefinition = ClassDefinition(name='ElectricCar',
                                                       position=Position(
                                                           52, 224),
                                                       size=Size(width=173,
                                                                 height=64))

        initMethod: MethodDefinition = MethodDefinition(name='__init__')
        descMethod: MethodDefinition = MethodDefinition(name='describeBattery')

        makeParameter: ParameterDefinition = ParameterDefinition(name='make')
        modelParameter: ParameterDefinition = ParameterDefinition(name='model')
        yearParameter: ParameterDefinition = ParameterDefinition(name='year')

        initMethod.parameters = [makeParameter, modelParameter, yearParameter]
        electricCar.methods = [initMethod, descMethod]
        return electricCar
Ejemplo n.º 7
0
    def _buildNameTestCase(self) -> ClassDefinition:

        namesTest: ClassDefinition = ClassDefinition(name='NamesTestCase',
                                                     position=Position(
                                                         409, 362),
                                                     size=Size(height=65,
                                                               width=184))

        testFirst: MethodDefinition = MethodDefinition(name='testFirstLasName')
        formattedName: MethodDefinition = MethodDefinition(
            name='getFormattedName')

        firstParam: ParameterDefinition = ParameterDefinition(name='first')
        lastParam: ParameterDefinition = ParameterDefinition(name='last')

        formattedName.parameters = [firstParam, lastParam]
        namesTest.methods = [testFirst, formattedName]

        return namesTest
Ejemplo n.º 8
0
    def _generateMethodParameters(
            self, xmlMethod: Element,
            methodDef: MethodDefinition) -> MethodDefinition:

        parameters: Parameters = []
        for xmlParam in xmlMethod.getElementsByTagName(ELEMENT_MODEL_PARAM):
            paramDef: ParameterDefinition = self._getParam(xmlParam=xmlParam)
            parameters.append(paramDef)

        methodDef.parameters = parameters

        return methodDef
Ejemplo n.º 9
0
    def __addParameters(self, methodDefinition: MethodDefinition, pyutMethod: PyutMethod) -> MethodDefinition:

        parameters: Parameters = []
        for parameter in pyutMethod.parameters:

            paramDef: ParameterDefinition = ParameterDefinition(name=parameter.name)
            paramDef.parameterType = parameter.type.value
            paramDef.defaultValue  = parameter.defaultValue

            parameters.append(paramDef)

        methodDefinition.parameters = parameters
        self.logger.info(f'{methodDefinition.name=}  {parameters=}')
        return methodDefinition
Ejemplo n.º 10
0
    def _buildInitMethod(self) -> MethodDefinition:

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

        initParam: ParameterDefinition = ParameterDefinition(
            name='make', parameterType='str', defaultValue='')
        modelParam: ParameterDefinition = ParameterDefinition(
            name='model', parameterType='str', defaultValue='')
        yearParam: ParameterDefinition = ParameterDefinition(
            name='year', parameterType='int', defaultValue='1957')

        initMethodDef.parameters = [initParam, modelParam, yearParam]

        return initMethodDef
Ejemplo n.º 11
0
    def _addMethods(self, classDefinition: ClassDefinition, pyutClass: PyutClass) -> ClassDefinition:

        methods: Methods = []
        for pyutMethod in pyutClass.methods:

            pyutMethod: PyutMethod = cast(PyutMethod, pyutMethod)

            methodDef: MethodDefinition = MethodDefinition(name=pyutMethod.name)
            methodDef.visibility = self.__toDefinitionType(pyutMethod.visibility)
            methodDef.returnType = pyutMethod.returnType.value

            self.__addParameters(methodDefinition=methodDef, pyutMethod=pyutMethod)
            methods.append(methodDef)

        classDefinition.methods = methods
        return classDefinition
Ejemplo n.º 12
0
    def generateMethods(self, xmlClass: Element) -> Methods:

        methods: Methods = []

        for xmlMethod in xmlClass.getElementsByTagName(ELEMENT_MODEL_METHOD):
            methodName: str = xmlMethod.getAttribute(ATTR_NAME)
            self.logger.debug(f'{methodName=}')

            method: MethodDefinition = MethodDefinition(name=methodName)

            method = self._generateMethodParameters(xmlMethod=xmlMethod,
                                                    methodDef=method)

            methods.append(method)

        return methods
Ejemplo n.º 13
0
    def _buildOpie(self) -> ClassDefinition:

        opie: ClassDefinition = ClassDefinition(name='Opie',
                                                position=Position(495, 208),
                                                size=Size(width=216,
                                                          height=87))

        publicMethod: MethodDefinition = MethodDefinition(
            name='publicMethod',
            visibility=DefinitionType.Public,
            returnType='bool')
        paramDef: ParameterDefinition = ParameterDefinition(
            name='param', parameterType='float', defaultValue='23.0')

        publicMethod.parameters = [paramDef]

        opie.methods = [publicMethod]

        return opie
Ejemplo n.º 14
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')
Ejemplo n.º 15
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')