Skip to content

Commit

Permalink
Trying to force better debug output - (Task #5)
Browse files Browse the repository at this point in the history
- Unit test stopped creating resonable debug output

---
Task #5: Implement Import Functionality
  • Loading branch information
PhilMFischer committed Oct 24, 2019
1 parent c013fd7 commit dcd23c2
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 124 deletions.
1 change: 1 addition & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ encoding//test/json_io/parts/test_json_part_sphere.py=utf-8
encoding//test/json_io/products/test_json_product.py=utf-8
encoding//test/json_io/products/test_json_product_assembly.py=utf-8
encoding//test/json_io/products/test_json_product_child.py=utf-8
encoding//test/json_io/test_json_data.py=utf-8
encoding//test/json_io/test_json_importer.py=utf-8
encoding//test/json_io/test_json_spread_sheet.py=utf-8
encoding//test/test_setup.py=utf-8
Expand Down
14 changes: 3 additions & 11 deletions test/json_io/parts/test_json_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from freecad.active_document import ActiveDocument
import FreeCAD
import FreeCADGui
from test.json_io.test_json_data import TEST_JSON_PART_BOX

App = FreeCAD
Gui = FreeCADGui
Expand All @@ -47,16 +48,7 @@ def tearDown(self):
super().tearDown()

def test_parse(self):
json_data = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "BOX",
"lengthX": 0.04,
"lengthY": 0.01,
"lengthZ": 0.3,
"radius": 0.0,
"color": 12632256
}"""
json_data = TEST_JSON_PART_BOX

json_object = json.loads(json_data)
json_part = AJsonPart().parse_from_json(json_object)
Expand All @@ -67,7 +59,7 @@ def test_parse(self):

self.assertEqual(json_part.length, 40, "Property is correctly set")
self.assertEqual(json_part.width, 10, "Property is correctly set")
self.assertEqual(json_part.height, 300, "Property is correctly set")
self.assertEqual(json_part.height, 30, "Property is correctly set")
self.assertEqual(json_part.radius, 0, "Property is correctly set and")

self.assertEqual(json_part.color, 12632256 << 8, "Property is correctly set")
Expand Down
12 changes: 2 additions & 10 deletions test/json_io/parts/test_json_part_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import FreeCAD
import FreeCADGui
from json_io.parts.json_part_box import JsonPartBox
from test.json_io.test_json_data import TEST_JSON_PART_BOX

App = FreeCAD
Gui = FreeCADGui
Expand All @@ -47,16 +48,7 @@ def tearDown(self):
super().tearDown()

def test_create_part_box(self):
json_data = """{
"color": 12632256,
"shape": "BOX",
"name": "Beam",
"lengthX": 0.04,
"lengthY": 0.02,
"lengthZ": 0.01,
"radius": 0.0,
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022"
}"""
json_data = TEST_JSON_PART_BOX

active_document = ActiveDocument(self._WORKING_DIRECTORY).open_set_and_get_document("PartBox")
json_object = json.loads(json_data)
Expand Down
12 changes: 2 additions & 10 deletions test/json_io/parts/test_json_part_cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from json_io.parts.json_part_cone import JsonPartCone
import FreeCAD
import FreeCADGui
from test.json_io.test_json_data import TEST_JSON_PART_CONE

App = FreeCAD
Gui = FreeCADGui
Expand All @@ -47,16 +48,7 @@ def tearDown(self):
super().tearDown()

def test_create_part_cone(self):
json_data = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "CONE",
"lengthX": 0.0,
"lengthY": 0.5,
"lengthZ": 0.0,
"radius": 0.2,
"color": 12632256
}"""
json_data = TEST_JSON_PART_CONE

active_document = ActiveDocument(self._WORKING_DIRECTORY).open_set_and_get_document("PartCone")
json_object = json.loads(json_data)
Expand Down
12 changes: 2 additions & 10 deletions test/json_io/parts/test_json_part_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import FreeCAD
import FreeCADGui
from json_io.parts.json_part_cylinder import JsonPartCylinder
from test.json_io.test_json_data import TEST_JSON_PART_CYLINDER

