def test_scad_render_to_file(self): a = circle(10) # No header, no included original code with TemporaryFileBuffer() as tmp: scad_render_to_file(a, filepath=tmp.name, include_orig_code=False) actual = tmp.contents expected = '\n\ncircle(r = 10);' # scad_render_to_file also adds a date & version stamp before scad code; # That won't match here, so just make sure the correct code is at the end self.assertTrue(actual.endswith(expected)) # Header with TemporaryFileBuffer() as tmp: scad_render_to_file(a, filepath=tmp.name, include_orig_code=False, file_header='$fn = 24;') actual = tmp.contents expected = '$fn = 24;\n\n\ncircle(r = 10);' self.assertTrue(actual.endswith(expected)) # Test out_dir specification, both using an existing dir & creating one # Using existing directory with TemporaryFileBuffer() as tmp: out_dir = Path(tmp.name).parent expected = (out_dir / 'test_solidpython.scad').as_posix() actual = scad_render_to_file(a, out_dir=out_dir) self.assertEqual(expected, actual) # Creating a directory on demand with TemporaryFileBuffer() as tmp: out_dir = Path(tmp.name).parent / 'SCAD' expected = (out_dir / 'test_solidpython.scad').as_posix() actual = scad_render_to_file(a, out_dir=out_dir) self.assertEqual(expected, actual)
#use of id_coord dict to establish to and from points. # Add these objects to the 3d lines list. for line in diagram_2d_lines: l = Builder.build_connector(line.get_connector_type(), line.get_connector_2d_info(), id_coord[line.get_from()], id_coord[line.get_to()], msg_dict, agg_dict, id_coord) lines_3d.append(l) #Now call the respective functions for the 3d shapes and # lines list to create 3d cards and lines and store in lists scad_lines = [] scad_shapes = [] for shape in shapes_3d: scad_shapes.append(Builder.make_3d_shape(shape)) for line in lines_3d: scad_lines.append(Builder.make_3d_connector(line)) #Use assembly function to put the pieces together final_product = assembly(scad_lines, scad_shapes) SEGMENTS = 48 #file_name = input('File Name: ') file_name = ARGS.file_name #Create an openSCAD file from finished_product #TODO: this is a klunky way to make file and needs fixed scad_render_to_file(final_product, file_header='$fn = %s;'%SEGMENTS, include_orig_code=True)