Skip to content

Commit 22be6d1

Browse files
Tests for accepting imported OpenSCAD calculations as arguments. This resolves #157 as well as #111
1 parent 37d1486 commit 22be6d1

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

solid/examples/scad_to_include.scad

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ module steps(howmany=3){
1313
}
1414
}
1515

16+
function scad_points() = [[0,0], [1,0], [0,1]];
17+
1618
echo("This text should appear only when called with include(), not use()");

solid/test/test_solidpython.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
scad_test_case_templates = [
1919
{'name': 'polygon', 'class': 'polygon' , 'kwargs': {'paths': [[0, 1, 2]]}, 'expected': '\n\npolygon(paths = [[0, 1, 2]], points = [[0, 0], [1, 0], [0, 1]]);', 'args': {'points': [[0, 0, 0], [1, 0, 0], [0, 1, 0]]}, },
20+
{'name': 'polygon', 'class': 'polygon' , 'kwargs': {}, 'expected': '\n\npolygon(points = [[0, 0], [1, 0], [0, 1]]);', 'args': {'points': [[0, 0, 0], [1, 0, 0], [0, 1, 0]]}, },
2021
{'name': 'circle', 'class': 'circle' , 'kwargs': {'segments': 12, 'r': 1}, 'expected': '\n\ncircle($fn = 12, r = 1);', 'args': {}, },
2122
{'name': 'circle_diam', 'class': 'circle' , 'kwargs': {'segments': 12, 'd': 1}, 'expected': '\n\ncircle($fn = 12, d = 1);', 'args': {}, },
2223
{'name': 'square', 'class': 'square' , 'kwargs': {'center': False, 'size': 1}, 'expected': '\n\nsquare(center = false, size = 1);', 'args': {}, },
@@ -219,6 +220,16 @@ def test_import_scad(self):
219220
# are imported correctly. Not sure how to do this without writing
220221
# temp files to those directories. Seems like overkill for the moment
221222

223+
def test_imported_scad_arguments(self):
224+
include_file = self.expand_scad_path("examples/scad_to_include.scad")
225+
mod = import_scad(include_file)
226+
points = mod.scad_points();
227+
poly = polygon(points);
228+
actual = scad_render(poly);
229+
abs_path = points._get_include_path(include_file)
230+
expected = f'use <{abs_path}>\n\n\npolygon(points = scad_points());'
231+
self.assertEqual(expected, actual)
232+
222233
def test_use_reserved_words(self):
223234
scad_str = '''module reserved_word_arg(or=3){\n\tcube(or);\n}\nmodule or(arg=3){\n\tcube(arg);\n}\n'''
224235

0 commit comments

Comments
 (0)