diff --git a/.gitignore b/.gitignore index b25c15b..979f64b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *~ +*.pyc +.pytest_cache/ +__pycache__/ diff --git a/README.markdown b/README.markdown index 266a637..3128a55 100644 --- a/README.markdown +++ b/README.markdown @@ -46,7 +46,7 @@ Currently Provided Tools: * motors.scad: - stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL) -Other tools (alpha and beta quality): +Tools (alpha and beta quality): * nuts_and_bolts.scad: for creating metric and imperial bolt/nut holes * bearing.scad: standard/custom bearings @@ -69,6 +69,26 @@ Very generally useful functions and constants: * shapes.scad: DEPRECATED simple shapes by Catarina Mota * polyholes.scad: holes that should come out well when printed +Other: + +* alphabet_block.scad +* bitmap.scad +* letter_necklace.scad +* name_tag.scad +* height_map.scad +* trochoids.scad +* libtriangles.scad +* layouts.scad +* transformations.scad +* 2Dshapes.scad +* gridbeam.scad +* fonts.scad +* unregular_shapes.scad +* metric_fastners.scad +* lego_compatibility.scad +* multiply.scad +* hardware.scad + External utils that generate and and process openscad code: * openscad_testing.py: testing code, see below diff --git a/openscad_testing.py b/openscad_testing.py index cadbc2f..05f30e7 100644 --- a/openscad_testing.py +++ b/openscad_testing.py @@ -7,16 +7,20 @@ temppath = py.test.ensuretemp('MCAD') def pytest_generate_tests(metafunc): if "modpath" in metafunc.funcargnames: + args1 = [] + args2 = [] for fpath, modnames in collect_test_modules().items(): basename = os.path.splitext(os.path.split(str(fpath))[1])[0] - #os.system("cp %s %s/" % (fpath, temppath)) if "modname" in metafunc.funcargnames: for modname in modnames: - print modname - metafunc.addcall(id=basename+"/"+modname, funcargs=dict(modname=modname, modpath=fpath)) + args2.append([fpath, modname]) else: - metafunc.addcall(id=os.path.split(str(fpath))[1], funcargs=dict(modpath=fpath)) + args1.append(fpath) + if "modname" in metafunc.funcargnames: + metafunc.parametrize(["modpath", "modname"], args2) + else: + metafunc.parametrize("modpath", args1) def test_module_compile(modname, modpath): tempname = modpath.basename + '-' + modname + '.scad' @@ -29,23 +33,21 @@ use <%s> %s(); """ % (modpath, modname) - print code + print(code) f.write(code) f.flush() - output = call_openscad(path=fpath, stlpath=stlpath, timeout=15) - print output + output = call_openscad(path=fpath, stlpath=stlpath, timeout=60) + print(output) assert output[0] is 0 for s in ("warning", "error"): - assert s not in output[2].strip().lower() + assert s not in output[2].strip().lower().decode("utf-8") assert len(stlpath.readlines()) > 2 def test_file_compile(modpath): stlpath = temppath.join(modpath.basename + "-test.stl") output = call_openscad(path=modpath, stlpath=stlpath) - print output + print(output) assert output[0] is 0 for s in ("warning", "error"): - assert s not in output[2].strip().lower() + assert s not in output[2].strip().lower().decode("utf-8") assert len(stlpath.readlines()) == 2 - - diff --git a/openscad_utils.py b/openscad_utils.py index 00d8dd9..c4a0880 100644 --- a/openscad_utils.py +++ b/openscad_utils.py @@ -1,4 +1,4 @@ -import py, re, os, signal, time, commands, sys +import py, re, os, signal, time, subprocess, sys from subprocess import Popen, PIPE mod_re = (r"\bmodule\s+(", r")\s*\(\s*") @@ -17,11 +17,11 @@ def extract_func_names(fpath, name_re=r"\w+"): def collect_test_modules(dirpath=None): dirpath = dirpath or py.path.local("./") - print "Collecting openscad test module names" + print("Collecting openscad test module names") test_files = {} for fpath in dirpath.visit('*.scad'): - #print fpath + #print(fpath) modules = extract_mod_names(fpath, r"test\w*") #functions = extract_func_names(fpath, r"test\w*") test_files[fpath] = modules @@ -32,20 +32,20 @@ class Timeout(Exception): pass def call_openscad(path, stlpath, timeout=5): if sys.platform == 'darwin': exe = 'OpenSCAD.app/Contents/MacOS/OpenSCAD' else: exe = 'openscad' - command = [exe, '-s', str(stlpath), str(path)] - print command + command = [exe, '-o', str(stlpath), str(path)] + print(command) if timeout: try: proc = Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True) calltime = time.time() time.sleep(0.05) - #print calltime + #print(calltime) while True: if proc.poll() is not None: break time.sleep(0.5) - #print time.time() + #print(time.time()) if time.time() > calltime + timeout: raise Timeout() finally: @@ -57,7 +57,7 @@ def call_openscad(path, stlpath, timeout=5): return (proc.returncode,) + proc.communicate() else: - output = commands.getstatusoutput(" ".join(command)) + output = subprocess.getstatusoutput(" ".join(command)).decode("utf-8") return output + ('', '') def parse_output(text): diff --git a/test_docs.py b/test_docs.py index cbf9b11..ff5c188 100644 --- a/test_docs.py +++ b/test_docs.py @@ -4,15 +4,17 @@ import os.path dirpath = py.path.local("./") def pytest_generate_tests(metafunc): + names = [] if "filename" in metafunc.funcargnames: for fpath in dirpath.visit('*.scad'): - metafunc.addcall(id=fpath.basename, funcargs=dict(filename=fpath.basename)) + names.append(fpath.basename) for fpath in dirpath.visit('*.py'): name = fpath.basename if not (name.startswith('test_') or name.startswith('_')): - metafunc.addcall(id=fpath.basename, funcargs=dict(filename=fpath.basename)) + names.append(name) + metafunc.parametrize("filename", names) def test_README(filename): - README = dirpath.join('README').read() + README = dirpath.join('README.markdown').read() assert filename in README