Ejemplo n.º 1
0
    def test_convert_simple(self):
        simple_class = ClassDiagramPart("Kitchen",
                                        methods=[
                                            "arrange_kitchen()",
                                            "place_floor_cabinet()",
                                            "place_wall_cabinet()"
                                        ],
                                        fields=["field1"])

        expected = """<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.0" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1">
	<xmi:Documentation exporter="Prexel" exporterVersion="1.0"/>
	<uml:Model name="RootModel" xmi:id="" xmi:type="uml:Model">
		<packagedElement isAbstract="false" isActive="false" isFinalSpecialization="false" isLeaf="false" name="Kitchen" visibility="public" xmi:id="" xmi:type="uml:Class">
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="field1" visibility="public" xmi:id="" xmi:type="uml:Property"/>
			<ownedOperation concurrency="sequential" isAbstract="false" isLeaf="false" isQuery="false" isStatic="false" name="arrange_kitchen" visibility="public" xmi:id="" xmi:type="uml:Operation"/>
			<ownedOperation concurrency="sequential" isAbstract="false" isLeaf="false" isQuery="false" isStatic="false" name="place_floor_cabinet" visibility="public" xmi:id="" xmi:type="uml:Operation"/>
			<ownedOperation concurrency="sequential" isAbstract="false" isLeaf="false" isQuery="false" isStatic="false" name="place_wall_cabinet" visibility="public" xmi:id="" xmi:type="uml:Operation"/>
		</packagedElement>
	</uml:Model>
</xmi:XMI>
"""

        diagram = Diagram(main=simple_class)
        xmi_encoder = XMIEncoder()
        actual = xmi_encoder.generate(diagram, display_id=False)
        self.assertEqual(expected, actual)
Ejemplo n.º 2
0
    def test_generate_with_inheritance(self):
        person = ClassDiagramPart("Person", fields=["name", "age"])

        inheritance = InheritanceDiagramPart()

        employee = ClassDiagramPart("Employee", fields=["job_title"])

        expected = """<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.0" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1">
	<xmi:Documentation exporter="Prexel" exporterVersion="1.0"/>
	<uml:Model name="RootModel" xmi:id="" xmi:type="uml:Model">
		<packagedElement isAbstract="false" isActive="false" isFinalSpecialization="false" isLeaf="false" name="Person" visibility="public" xmi:id="" xmi:type="uml:Class">
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="name" visibility="public" xmi:id="" xmi:type="uml:Property"/>
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="age" visibility="public" xmi:id="" xmi:type="uml:Property"/>
		</packagedElement>
		<packagedElement isAbstract="false" isActive="false" isFinalSpecialization="false" isLeaf="false" name="Employee" visibility="public" xmi:id="" xmi:type="uml:Class">
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="job_title" visibility="public" xmi:id="" xmi:type="uml:Property"/>
			<generalization general="" specific="" xmi:type="uml:Generalization"/>
		</packagedElement>
	</uml:Model>
</xmi:XMI>
"""

        diagram = Diagram(employee, parent=person, inheritance=inheritance)

        encoder = XMIEncoder()
        actual = encoder.generate(diagram, display_id=False)
        self.assertEqual(expected, actual)
Ejemplo n.º 3
0
    def test_generate_with_inheritance_alt(self):
        room = ClassDiagramPart("Room",
                                fields=["width", "height"],
                                methods=["set_color()"])

        inheritance = InheritanceDiagramPart()

        kitchen = ClassDiagramPart("Kitchen",
                                   methods=[
                                       "arrange_kitchen()",
                                       "place_floor_cabinet()",
                                       "place_wall_cabinet()"
                                   ])

        diagram = Diagram(kitchen, parent=room, inheritance=inheritance)

        expected = (" ___________ \n"
                    "|   Room    |\n"
                    "|-----------|\n"
                    "|width      |\n"
                    "|height     |\n"
                    "|set_color()|\n"
                    "|___________|\n"
                    "∆\n"
                    "|_____________________ \n"
                    "|       Kitchen       |\n"
                    "|---------------------|\n"
                    "|arrange_kitchen()    |\n"
                    "|place_floor_cabinet()|\n"
                    "|place_wall_cabinet() |\n"
                    "|_____________________|\n")

        encoder = PrettyPrintEncoder()
        actual = encoder.generate(diagram)
        self.assertEqual(expected, actual)
