77 defining a build_object function to return results
88"""
99
10+ import pytest
1011from cadquery import cqgi
1112from tests import BaseTest
1213import textwrap
1617 height=2.0
1718 width=3.0
1819 (a,b) = (1.0,1.0)
20+ o = (2, 2, 0)
1921 foo="bar"
2022
21- result = "%s|%s|%s|%s" % ( str(height) , str(width) , foo , str(a) )
23+ result = "%s|%s|%s|%s|%s " % ( str(height) , str(width) , foo , str(a) , str(o ) )
2224 show_object(result)
2325 """
2426)
2830 height=2.0
2931 width=3.0
3032 (a,b) = (1.0,1.0)
33+ o = (2, 2, 0)
3134 foo="bar"
3235 debug(foo, { "color": 'yellow' } )
33- result = "%s|%s|%s|%s" % ( str(height) , str(width) , foo , str(a) )
36+ result = "%s|%s|%s|%s|%s " % ( str(height) , str(width) , foo , str(a) , str(o ) )
3437 show_object(result)
3538 debug(height )
3639 """
@@ -41,9 +44,8 @@ class TestCQGI(BaseTest):
4144 def test_parser (self ):
4245 model = cqgi .CQModel (TESTSCRIPT )
4346 metadata = model .metadata
44-
4547 self .assertEqual (
46- set (metadata .parameters .keys ()), {"height" , "width" , "a" , "b" , "foo" }
48+ set (metadata .parameters .keys ()), {"height" , "width" , "a" , "b" , "foo" , "o" }
4749 )
4850
4951 def test_build_with_debug (self ):
@@ -62,12 +64,19 @@ def test_build_with_empty_params(self):
6264
6365 self .assertTrue (result .success )
6466 self .assertTrue (len (result .results ) == 1 )
65- self .assertTrue (result .results [0 ].shape == "2.0|3.0|bar|1.0" )
67+ self .assertTrue (result .results [0 ].shape == "2.0|3.0|bar|1.0|(2, 2, 0) " )
6668
6769 def test_build_with_different_params (self ):
6870 model = cqgi .CQModel (TESTSCRIPT )
69- result = model .build ({"height" : 3.0 })
70- self .assertTrue (result .results [0 ].shape == "3.0|3.0|bar|1.0" )
71+ result = model .build ({"height" : 3.0 , "o" : (3 , 3 )})
72+ print (result .results [0 ].shape )
73+ self .assertTrue (result .results [0 ].shape == "3.0|3.0|bar|1.0|(3, 3)" )
74+
75+ def test_build_with_nested_tuple_params (self ):
76+ model = cqgi .CQModel (TESTSCRIPT )
77+ result = model .build ({"height" : 3.0 , "o" : ((2 , 2 ), (3 , 3 ))})
78+ print (result .results [0 ].shape )
79+ self .assertTrue (result .results [0 ].shape == "3.0|3.0|bar|1.0|((2, 2), (3, 3))" )
7180
7281 def test_describe_parameters (self ):
7382 script = textwrap .dedent (
@@ -222,3 +231,19 @@ def do_stuff():
222231 model = cqgi .parse (script )
223232
224233 self .assertEqual (2 , len (model .metadata .parameters ))
234+
235+ def test_invalid_parameter_type (self ):
236+ """Contrived test in case a parameter type that is not valid for InputParameter sneaks through."""
237+
238+ # Made up parameter class
239+ class UnknowParameter :
240+ def __init__ ():
241+ return 1
242+
243+ # Set up the most basic InputParameter object that is possible
244+ p = cqgi .InputParameter ()
245+ p .varType = UnknowParameter
246+
247+ # Setting the parameter should throw an unknown parameter type error
248+ with pytest .raises (ValueError ) as info :
249+ p .set_value (2 )
0 commit comments