Improved testing and fixed a warning thus found

This commit is contained in:
Elmom 2010-09-30 09:22:54 +03:00
parent d650715b6f
commit 55bd2607c8
3 changed files with 35 additions and 26 deletions

View file

@ -1,4 +1,4 @@
import py, re, os, signal, time import py, re, os, signal, time, commands
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*")
@ -30,26 +30,33 @@ def collect_test_modules(dirpath=None):
class Timeout(Exception): pass class Timeout(Exception): pass
def call_openscad(path, stlpath, timeout=1): def call_openscad(path, stlpath, timeout=1):
try: command = ['openscad', '-s', str(stlpath), str(path)]
command = ['openscad', '-s', str(stlpath), str(path)] print command
print command if timeout:
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: try:
proc.terminate() proc = Popen(command,
proc.kill() stdout=PIPE, stderr=PIPE, close_fds=True)
except OSError: calltime = time.time()
pass 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() return (proc.returncode,) + proc.communicate()
else:
output = commands.getstatusoutput(" ".join(command))
return output + ('', '')
def parse_output(text):
pass

View file

@ -30,10 +30,11 @@ use <%s>
print code print code
f.write(code) f.write(code)
f.flush f.flush
output = call_openscad(path=fpath, stlpath=stlpath, timeout=5) output = call_openscad(path=fpath, stlpath=stlpath, timeout=0)
print output print output
assert output[0] is 0 assert output[0] is 0
assert "warning" or "error" not in output[2].strip().lowercase() for s in ("warning", "error"):
assert s not in output[2].strip().lower()
assert len(stlpath.readlines()) > 2 assert len(stlpath.readlines()) > 2
def test_file_compile(modpath): def test_file_compile(modpath):
@ -41,7 +42,8 @@ def test_file_compile(modpath):
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
assert "warning" or "error" not in output[2].strip().lowercase() for s in ("warning", "error"):
assert s not in output[2].strip().lower()
assert len(stlpath.readlines()) == 2 assert len(stlpath.readlines()) == 2

View file

@ -5,7 +5,7 @@
* Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later * Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later
*/ */
<units.scad> include <units.scad>
function distance(a, b) = sqrt( (a[0] - b[0])*(a[0] - b[0]) + function distance(a, b) = sqrt( (a[0] - b[0])*(a[0] - b[0]) +
(a[1] - b[1])*(a[1] - b[1]) + (a[1] - b[1])*(a[1] - b[1]) +