Ejemplo n.º 4
0
    def test_generate_with_aggregation(self):
        task_list_diagram = ClassDiagramPart("TaskList", methods=[
            "get_the_tasks()",
            "prioritize()"
        ], fields=["the_tasks"])

        task_list_aggregation = AggregationDiagramPart("the_tasks",
                                                       right_multiplicity="*")

        task_diagram = ClassDiagramPart("Task")

        diagram = Diagram(task_list_diagram,
                          aggregation=task_list_aggregation,
                          aggregated=task_diagram)

        task_list_class = ("class TaskList:\n"
                           "    def __init__(self, the_tasks):\n"
                           "        self.the_tasks = the_tasks\n"
                           "\n"
                           "    def get_the_tasks(self):\n"
                           "        pass\n"
                           "\n"
                           "    def prioritize(self):\n"
                           "        pass\n")

        task_class = ("class Task:\n"
                      "    pass\n")

        encoder = SourceCodeEncoder()
        actual = encoder.generate(diagram)

        self.assertEqual("tasklist", actual[1][0])
        self.assertEqual(task_list_class, actual[1][1])
        self.assertEqual("task", actual[0][0])
        self.assertEqual(task_class, actual[0][1])
Ejemplo n.º 5
0
    def test_generate_with_inheritance(self):
        person = ClassDiagramPart("Person", fields=[
            "name",
            "age"
        ])

        inheritance = InheritanceDiagramPart()

        employee = ClassDiagramPart("Employee", fields=[
            "job_title"
        ])

        diagram = Diagram(employee,
                          parent=person,
                          inheritance=inheritance)

        person_class = ("class Person:\n"
                        "    def __init__(self, name, age):\n"
                        "        self.name = name\n"
                        "        self.age = age\n")

        employee_class = ("class Employee(Person):\n"
                          "    def __init__(self, job_title):\n"
                          "        self.job_title = job_title\n")

        encoder = SourceCodeEncoder()
        actual = encoder.generate(diagram)  # Returns and array of classes

        self.assertEqual("person", actual[0][0])
        self.assertEqual(person_class, actual[0][1])
        self.assertEqual("employee", actual[1][0])
        self.assertEqual(employee_class, actual[1][1])
Ejemplo n.º 6
0
    def test_generate_empty_class(self):
        wing = ClassDiagramPart("Wing")

        diagram = Diagram(wing)

        expected = ("class Wing:\n"
                    "    pass\n")

        encoder = SourceCodeEncoder()
        actual = encoder.generate(diagram)

        self.assertEqual("wing", actual[0][0])
        self.assertEqual(expected, actual[0][1])
