MCAD-Library/test_compile.py

46 lines
1.3 KiB
Python
Raw Normal View History

import py
2010-07-26 09:35:32 -05:00
from openscad_utils import *
temppath = py.test.ensuretemp('MCAD')
2010-07-26 09:35:32 -05:00
def pytest_generate_tests(metafunc):
if "modpath" in metafunc.funcargnames:
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:
metafunc.addcall(funcargs=dict(modpath=fpath))
2010-07-26 09:35:32 -05:00
2010-08-26 06:19:49 -05:00
def test_module_compile(modname, modpath):
tempname = modpath.basename + '-' + modname + '.scad'
fpath = temppath.join(tempname)
stlpath = temppath.join(tempname + ".stl")
f = fpath.open('w')
f.write("""
//generated testfile
2010-08-26 06:19:49 -05:00
use <%s>
%s();
""" % (modpath, modname))
f.flush
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()
assert len(stlpath.readlines()) > 2
2010-08-26 06:19:49 -05:00
def test_file_compile(modpath):
stlpath = temppath.join(modpath.basename + "-test.stl")
output = call_openscad(path=modpath, stlpath=stlpath)
print output
assert output[0] is 0
assert "warning" or "error" not in output[2].strip().lowercase()
assert len(stlpath.readlines()) == 2