Skip to content

Commit

Permalink
Updated dicutil tests, import
Browse files Browse the repository at this point in the history
Update to PR #311 - revised "test/dictutil_test.py" import statements, updated names (files, function) as per comments. Added new tests for completeness. Verified that all tests pass.
  • Loading branch information
edpmay committed Jul 30, 2021
1 parent 432276c commit 8b176f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
LineSegment3D, Arc3D, Polyline3D, Polyface3D, Mesh3D,
Plane, Face3D, Sphere, Cone, Cylinder)

def lb_geom_dict_to_object(ladybug_geom_dict, raise_exception=True): #-> Optional[object]
def geometry_dict_to_object(ladybug_geom_dict, raise_exception=True):
# type (dict, bool) -> object | None
"""
Args:
ladybug_geom_dict (dict): A dictionary of any Ladybug Geometry object. Note
Expand Down
85 changes: 36 additions & 49 deletions tests/lb_dictutil_test.py → tests/dictutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,45 @@
Note: Written in PyTest format.
"""

import pytest
from ladybug_geometry.geometry2d import (Vector2D, Point2D, Ray2D,
LineSegment2D, Arc2D, Polyline2D, Polygon2D, Mesh2D)
from ladybug_geometry.geometry3d import (Vector3D, Point3D, Ray3D,
LineSegment3D, Arc3D, Polyline3D, Polyface3D, Mesh3D,
Plane, Face3D, Sphere, Cone, Cylinder)
from lb_dictutil import lb_geom_dict_to_object
from ladybug_geometry.dictutil import geometry_dict_to_object

#--- Test not Ladubug Geometry dict
def test_not_valid_dict():
d = { 'key_1':'val_1' } # dict Does NOT inlcude 'type' key
with pytest.raises(ValueError):
obj = geometry_dict_to_object( d )

def test_not_valid_dict():
d = { 'type':'not_a_valid_type' } # Includes 'type', but is not a valid Ladybug Type
with pytest.raises(ValueError):
obj = geometry_dict_to_object( d )

#--- Test 2D Geometry
def test_Point2D():
obj1 = Point2D()
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

def test_Arc2D():
pt1 = Point2D()
obj1 = Arc2D(pt1, 2)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

def test_Vector2D():
obj1 = Vector2D(0,1)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -38,7 +49,7 @@ def test_Ray2D():
v1 = Vector2D(0,1)
obj1 = Ray2D(pt1,v1)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -47,7 +58,7 @@ def test_LineSegment2D():
v1 = Vector2D(0,1)
obj1 = LineSegment2D(pt1,v1)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -57,7 +68,7 @@ def test_Polyline2D():
pt3 = Point2D(2,3)
obj1 = Polyline2D([pt1, pt2, pt3], False)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -68,7 +79,7 @@ def test_Polygon2D():
pt4 = Point2D(0,1)
obj1 = Polygon2D([pt1, pt2, pt3, pt4])
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -79,30 +90,30 @@ def test_Mesh2D():
pt4 = Point2D(0,1)
obj1 = Mesh2D(vertices=(pt1, pt2, pt3, pt4), faces=[(0,1,2)] )
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

#--- Test 3D Geometry
def test_Point3D():
obj1 = Point3D()
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

def test_Arc3D():
pl = Plane()
obj1 = Arc3D(pl, 2)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

def test_Vector3D():
obj1 = Vector3D(0,1)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -111,7 +122,7 @@ def test_Ray3D():
v1 = Vector3D(0,1)
obj1 = Ray3D(pt1,v1)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -120,7 +131,7 @@ def test_LineSegment3D():
v1 = Vector3D(0,1)
obj1 = LineSegment3D(pt1,v1)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -130,7 +141,7 @@ def test_Polyline3D():
pt3 = Point3D(2,3)
obj1 = Polyline3D([pt1, pt2, pt3], False)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -141,7 +152,7 @@ def test_Polyface3D():
pt4 = Point3D(0,1)
obj1 = Polyface3D(vertices=[pt1, pt2, pt3, pt4], face_indices=[ [[1]] ] )
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -153,14 +164,14 @@ def test_Mesh3D():
obj1 = Mesh3D(vertices=(pt1, pt2, pt3, pt4), faces=[(0,1,2)] )

d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

def test_Plane():
obj1 = Plane()
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -170,15 +181,15 @@ def test_Face3D():
pt3 = Point3D(2,3)
obj1 = Face3D([pt1, pt2, pt3])
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

def test_Sphere():
pt1 = Point3D()
obj1 = Sphere(pt1, 1)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -187,7 +198,7 @@ def test_Cone():
axis = Vector3D(0,0,1)
obj1 = Cone(v1, axis, 45)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

Expand All @@ -196,30 +207,6 @@ def test_Cylinder():
axis = Vector3D(0,0,1)
obj1 = Cylinder(v1, axis, 10)
d = obj1.to_dict()
obj2 = lb_geom_dict_to_object(d)

assert obj2 == obj1

# if __name__ == '__main__':
# test_Point2D()
# test_Arc2D()
# test_Vector2D()
# test_Ray2D()
# test_LineSegment2D()
# test_Polyline2D()
# test_Polygon2D()
# test_Mesh2D()

# test_Point3D()
# test_Arc3D()
# test_Vector3D()
# test_Ray3D()
# test_LineSegment3D()
# test_Polyline3D()
# test_Polyface3D()
# test_Mesh3D()
# test_Plane()
# test_Face3D()
# test_Sphere()
# test_Cone()
# test_Cylinder()
obj2 = geometry_dict_to_object(d)

assert obj2 == obj1

0 comments on commit 8b176f5

Please sign in to comment.