Ejemplo n.º 7
0
    def test_generate_with_aggregation_with_multiplicity(self):
        employer_diagram = ClassDiagramPart(
            "Employer", fields=["name", "age", "employees"])

        employees_aggregation = AggregationDiagramPart("employees",
                                                       left_multiplicity="1",
                                                       right_multiplicity="*")
        employee_diagram = ClassDiagramPart("Employee", fields=["position"])

        expected = """<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.0" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1">
	<xmi:Documentation exporter="Prexel" exporterVersion="1.0"/>
	<uml:Model name="RootModel" xmi:id="" xmi:type="uml:Model">
		<packagedElement isAbstract="false" isActive="false" isFinalSpecialization="false" isLeaf="false" name="Employer" visibility="public" xmi:id="" xmi:type="uml:Class">
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="name" visibility="public" xmi:id="" xmi:type="uml:Property"/>
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="age" visibility="public" xmi:id="" xmi:type="uml:Property"/>
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="employees" visibility="public" xmi:id="" xmi:type="uml:Property"/>
		</packagedElement>
		<packagedElement isAbstract="false" isActive="false" isFinalSpecialization="false" isLeaf="false" name="Employee" visibility="public" xmi:id="" xmi:type="uml:Class">
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="position" visibility="public" xmi:id="" xmi:type="uml:Property"/>
			<ownedMember isDerived="false" name="employees" visibility="public" xmi:id="" xmi:type="uml:Association">
				<ownedEnd aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" type="" visibility="public" xmi:type="uml:Property" xmi:id="">
					<lowerValue value="1" xmi:id="" xmi:type="uml:LiteralInteger"/>
					<upperValue value="1" xmi:id="" xmi:type="uml:LiteralInteger"/>
				</ownedEnd>
				<ownedEnd aggregation="shared" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" type="" visibility="public" xmi:type="uml:Property" xmi:id="">
					<lowerValue value="*" xmi:id="" xmi:type="uml:LiteralUnlimitedNatural"/>
					<upperValue value="*" xmi:id="" xmi:type="uml:LiteralUnlimitedNatural"/>
				</ownedEnd>
				<memberEnd xmi:idref=""/>
				<memberEnd xmi:idref=""/>
			</ownedMember>
		</packagedElement>
	</uml:Model>
</xmi:XMI>
"""

        diagram = Diagram(employer_diagram,
                          aggregation=employees_aggregation,
                          aggregated=employee_diagram)

        encoder = XMIEncoder()
        actual = encoder.generate(diagram, display_id=False)
        self.assertEqual(expected, actual)
Ejemplo n.º 8
0
    def test_generate_full(self):
        task_list_diagram = ClassDiagramPart(
            "TaskList", methods=["get_the_tasks()", "prioritize()"])

        task_list_aggregation = AggregationDiagramPart("the_tasks",
                                                       right_multiplicity="*")

        task_diagram = ClassDiagramPart("Task", fields=["name", "description"])

        parent = ClassDiagramPart("Manager",
                                  fields=["field1", "field2"],
                                  methods=["method1()", "method2()"])

        inheritance = InheritanceDiagramPart()

        diagram = Diagram(task_list_diagram,
                          parent=parent,
                          inheritance=inheritance,
                          aggregation=task_list_aggregation,
                          aggregated=task_diagram)

        expected = (" _________ \n"
                    "| Manager |\n"
                    "|---------|\n"
                    "|field1   |\n"
                    "|field2   |\n"
                    "|method1()|\n"
                    "|method2()|\n"
                    "|_________|\n"
                    "∆\n"
                    "|_______________                   ___________ \n"
                    "|   TaskList    |<>-the_tasks---*>|   Task    |\n"
                    "|---------------|                 |-----------|\n"
                    "|get_the_tasks()|                 |name       |\n"
                    "|prioritize()   |                 |description|\n"
                    "|_______________|                 |___________|\n")

        encoder = PrettyPrintEncoder()
        actual = encoder.generate(diagram)
        self.assertEqual(expected, actual)
Ejemplo n.º 9
0
    def test_generate_full(self):
        task_list_diagram = ClassDiagramPart("TaskList", methods=[
            "get_the_tasks()",
            "prioritize()"
        ])

        task_list_aggregation = AggregationDiagramPart("name",
                                                       right_multiplicity="*")

        task_diagram = ClassDiagramPart("Task", fields=[
            "name",
            "description"
        ], methods=[
            "complete()",
            "delete()"
        ])

        parent = ClassDiagramPart("Manager", fields=[
            "field1",
            "field2"
        ], methods=[
            "method1()",
            "method2()"
        ])

        inheritance = InheritanceDiagramPart()

        diagram = Diagram(task_list_diagram,
                          parent=parent,
                          inheritance=inheritance,
                          aggregation=task_list_aggregation,
                          aggregated=task_diagram)

        encoder = SourceCodeEncoder()
        actual = encoder.generate(diagram)

        # NOT TESTING ANYTHING, JUST CHECKING OUTPUT
        print(actual[0][1])
        print(actual[1][1])
