MCAD-Library/openscad_testing.py

54 lines
1.6 KiB
Python
Raw Normal View History

import py
2011-09-07 20:52:11 -05:00
import os.path
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 = []
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]
if "modname" in metafunc.funcargnames:
for modname in modnames:
2018-09-23 12:03:17 -05:00
args2.append([fpath, modname])
else:
2018-09-23 12:03:17 -05:00
args1.append(fpath)
2018-09-23 12:03:17 -05:00
if "modname" in metafunc.funcargnames:
metafunc.parametrize(["modpath", "modname"], args2)
else:
metafunc.parametrize("modpath", args1)
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)
f.write(code)
f.flush()
2018-09-23 12:03:17 -05:00
output = call_openscad(path=fpath, stlpath=stlpath, timeout=60)
print(output)
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")
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)
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")
assert len(stlpath.readlines()) == 2