App = FreeCAD
Gui = FreeCADGui
Expand All @@ -47,16 +48,7 @@ def tearDown(self):
super().tearDown()

def test_create_part_cylinder(self):
json_data = """{
"color": 12632256,
"shape": "CYLINDER",
"name": "Tube",
"lengthX": 0.0,
"lengthY": 0.1,
"lengthZ": 0.0,
"radius": 0.05,
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022"
}"""
json_data = TEST_JSON_PART_CYLINDER

active_document = ActiveDocument(self._WORKING_DIRECTORY).open_set_and_get_document("PartCylinder")
json_object = json.loads(json_data)
Expand Down
71 changes: 9 additions & 62 deletions test/json_io/parts/test_json_part_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,108 +33,55 @@
from json_io.parts.json_part_geometry import JsonPartGeometry
from json_io.parts.json_part_cylinder import JsonPartCylinder
from json_io.parts.json_part_cone import JsonPartCone
from test.json_io.test_json_data import TEST_JSON_PART_BOX, TEST_JSON_PART_CONE,\
TEST_JSON_PART_CYLINDER, TEST_JSON_PART_SPHERE, TEST_JSON_PART_GEOMETRY,\
TEST_JSON_PART_NONE


class TestJsonPartFactory(unittest.TestCase):

def test_create_box(self):
json_data = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "BOX",
"lengthX": 0.04,
"lengthY": 0.01,
"lengthZ": 0.3,
"radius": 0.0,
"color": 12632256
}"""
json_data = TEST_JSON_PART_BOX

json_object = json.loads(json_data)
json_part = JsonPartFactory().create_from_json(json_object)

self.assertIsInstance(json_part, JsonPartBox, "Created correct object")

def test_create_cone(self):
json_data = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "CONE",
"lengthX": 0.04,
"lengthY": 0.01,
"lengthZ": 0.3,
"radius": 0.0,
"color": 12632256
}"""
json_data = TEST_JSON_PART_CONE

json_object = json.loads(json_data)
json_part = JsonPartFactory().create_from_json(json_object)

self.assertIsInstance(json_part, JsonPartCone, "Created correct object")

def test_create_cylinder(self):
json_data = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "CYLINDER",
"lengthX": 0.04,
"lengthY": 0.01,
"lengthZ": 0.3,
"radius": 0.0,
"color": 12632256
}"""
json_data = TEST_JSON_PART_CYLINDER

json_object = json.loads(json_data)
json_part = JsonPartFactory().create_from_json(json_object)

self.assertIsInstance(json_part, JsonPartCylinder, "Created correct object")

def test_create_sphere(self):
json_data = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "SPHERE",
"lengthX": 0.04,
"lengthY": 0.01,
"lengthZ": 0.3,
"radius": 0.0,
"color": 12632256
}"""
json_data = TEST_JSON_PART_SPHERE

json_object = json.loads(json_data)
json_part = JsonPartFactory().create_from_json(json_object)

self.assertIsInstance(json_part, JsonPartSphere, "Created correct object")

def test_create_geometry(self):
json_data = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "GEOMETRY",
"lengthX": 0.04,
"lengthY": 0.01,
"lengthZ": 0.3,
"radius": 0.0,
"color": 12632256,
"stlPath" : "testfile.stl"
}"""
json_data = TEST_JSON_PART_GEOMETRY

json_object = json.loads(json_data)
json_part = JsonPartFactory().create_from_json(json_object)

self.assertIsInstance(json_part, JsonPartGeometry, "Created correct object")

def test_create_none(self):
json_data = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "NONE",
"lengthX": 0.04,
"lengthY": 0.01,
"lengthZ": 0.3,
"radius": 0.0,
"color": 12632256,
"stlPath" : "testfile.stl"
}"""
json_data = TEST_JSON_PART_NONE

