File: shouldfail.py

package info (click to toggle)
openscad 2021.01-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 35,608 kB
  • sloc: cpp: 53,187; sh: 4,384; ansic: 4,382; python: 1,813; yacc: 853; javascript: 762; lex: 417; lisp: 163; xml: 127; makefile: 114
file content (56 lines) | stat: -rw-r--r-- 1,912 bytes parent folder | download | duplicates (5)
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
54
55
56
#!/usr/bin/python3

# Test expected failure
#
#
# Usage: <script> <inputfile> --openscad=<executable-path> --retval=<retval> [openscad args]
#
#
# This script should return 0 on success, not-0 on error.
#

import sys, os, re, subprocess, argparse

def failquit(*args):
    if len(args)!=0: print(args)
    print('export_import_pngtest args:',str(sys.argv))
    print('exiting export_import_pngtest.py with failure')
    sys.exit(1)

def createImport(inputfile, scadfile):
    print ('createImport: ' + inputfile + " " + scadfile)
    outputdir = os.path.dirname(scadfile)
    try:
        if outputdir and not os.path.exists(outputdir): os.mkdir(outputdir)
        f = open(scadfile,'w')
        f.write('import("'+inputfile+'");'+os.linesep)
        f.close()
    except:
        failquit('failure while opening/writing ' + scadfile + ': ' + str(sys.exc_info()))


#
# Parse arguments
#
parser = argparse.ArgumentParser()
parser.add_argument('--openscad', required=True, help='Specify OpenSCAD executable')
parser.add_argument('--retval', required=True, help='Expected return value')
args,remaining_args = parser.parse_known_args()

inputfile = remaining_args[0]         # Can be .scad file or a file to be imported
remaining_args = remaining_args[1:]    # Passed on to the OpenSCAD executable

if not os.path.exists(inputfile):
    failquit('cant find input file named: ' + inputfile)
if not os.path.exists(args.openscad):
    failquit('cant find openscad executable named: ' + args.openscad)

inputpath, inputfilename = os.path.split(inputfile)
inputbasename,inputsuffix = os.path.splitext(inputfilename)

export_cmd = [args.openscad, inputfile] + remaining_args
print('Running OpenSCAD:')
print(' '.join(export_cmd))
result = subprocess.call(export_cmd)
if str(result) != str(args.retval):
    failquit('OpenSCAD failed with unexpected return value ' + str(result) + ' (should be ' + str(args.retval) + ')')