Skip to content

Commit fa26086

Browse files
committed
Added tests for #163
1 parent 4a4872f commit fa26086

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

solid/examples/scad_to_include.scad

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ module steps(howmany=3){
1515

1616
function scad_points() = [[0,0], [1,0], [0,1]];
1717

18+
// In Python, calling this function without an argument would be an error.
19+
// Leave this here to confirm that this works in OpenSCAD.
20+
function optional_nondefault_arg(arg1){
21+
s = arg1 ? arg1 : 1;
22+
cube([s,s,s]);
23+
}
24+
1825
echo("This text should appear only when called with include(), not use()");

solid/test/test_solidpython.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ def test_parse_scad_callables(self):
143143
module var_with_arithmetic(var_with_arithmetic = 8 * 9 - 1 + 89 / 15){}
144144
module var_with_parentheses(var_with_parentheses = 8 * ((9 - 1) + 89) / 15){}
145145
module var_with_functions(var_with_functions = abs(min(chamferHeight2, 0)) */-+ 1){}
146-
module var_with_conditionnal_assignment(var_with_conditionnal_assignment = mytest ? 45 : yop){}
146+
module var_with_conditional_assignment(var_with_conditional_assignment = mytest ? 45 : yop){}
147147
"""
148148
expected = [
149149
{'name': 'hex', 'args': [], 'kwargs': ['width', 'height', 'flats', 'center']},
150150
{'name': 'righty', 'args': [], 'kwargs': ['angle']},
151-
{'name': 'lefty', 'args': ['avar'], 'kwargs': []},
151+
{'name': 'lefty', 'args': [], 'kwargs': ['avar']},
152152
{'name': 'more', 'args': [], 'kwargs': ['a']},
153153
{'name': 'pyramid', 'args': [], 'kwargs': ['side', 'height', 'square', 'centerHorizontal', 'centerVertical']},
154154
{'name': 'no_comments', 'args': [], 'kwargs': ['arg', 'other_arg', 'last_arg']},
155155
{'name': 'float_arg', 'args': [], 'kwargs': ['arg']},
156-
{'name': 'arg_var', 'args': ['var5'], 'kwargs': []},
156+
{'name': 'arg_var', 'args': [], 'kwargs': ['var5']},
157157
{'name': 'kwarg_var', 'args': [], 'kwargs': ['var2']},
158158
{'name': 'var_true', 'args': [], 'kwargs': ['var_true']},
159159
{'name': 'var_false', 'args': [], 'kwargs': ['var_false']},
@@ -172,7 +172,7 @@ def test_parse_scad_callables(self):
172172
{'name': 'var_with_arithmetic', 'args': [], 'kwargs': ['var_with_arithmetic']},
173173
{'name': 'var_with_parentheses', 'args': [], 'kwargs': ['var_with_parentheses']},
174174
{'name': 'var_with_functions', 'args': [], 'kwargs': ['var_with_functions']},
175-
{'name': 'var_with_conditionnal_assignment', 'args': [], 'kwargs': ['var_with_conditionnal_assignment']}
175+
{'name': 'var_with_conditional_assignment', 'args': [], 'kwargs': ['var_with_conditional_assignment']}
176176
]
177177

178178
from solid.solidpython import parse_scad_callables
@@ -205,6 +205,12 @@ def test_import_scad(self):
205205
expected = f"{header}\nuse <{abs_path}>\n\n\nsteps(howmany = 3);"
206206
self.assertEqual(expected, actual)
207207

208+
# Confirm that we can leave out even non-default arguments in OpenSCAD
209+
a = mod.optional_nondefault_arg();
210+
actual = scad_render(a)
211+
expected = f'use <{abs_path}>\n\n\noptional_nondefault_arg();'
212+
self.assertEqual(expected, actual);
213+
208214
# Make sure we throw ValueError on nonexistent imports
209215
self.assertRaises(ValueError, import_scad, 'path/doesnt/exist.scad')
210216

0 commit comments

Comments
 (0)