json_object = json.loads(json_data)
json_part = JsonPartFactory().create_from_json(json_object)
Expand Down
13 changes: 2 additions & 11 deletions test/json_io/parts/test_json_part_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from json_io.parts.json_part_geometry import JsonPartGeometry
from module.environment import Environment
from json_io.json_definitions import JSON_ELEMENT_STL_PATH
from test.json_io.test_json_data import TEST_JSON_PART_GEOMETRY

App = FreeCAD
Gui = FreeCADGui
Expand All @@ -49,17 +50,7 @@ def tearDown(self):
super().tearDown()

def test_create_part_geometry(self):
json_data = """{
"color": 66280,
"shape": "GEOMETRY",
"name": "Geometry",
"lengthY": 1.0,
"lengthX": 0.0,
"radius": 1.0,
"lengthZ": 0.0,
"uuid": "38eae3a5-8338-4a51-b1df-5583058f9e77",
"stlPath": "Test.stl"
}"""
json_data = TEST_JSON_PART_GEOMETRY

active_document = ActiveDocument(self._WORKING_DIRECTORY).open_set_and_get_document("PartGeometry")
json_object = json.loads(json_data)
Expand Down
12 changes: 2 additions & 10 deletions test/json_io/parts/test_json_part_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import FreeCAD
import FreeCADGui
from json_io.parts.json_part_sphere import JsonPartSphere
from test.json_io.test_json_data import TEST_JSON_PART_SPHERE

App = FreeCAD
Gui = FreeCADGui
Expand All @@ -47,16 +48,7 @@ def tearDown(self):
super().tearDown()

def test_create_part_sphere(self):
json_data = """{
"color": 12632256,
"shape": "SPHERE",
"name": "Tube",
"lengthX": 0.0,
"lengthY": 0.0,
"lengthZ": 0.0,
"radius": 0.003,
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022"
}"""
json_data = TEST_JSON_PART_SPHERE

active_document = ActiveDocument(self._WORKING_DIRECTORY).open_set_and_get_document("PartSphere")
json_object = json.loads(json_data)
Expand Down
93 changes: 93 additions & 0 deletions test/json_io/test_json_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
#
# Virtual Satellite 4 - FreeCAD module
#
# Copyright (C) 2019 by
#
# DLR (German Aerospace Center),
# Software for Space Systems and interactive Visualization
# Braunschweig, Germany
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
#

TEST_JSON_PART_BOX = """{
"color": 12632256,
"shape": "BOX",
"name": "Beam",
"lengthX": 0.04,
"lengthY": 0.02,
"lengthZ": 0.01,
"radius": 0.0,
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022"
}"""

TEST_JSON_PART_CONE = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "CONE",
"lengthX": 0.0,
"lengthY": 0.5,
"lengthZ": 0.0,
"radius": 0.2,
"color": 12632256
}"""

TEST_JSON_PART_CYLINDER = """{
"color": 12632256,
"shape": "CYLINDER",
"name": "Tube",
"lengthX": 0.0,
"lengthY": 0.1,
"lengthZ": 0.0,
"radius": 0.05,
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022"
}"""

TEST_JSON_PART_SPHERE = """{
"color": 12632256,
"shape": "SPHERE",
"name": "Tube",
"lengthX": 0.0,
"lengthY": 0.0,
"lengthZ": 0.0,
"radius": 0.003,
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022"
}"""

TEST_JSON_PART_GEOMETRY = """{
"color": 66280,
"shape": "GEOMETRY",
"name": "Geometry",
"lengthY": 1.0,
"lengthX": 0.0,
"radius": 1.0,
"lengthZ": 0.0,
"uuid": "38eae3a5-8338-4a51-b1df-5583058f9e77",
"stlPath": "Test.stl"
}"""

TEST_JSON_PART_NONE = """{
"name": "Beam",
"uuid": "6201a731-d703-43f8-ab37-6a0581dfe022",
"shape": "NONE",
"lengthX": 0.04,
"lengthY": 0.01,
"lengthZ": 0.3,
"radius": 0.0,
"color": 12632256,
"stlPath" : "testfile.stl"
}"""

0 comments on commit dcd23c2

Please sign in to comment.