File: openscad_testing.py

package info (click to toggle)
openscad 2021.01-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,096 kB
  • sloc: cpp: 53,199; sh: 4,384; ansic: 4,382; python: 1,813; yacc: 853; javascript: 762; lex: 417; lisp: 163; xml: 127; makefile: 118
file content (53 lines) | stat: -rw-r--r-- 1,647 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import py
import os.path
from openscad_utils import *


temppath = py.test.ensuretemp('MCAD')

def pytest_generate_tests(metafunc):
    if "modpath" in metafunc.funcargnames:
        args1 = []
        args2 = []
        for fpath, modnames in collect_test_modules().items():
            basename = os.path.splitext(os.path.split(str(fpath))[1])[0]
            if "modname" in metafunc.funcargnames:
                for modname in modnames:
                    args2.append([fpath, modname])
            else:
                args1.append(fpath)

        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)
    print(code)
    f.write(code)
    f.flush()
    output = call_openscad(path=fpath, stlpath=stlpath, timeout=60)
    print(output)
    assert output[0] is 0
    for s in ("warning", "error"):
        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)
    print(output)
    assert output[0] is 0
    for s in ("warning", "error"):
        assert s not in output[2].strip().lower().decode("utf-8")
    assert len(stlpath.readlines()) == 2