Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small improvements to the testing infra.

  • Loading branch information...
commit 30607913a3f51f9aec9a2c882d536513fa384209 1 parent f0960f9
Elmo authored rambo committed
Showing with 28 additions and 22 deletions.
  1. +17 −13 openscad_utils.py
  2. +11 −9 test_compile.py
View
30 openscad_utils.py
@@ -4,20 +4,21 @@
mod_re = (r"\bmodule\s+(", r")\s*\(\s*")
func_re = (r"\bfunction\s+(", r")\s*\(")
-def extract_mod_names(fpath, name_re=r"\w+"):
- regex = name_re.join(mod_re)
+def extract_definitions(fpath, name_re=r"\w+", def_re=""):
+ regex = name_re.join(def_re)
matcher = re.compile(regex)
return (m.group(1) for m in matcher.finditer(fpath.read()))
+def extract_mod_names(fpath, name_re=r"\w+"):
+ return extract_definitions(fpath, name_re=name_re, def_re=mod_re)
+
def extract_func_names(fpath, name_re=r"\w+"):
- regex = name_re.join(func_re)
- matcher = re.compile(regex)
- return (m.group(1) for m in matcher.finditer(fpath.read()))
+ return extract_definitions(fpath, name_re=name_re, def_re=func_re)
-def collect_test_modules():
- dirpath = py.path.local("./")
+def collect_test_modules(dirpath=None):
+ dirpath = dirpath or py.path.local("./")
print "Collecting openscad test module names"
-
+
test_files = {}
for fpath in dirpath.visit('*.scad'):
#print fpath
@@ -26,21 +27,24 @@ def collect_test_modules():
test_files[fpath] = modules
return test_files
-collect_test_modules()
+class Timeout(Exception): pass
-def call_openscad(path, stlpath, timeout=20):
+def call_openscad(path, stlpath, timeout=1):
try:
- proc = Popen(['openscad', '-s', str(stlpath), str(path)],
+ command = ['openscad', '-s', str(stlpath), str(path)]
+ print command
+ proc = Popen(command,
stdout=PIPE, stderr=PIPE, close_fds=True)
calltime = time.time()
+ time.sleep(0.01)
#print calltime
while True:
if proc.poll() is not None:
break
- time.sleep(0.1)
+ time.sleep(0.5)
#print time.time()
if time.time() > calltime + timeout:
- raise Exception("Timeout")
+ raise Timeout()
finally:
try:
proc.terminate()
View
20 test_compile.py
@@ -2,21 +2,22 @@
from openscad_utils import *
+
+temppath = py.test.ensuretemp('MCAD')
+
def pytest_generate_tests(metafunc):
if "modpath" in metafunc.funcargnames:
- if "modname" in metafunc.funcargnames:
- for fpath, modnames in collect_test_modules().items():
+ for fpath, modnames in collect_test_modules().items():
+ os.system("cp %s %s/" % (fpath, temppath))
+ if "modname" in metafunc.funcargnames:
for modname in modnames:
metafunc.addcall(funcargs=dict(modname=modname, modpath=fpath))
- else:
- dirpath = py.path.local("./")
- for fpath in dirpath.visit('*.scad'):
+ else:
metafunc.addcall(funcargs=dict(modpath=fpath))
-temppath = py.test.ensuretemp('MCAD')
def test_compile(modname, modpath):
- tempname = "test_" + modpath.basename + modname
+ tempname = "test_" + modpath.basename + modname + '.scad'
fpath = temppath.join(tempname)
stlpath = temppath.join(tempname + ".stl")
f = fpath.open('w')
@@ -24,10 +25,10 @@ def test_compile(modname, modpath):
//generated testfile
include <%s>
-%s()
+%s();
""" % (modpath, modname))
f.flush
- output = call_openscad(path=fpath, stlpath=stlpath)
+ output = call_openscad(path=fpath, stlpath=stlpath, timeout=5)
print output
assert output[0] is 0
assert "warning" or "error" not in output[2].strip().lowercase()
@@ -40,5 +41,6 @@ def test_compile_default(modpath):
print output
assert output[0] is 0
assert "warning" or "error" not in output[2].strip().lowercase()
+ assert len(stlpath.readlines()) == 2
Please sign in to comment.
Something went wrong with that request. Please try again.