Skip to content

Commit

Permalink
Unifying test data - (Task #5)
Browse files Browse the repository at this point in the history
- Added test data to test data module for product related test cases

---
Task #5: Implement Import Functionality
  • Loading branch information
PhilMFischer committed Oct 24, 2019
1 parent 6df536e commit 59b2973
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 210 deletions.
62 changes: 11 additions & 51 deletions test/json_io/products/test_json_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import FreeCAD
import FreeCADGui
from json_io.products.json_product import AJsonProduct
from test.json_io.test_json_data import TEST_JSON_PRODUCT_WITHOUT_CHILDREN


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

def test_parse(self):
json_data = """{
"name": "BasePlateBottom",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate",
"posX": 2.0,
"posY": 3.0,
"posZ": 4.0,
"rotX": 0.1,
"rotY": 0.2,
"rotZ": 0.3,
"children": [
]
}
"""
json_data = TEST_JSON_PRODUCT_WITHOUT_CHILDREN

json_object = json.loads(json_data)
json_product = AJsonProduct().parse_from_json(json_object)
Expand All @@ -72,32 +59,18 @@ def test_parse(self):
self.assertEqual(json_product.part_name, "BasePlate", "Property is correctly set")
self.assertEqual(json_product.part_uuid, "3d3708fd_5c6c_4af9_b710_d68778466084", "Property is correctly set")

self.assertEqual(json_product.pos_x, 2000, "Property is correctly set")
self.assertEqual(json_product.pos_y, 3000, "Property is correctly set")
self.assertEqual(json_product.pos_z, 4000, "Property is correctly set")
self.assertEqual(json_product.pos_x, 20, "Property is correctly set")
self.assertEqual(json_product.pos_y, 30, "Property is correctly set")
self.assertEqual(json_product.pos_z, 40, "Property is correctly set")

self.assertEqual(json_product.rot_x, 5.729577951308233, "Property is correctly set")
self.assertEqual(json_product.rot_y, 11.459155902616466, "Property is correctly set")
self.assertEqual(json_product.rot_z, 17.188733853924695, "Property is correctly set")
self.assertAlmostEqual(json_product.rot_x, 20, 5, "Property is correctly set")
self.assertAlmostEqual(json_product.rot_y, 40, 5, "Property is correctly set")
self.assertAlmostEqual(json_product.rot_z, 60, 5, "Property is correctly set")

self.assertFalse(json_product.has_children, "The defined product has an empty list of children")

def test_get_unique_names(self):
json_data = """{
"name": "BasePlateBottom",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate",
"posX": 2.0,
"posY": 3.0,
"posZ": 4.0,
"rotX": 0.1,
"rotY": 0.2,
"rotZ": 0.3,
"children": [
]
}
"""
json_data = TEST_JSON_PRODUCT_WITHOUT_CHILDREN

json_object = json.loads(json_data)
json_product = AJsonProduct().parse_from_json(json_object)
Expand Down Expand Up @@ -125,21 +98,8 @@ def test_is_part_reference(self):

self.assertFalse(json_product.is_part_reference(), "The current product does not reference a part")

json_data = """{
"name": "BasePlateBottom",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate",
"posX": 2.0,
"posY": 3.0,
"posZ": 4.0,
"rotX": 0.1,
"rotY": 0.2,
"rotZ": 0.3,
"children": [
]
}
"""
json_data = TEST_JSON_PRODUCT_WITHOUT_CHILDREN

json_object = json.loads(json_data)
json_product = AJsonProduct().parse_from_json(json_object)

Expand Down
62 changes: 4 additions & 58 deletions test/json_io/products/test_json_product_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import FreeCADGui
from json_io.products.json_product_assembly import JsonProductAssembly
from freecad.active_document import ActiveDocument
from test.json_io.test_json_data import TEST_JSON_PRODUCT_WITH_CHILDREN,\
TEST_JSON_PRODUCT_WITHOUT_CHILDREN


App = FreeCAD
Expand All @@ -39,49 +41,7 @@

class TestJsonProductAssembly(AWorkingDirectoryTest):

json_data = """{
"name": "BasePlateBottom1",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate",
"posX": 10.0,
"posY": 15.0,
"posZ": 20.0,
"rotX": 0.349,
"rotY": 0.698,
"rotZ": 1.046,
"children": [
{
"posX": 0.0,
"posY": 0.0,
"posZ": 0.0,
"rotX": 0.0,
"children": [
],
"rotZ": 0.0,
"rotY": 0.0,
"name": "BasePlateBottom2",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate"
},
{
"posX": 0.0,
"posY": 0.0,
"posZ": 0.5,
"rotX": 0.0,
"children": [
],
"rotZ": 0.0,
"rotY": 0.0,
"name": "BasePlateTop",
"uuid": "a199e3bd-3bc1-426d-8321-e9bd829339b3",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate"
}
]
}
"""
json_data = TEST_JSON_PRODUCT_WITH_CHILDREN

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -120,21 +80,7 @@ def test_parse_with_children(self):
self.assertEqual(json_product_child_2.name, "BasePlateTop", "Parsed correct child")

def test_parse_with_no_children(self):
json_data = """{
"name": "BasePlateBottom",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate",
"posX": 2.0,
"posY": 3.0,
"posZ": 4.0,
"rotX": 0.1,
"rotY": 0.2,
"rotZ": 0.3,
"children": [
]
}
"""
json_data = TEST_JSON_PRODUCT_WITHOUT_CHILDREN

json_object = json.loads(json_data)
json_product = JsonProductAssembly().parse_from_json(json_object)
Expand Down
49 changes: 4 additions & 45 deletions test/json_io/products/test_json_product_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from json_io.products.json_product_child import JsonProductChild
from freecad.active_document import ActiveDocument
from json_io.json_definitions import get_product_name_uuid
from test.json_io.test_json_data import TEST_JSON_PRODUCT_WITHOUT_CHILDREN,\
TEST_JSON_PRODUCT_WITH_ONE_CHILD


App = FreeCAD
Expand All @@ -40,51 +42,8 @@

class TestJsonProductChild(AWorkingDirectoryTest):

json_data = """{
"name": "BasePlateBottom",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate",
"posX": 0.02,
"posY": 0.03,
"posZ": 0.04,
"rotX": 0.3490659,
"rotY": 0.6981317,
"rotZ": 1.0471976,
"children": [
]
}
"""

json_data_with_child = """{
"name": "BasePlateBottom",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate",
"posX": 0.02,
"posY": 0.03,
"posZ": 0.04,
"rotX": 0.3490659,
"rotY": 0.6981317,
"rotZ": 1.0471976,
"children": [
{
"posX": 0.0,
"posY": 0.0,
"posZ": 0.0,
"rotX": 0.0,
"children": [
],
"rotZ": 0.0,
"rotY": 0.0,
"name": "BasePlateBottom",
"uuid": "e8794f3d-86ec-44c5-9618-8b7170c45484",
"partUuid": "3d3708fd-5c6c-4af9-b710-d68778466084",
"partName": "BasePlate"
}
]
}
"""
json_data = TEST_JSON_PRODUCT_WITHOUT_CHILDREN
json_data_with_child = TEST_JSON_PRODUCT_WITH_ONE_CHILD

@classmethod
def setUpClass(cls):
Expand Down
Loading

0 comments on commit 59b2973

Please sign in to comment.