2010-10-13 01:25:21 -05:00
|
|
|
import py
|
2011-09-07 20:52:11 -05:00
|
|
|
import os.path
|
2010-10-13 01:25:21 -05:00
|
|
|
from openscad_utils import *
|
|
|
|
|
|
|
|
|
|
|
|
temppath = py.test.ensuretemp('MCAD')
|
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if "modpath" in metafunc.funcargnames:
|
2018-09-23 12:03:17 -05:00
|
|
|
args1 = []
|
|
|
|
args2 = []
|
2010-10-13 01:25:21 -05:00
|
|
|
for fpath, modnames in collect_test_modules().items():
|
2011-09-07 20:52:11 -05:00
|
|
|
basename = os.path.splitext(os.path.split(str(fpath))[1])[0]
|
2010-10-13 01:25:21 -05:00
|
|
|
if "modname" in metafunc.funcargnames:
|
|
|
|
for modname in modnames:
|
2018-09-23 12:03:17 -05:00
|
|
|
args2.append([fpath, modname])
|
2010-10-13 01:25:21 -05:00
|
|
|
else:
|
2018-09-23 12:03:17 -05:00
|
|
|
args1.append(fpath)
|
2010-10-13 01:25:21 -05:00
|
|
|
|
2018-09-23 12:03:17 -05:00
|
|
|
if "modname" in metafunc.funcargnames:
|
|
|
|
metafunc.parametrize(["modpath", "modname"], args2)
|
|
|
|
else:
|
|
|
|
metafunc.parametrize("modpath", args1)
|
2010-10-13 01:25:21 -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')
|
|
|
|
code = """
|
|
|
|
//generated testfile
|
|
|
|
use <%s>
|
|
|
|
|
|
|
|
%s();
|
|
|
|
""" % (modpath, modname)
|
2018-09-23 12:03:17 -05:00
|
|
|
print(code)
|
2010-10-13 01:25:21 -05:00
|
|
|
f.write(code)
|
|
|
|
f.flush()
|
2018-09-23 12:03:17 -05:00
|
|
|
output = call_openscad(path=fpath, stlpath=stlpath, timeout=60)
|
|
|
|
print(output)
|
2010-10-13 01:25:21 -05:00
|
|
|
assert output[0] is 0
|
|
|
|
for s in ("warning", "error"):
|
2018-09-23 12:03:17 -05:00
|
|
|
assert s not in output[2].strip().lower().decode("utf-8")
|
2010-10-13 01:25:21 -05:00
|
|
|
assert len(stlpath.readlines()) > 2
|
|
|
|
|
|
|
|
def test_file_compile(modpath):
|
|
|
|
stlpath = temppath.join(modpath.basename + "-test.stl")
|
|
|
|
output = call_openscad(path=modpath, stlpath=stlpath)
|
2018-09-23 12:03:17 -05:00
|
|
|
print(output)
|
2010-10-13 01:25:21 -05:00
|
|
|
assert output[0] is 0
|
|
|
|
for s in ("warning", "error"):
|
2018-09-23 12:03:17 -05:00
|
|
|
assert s not in output[2].strip().lower().decode("utf-8")
|
2010-10-13 01:25:21 -05:00
|
|
|
assert len(stlpath.readlines()) == 2
|