2010-09-30 01:22:54 -05:00
|
|
|
import py, re, os, signal, time, commands
|
2010-07-26 12:56:02 -05:00
|
|
|
from subprocess import Popen, PIPE
|
2010-07-26 09:35:32 -05:00
|
|
|
|
|
|
|
mod_re = (r"\bmodule\s+(", r")\s*\(\s*")
|
|
|
|
func_re = (r"\bfunction\s+(", r")\s*\(")
|
|
|
|
|
2010-08-26 03:05:04 -05:00
|
|
|
def extract_definitions(fpath, name_re=r"\w+", def_re=""):
|
|
|
|
regex = name_re.join(def_re)
|
2010-07-26 09:35:32 -05:00
|
|
|
matcher = re.compile(regex)
|
|
|
|
return (m.group(1) for m in matcher.finditer(fpath.read()))
|
|
|
|
|
2010-08-26 03:05:04 -05:00
|
|
|
def extract_mod_names(fpath, name_re=r"\w+"):
|
|
|
|
return extract_definitions(fpath, name_re=name_re, def_re=mod_re)
|
|
|
|
|
2010-07-26 09:35:32 -05:00
|
|
|
def extract_func_names(fpath, name_re=r"\w+"):
|
2010-08-26 03:05:04 -05:00
|
|
|
return extract_definitions(fpath, name_re=name_re, def_re=func_re)
|
2010-07-26 09:35:32 -05:00
|
|
|
|
2010-08-26 03:05:04 -05:00
|
|
|
def collect_test_modules(dirpath=None):
|
|
|
|
dirpath = dirpath or py.path.local("./")
|
2010-07-26 09:35:32 -05:00
|
|
|
print "Collecting openscad test module names"
|
2010-08-26 03:05:04 -05:00
|
|
|
|
2010-07-26 09:35:32 -05:00
|
|
|
test_files = {}
|
|
|
|
for fpath in dirpath.visit('*.scad'):
|
|
|
|
#print fpath
|
|
|
|
modules = extract_mod_names(fpath, r"test\w*")
|
|
|
|
#functions = extract_func_names(fpath, r"test\w*")
|
|
|
|
test_files[fpath] = modules
|
|
|
|
return test_files
|
|
|
|
|
2010-08-26 03:05:04 -05:00
|
|
|
class Timeout(Exception): pass
|
2010-07-26 12:56:02 -05:00
|
|
|
|
2010-08-26 03:05:04 -05:00
|
|
|
def call_openscad(path, stlpath, timeout=1):
|
2010-09-30 01:22:54 -05:00
|
|
|
command = ['openscad', '-s', str(stlpath), str(path)]
|
|
|
|
print command
|
|
|
|
if timeout:
|
2010-07-26 12:56:02 -05:00
|
|
|
try:
|
2010-09-30 01:22:54 -05:00
|
|
|
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.5)
|
|
|
|
#print time.time()
|
|
|
|
if time.time() > calltime + timeout:
|
|
|
|
raise Timeout()
|
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
proc.terminate()
|
|
|
|
proc.kill()
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return (proc.returncode,) + proc.communicate()
|
|
|
|
else:
|
|
|
|
output = commands.getstatusoutput(" ".join(command))
|
|
|
|
return output + ('', '')
|
|
|
|
|
|
|
|
def parse_output(text):
|
|
|
|
pass
|