Ejemplo n.º 10
0
    def test_generate_with_aggregation(self):
        task_list_diagram = ClassDiagramPart(
            "TaskList", methods=["get_the_tasks()", "prioritize()"])

        task_list_aggregation = AggregationDiagramPart("the_tasks",
                                                       right_multiplicity="*")

        task_diagram = ClassDiagramPart("Task")

        diagram = Diagram(task_list_diagram,
                          aggregation=task_list_aggregation,
                          aggregated=task_diagram)

        expected = (" _______________                   ____ \n"
                    "|   TaskList    |<>-the_tasks---*>|Task|\n"
                    "|---------------|                 |____|\n"
                    "|get_the_tasks()|                       \n"
                    "|prioritize()   |                       \n"
                    "|_______________|                       \n")

        encoder = PrettyPrintEncoder()
        actual = encoder.generate(diagram)
        self.assertEqual(expected, actual)
Ejemplo n.º 11
0
    def test_generate_with_aggregation(self):
        task_list_diagram = ClassDiagramPart(
            "TaskList",
            methods=["get_the_tasks()", "prioritize()"],
            fields=["the_tasks"])

        task_list_aggregation = AggregationDiagramPart("the_tasks")
        task_diagram = ClassDiagramPart("Task")

        expected = """<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.0" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1">
	<xmi:Documentation exporter="Prexel" exporterVersion="1.0"/>
	<uml:Model name="RootModel" xmi:id="" xmi:type="uml:Model">
		<packagedElement isAbstract="false" isActive="false" isFinalSpecialization="false" isLeaf="false" name="TaskList" visibility="public" xmi:id="" xmi:type="uml:Class">
			<ownedAttribute aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" name="the_tasks" visibility="public" xmi:id="" xmi:type="uml:Property"/>
			<ownedOperation concurrency="sequential" isAbstract="false" isLeaf="false" isQuery="false" isStatic="false" name="get_the_tasks" visibility="public" xmi:id="" xmi:type="uml:Operation"/>
			<ownedOperation concurrency="sequential" isAbstract="false" isLeaf="false" isQuery="false" isStatic="false" name="prioritize" visibility="public" xmi:id="" xmi:type="uml:Operation"/>
		</packagedElement>
		<packagedElement isAbstract="false" isActive="false" isFinalSpecialization="false" isLeaf="false" name="Task" visibility="public" xmi:id="" xmi:type="uml:Class">
			<ownedMember isDerived="false" name="the_tasks" visibility="public" xmi:id="" xmi:type="uml:Association">
				<ownedEnd aggregation="none" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" type="" visibility="public" xmi:type="uml:Property" xmi:id=""/>
				<ownedEnd aggregation="shared" isDerived="false" isID="false" isLeaf="false" isOrdered="false" isReadOnly="false" isStatic="false" isUnique="false" type="" visibility="public" xmi:type="uml:Property" xmi:id=""/>
				<memberEnd xmi:idref=""/>
				<memberEnd xmi:idref=""/>
			</ownedMember>
		</packagedElement>
	</uml:Model>
</xmi:XMI>
"""

        diagram = Diagram(task_list_diagram,
                          aggregation=task_list_aggregation,
                          aggregated=task_diagram)

        encoder = XMIEncoder()
        actual = encoder.generate(diagram, display_id=False)
        self.assertEqual(expected, actual)
Ejemplo n.º 12
0
 def __init__(self, lexer):
     self.lexer = lexer
     self.current_token = self.lexer.get_token()
     self.diagram = Diagram()