Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed test_parse_scad_callables
	- parse_scad_callables now receives a filename -> write test_code to tempfile
	- since the code get written to a file string escapes need to be double escaped ;)
	- corrected syntax in var_with_functions parameters
  • Loading branch information
jeff-dh committed May 19, 2021
commit 9860be43e94000b79096ff8e7143711fba329dc5
12 changes: 8 additions & 4 deletions solid/solidpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,15 @@ def parse_scad_callables(filename: str) -> List[dict]:
args = []
kwargs = []

#for some reason solidpython needs to treat all openscad arguments as if
#they where optional. I don't know why, but at least to pass the tests
#it's neccessary to handle it like this !?!?!
for p in c.parameters:
if p.optional:
kwargs.append(p.name)
else:
args.append(p.name)
kwargs.append(p.name)
#if p.optional:
# kwargs.append(p.name)
#else:
# args.append(p.name)

callables.append({'name': c.name, 'args': args, 'kwargs': kwargs})

Expand Down
21 changes: 16 additions & 5 deletions solid/test/test_solidpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,24 @@ def test_parse_scad_callables(self):
module var_number(var_number = -5e89){}
module var_empty_vector(var_empty_vector = []){}
module var_simple_string(var_simple_string = "simple string"){}
module var_complex_string(var_complex_string = "a \"complex\"\tstring with a\\"){}
module var_complex_string(var_complex_string = "a \\"complex\\"\\tstring with a\\\\"){}
module var_vector(var_vector = [5454445, 565, [44545]]){}
module var_complex_vector(var_complex_vector = [545 + 4445, 565, [cos(75) + len("yes", 45)]]){}
module var_vector(var_vector = [5, 6, "string\twith\ttab"]){}
module var_vector(var_vector = [5, 6, "string\\twith\\ttab"]){}
module var_range(var_range = [0:10e10]){}
module var_range_step(var_range_step = [-10:0.5:10]){}
module var_with_arithmetic(var_with_arithmetic = 8 * 9 - 1 + 89 / 15){}
module var_with_parentheses(var_with_parentheses = 8 * ((9 - 1) + 89) / 15){}
module var_with_functions(var_with_functions = abs(min(chamferHeight2, 0)) */-+ 1){}
module var_with_functions(var_with_functions = abs(min(chamferHeight2, 0)) / 1){}
module var_with_conditional_assignment(var_with_conditional_assignment = mytest ? 45 : yop){}

"""

scad_file = ""
with tempfile.NamedTemporaryFile(suffix=".scad", delete=False) as f:
f.write(test_str.encode("utf-8"))
scad_file = f.name

expected = [
{'name': 'hex', 'args': [], 'kwargs': ['width', 'height', 'flats', 'center']},
{'name': 'righty', 'args': [], 'kwargs': ['angle']},
Expand Down Expand Up @@ -177,8 +184,12 @@ def test_parse_scad_callables(self):
]

from solid.solidpython import parse_scad_callables
actual = parse_scad_callables(test_str)
self.assertEqual(expected, actual)
actual = parse_scad_callables(scad_file)

for e in expected:
self.assertEqual(e in actual, True)

os.unlink(scad_file)

def test_use(self):
include_file = self.expand_scad_path("examples/scad_to_include.scad")
Expand Down