Update test code for Python3.
This commit is contained in:
parent
bf61e4920f
commit
9eae9ba98e
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,4 @@
|
||||||
*~
|
*~
|
||||||
|
*.pyc
|
||||||
|
.pytest_cache/
|
||||||
|
__pycache__/
|
||||||
|
|
|
@ -46,7 +46,7 @@ Currently Provided Tools:
|
||||||
* motors.scad:
|
* motors.scad:
|
||||||
- stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL)
|
- 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
|
* nuts_and_bolts.scad: for creating metric and imperial bolt/nut holes
|
||||||
* bearing.scad: standard/custom bearings
|
* bearing.scad: standard/custom bearings
|
||||||
|
@ -69,6 +69,26 @@ Very generally useful functions and constants:
|
||||||
* shapes.scad: DEPRECATED simple shapes by Catarina Mota
|
* shapes.scad: DEPRECATED simple shapes by Catarina Mota
|
||||||
* polyholes.scad: holes that should come out well when printed
|
* 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:
|
External utils that generate and and process openscad code:
|
||||||
|
|
||||||
* openscad_testing.py: testing code, see below
|
* openscad_testing.py: testing code, see below
|
||||||
|
|
|
@ -7,16 +7,20 @@ temppath = py.test.ensuretemp('MCAD')
|
||||||
|
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
if "modpath" in metafunc.funcargnames:
|
if "modpath" in metafunc.funcargnames:
|
||||||
|
args1 = []
|
||||||
|
args2 = []
|
||||||
for fpath, modnames in collect_test_modules().items():
|
for fpath, modnames in collect_test_modules().items():
|
||||||
basename = os.path.splitext(os.path.split(str(fpath))[1])[0]
|
basename = os.path.splitext(os.path.split(str(fpath))[1])[0]
|
||||||
#os.system("cp %s %s/" % (fpath, temppath))
|
|
||||||
if "modname" in metafunc.funcargnames:
|
if "modname" in metafunc.funcargnames:
|
||||||
for modname in modnames:
|
for modname in modnames:
|
||||||
print modname
|
args2.append([fpath, modname])
|
||||||
metafunc.addcall(id=basename+"/"+modname, funcargs=dict(modname=modname, modpath=fpath))
|
|
||||||
else:
|
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):
|
def test_module_compile(modname, modpath):
|
||||||
tempname = modpath.basename + '-' + modname + '.scad'
|
tempname = modpath.basename + '-' + modname + '.scad'
|
||||||
|
@ -29,23 +33,21 @@ use <%s>
|
||||||
|
|
||||||
%s();
|
%s();
|
||||||
""" % (modpath, modname)
|
""" % (modpath, modname)
|
||||||
print code
|
print(code)
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
output = call_openscad(path=fpath, stlpath=stlpath, timeout=15)
|
output = call_openscad(path=fpath, stlpath=stlpath, timeout=60)
|
||||||
print output
|
print(output)
|
||||||
assert output[0] is 0
|
assert output[0] is 0
|
||||||
for s in ("warning", "error"):
|
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
|
assert len(stlpath.readlines()) > 2
|
||||||
|
|
||||||
def test_file_compile(modpath):
|
def test_file_compile(modpath):
|
||||||
stlpath = temppath.join(modpath.basename + "-test.stl")
|
stlpath = temppath.join(modpath.basename + "-test.stl")
|
||||||
output = call_openscad(path=modpath, stlpath=stlpath)
|
output = call_openscad(path=modpath, stlpath=stlpath)
|
||||||
print output
|
print(output)
|
||||||
assert output[0] is 0
|
assert output[0] is 0
|
||||||
for s in ("warning", "error"):
|
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
|
assert len(stlpath.readlines()) == 2
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
mod_re = (r"\bmodule\s+(", r")\s*\(\s*")
|
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):
|
def collect_test_modules(dirpath=None):
|
||||||
dirpath = dirpath or py.path.local("./")
|
dirpath = dirpath or py.path.local("./")
|
||||||
print "Collecting openscad test module names"
|
print("Collecting openscad test module names")
|
||||||
|
|
||||||
test_files = {}
|
test_files = {}
|
||||||
for fpath in dirpath.visit('*.scad'):
|
for fpath in dirpath.visit('*.scad'):
|
||||||
#print fpath
|
#print(fpath)
|
||||||
modules = extract_mod_names(fpath, r"test\w*")
|
modules = extract_mod_names(fpath, r"test\w*")
|
||||||
#functions = extract_func_names(fpath, r"test\w*")
|
#functions = extract_func_names(fpath, r"test\w*")
|
||||||
test_files[fpath] = modules
|
test_files[fpath] = modules
|
||||||
|
@ -32,20 +32,20 @@ class Timeout(Exception): pass
|
||||||
def call_openscad(path, stlpath, timeout=5):
|
def call_openscad(path, stlpath, timeout=5):
|
||||||
if sys.platform == 'darwin': exe = 'OpenSCAD.app/Contents/MacOS/OpenSCAD'
|
if sys.platform == 'darwin': exe = 'OpenSCAD.app/Contents/MacOS/OpenSCAD'
|
||||||
else: exe = 'openscad'
|
else: exe = 'openscad'
|
||||||
command = [exe, '-s', str(stlpath), str(path)]
|
command = [exe, '-o', str(stlpath), str(path)]
|
||||||
print command
|
print(command)
|
||||||
if timeout:
|
if timeout:
|
||||||
try:
|
try:
|
||||||
proc = Popen(command,
|
proc = Popen(command,
|
||||||
stdout=PIPE, stderr=PIPE, close_fds=True)
|
stdout=PIPE, stderr=PIPE, close_fds=True)
|
||||||
calltime = time.time()
|
calltime = time.time()
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
#print calltime
|
#print(calltime)
|
||||||
while True:
|
while True:
|
||||||
if proc.poll() is not None:
|
if proc.poll() is not None:
|
||||||
break
|
break
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
#print time.time()
|
#print(time.time())
|
||||||
if time.time() > calltime + timeout:
|
if time.time() > calltime + timeout:
|
||||||
raise Timeout()
|
raise Timeout()
|
||||||
finally:
|
finally:
|
||||||
|
@ -57,7 +57,7 @@ def call_openscad(path, stlpath, timeout=5):
|
||||||
|
|
||||||
return (proc.returncode,) + proc.communicate()
|
return (proc.returncode,) + proc.communicate()
|
||||||
else:
|
else:
|
||||||
output = commands.getstatusoutput(" ".join(command))
|
output = subprocess.getstatusoutput(" ".join(command)).decode("utf-8")
|
||||||
return output + ('', '')
|
return output + ('', '')
|
||||||
|
|
||||||
def parse_output(text):
|
def parse_output(text):
|
||||||
|
|
|
@ -4,15 +4,17 @@ import os.path
|
||||||
dirpath = py.path.local("./")
|
dirpath = py.path.local("./")
|
||||||
|
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
|
names = []
|
||||||
if "filename" in metafunc.funcargnames:
|
if "filename" in metafunc.funcargnames:
|
||||||
for fpath in dirpath.visit('*.scad'):
|
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'):
|
for fpath in dirpath.visit('*.py'):
|
||||||
name = fpath.basename
|
name = fpath.basename
|
||||||
if not (name.startswith('test_') or name.startswith('_')):
|
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):
|
def test_README(filename):
|
||||||
README = dirpath.join('README').read()
|
README = dirpath.join('README.markdown').read()
|
||||||
|
|
||||||
assert filename in README
|
assert filename in README
|
||||||
|
|
Loading…
Reference in a new issue