summaryrefslogtreecommitdiff
path: root/tests/test_cmdline_tool.py
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-03-11 20:12:35 (GMT)
committerMarius Kintel <marius@kintel.net>2013-03-11 20:12:35 (GMT)
commitbe645d8a543ac08838c769e60a914f5a201ebb1b (patch)
treeeb8e7c864be8a36bf44f88862da0082e6e9f2872 /tests/test_cmdline_tool.py
parenta1308a6a5ea36ff51a1d96264cc2bc2cd8618831 (diff)
Small generalization of cmd-line test driver. Added tests for image output and camera settings for the OpenSCAD app
Diffstat (limited to 'tests/test_cmdline_tool.py')
-rwxr-xr-xtests/test_cmdline_tool.py50
1 files changed, 33 insertions, 17 deletions
diff --git a/tests/test_cmdline_tool.py b/tests/test_cmdline_tool.py
index 81a7795..eb01abd 100755
--- a/tests/test_cmdline_tool.py
+++ b/tests/test_cmdline_tool.py
@@ -32,17 +32,28 @@ def initialize_environment():
if not options.generate: options.generate = bool(os.getenv("TEST_GENERATE"))
return True
-def init_expected_filename(testname, cmd):
+def init_expected_filename():
global expecteddir, expectedfilename
+
+ expected_testname = options.testname
+
if hasattr(options, "expecteddir"):
- expected_basename = options.expecteddir
+ expected_dirname = options.expecteddir
else:
- expected_basename = os.path.split(cmd)[1]
+ expected_dirname = expected_testname
- expecteddir = os.path.join(options.regressiondir, expected_basename)
- expectedfilename = os.path.join(expecteddir, testname + "-expected." + options.suffix)
+ expecteddir = os.path.join(options.regressiondir, expected_dirname)
+ expectedfilename = os.path.join(expecteddir, options.filename + "-expected." + options.suffix)
expectedfilename = os.path.normpath(expectedfilename)
+def init_actual_filename():
+ global actualdir, actualfilename
+
+ cmdname = os.path.split(options.cmd)[1]
+ actualdir = os.path.join(os.getcwd(), options.testname + "-output")
+ actualfilename = os.path.join(actualdir, options.filename + "-actual." + options.suffix)
+ actualfilename = os.path.normpath(actualfilename)
+
def verify_test(testname, cmd):
global expectedfilename
if not options.generate:
@@ -133,17 +144,13 @@ def compare_with_expected(resultfilename):
def run_test(testname, cmd, args):
cmdname = os.path.split(options.cmd)[1]
- outputdir = os.path.join(os.getcwd(), cmdname + "-output")
- actualfilename = os.path.join(outputdir, testname + "-actual." + options.suffix)
- actualfilename = os.path.normpath(actualfilename)
-
if options.generate:
if not os.path.exists(expecteddir): os.makedirs(expecteddir)
outputname = expectedfilename
else:
- if not os.path.exists(outputdir): os.makedirs(outputdir)
+ if not os.path.exists(actualdir): os.makedirs(actualdir)
outputname = actualfilename
- outputname = os.path.normpath( outputname )
+ outputname = os.path.normpath(outputname)
outfile = open(outputname, "wb")
@@ -154,6 +161,7 @@ def run_test(testname, cmd, args):
cmdline = ['wine']+[cmd] + args + [outputname]
else:
cmdline = [cmd] + args + [outputname]
+ print cmdline
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errtext = proc.communicate()[1]
if errtext != None and len(errtext) > 0:
@@ -182,14 +190,15 @@ def usage():
print >> sys.stderr, " -g, --generate Generate expected output for the given tests"
print >> sys.stderr, " -s, --suffix=<suffix> Write -expected and -actual files with the given suffix instead of .txt"
print >> sys.stderr, " -e, --expected-dir=<dir> Use -expected files from the given dir (to share files between test drivers)"
- print >> sys.stderr, " -t, --test=<name> Specify test name instead of deducting it from the argument"
+ print >> sys.stderr, " -t, --test=<name> Specify test name instead of deducting it from the argument (defaults to basename <exe>)"
+ print >> sys.stderr, " -f, --file=<name> Specify test file instead of deducting it from the argument (default to basename <first arg>)"
print >> sys.stderr, " -c, --convexec=<name> Path to ImageMagick 'convert' executable"
print >> sys.stderr, " -x, --mingw-cross-env Mingw-cross-env cross compilation"
if __name__ == '__main__':
# Handle command-line arguments
try:
- opts, args = getopt.getopt(sys.argv[1:], "gs:e:c:t:m:x", ["generate", "convexec=", "suffix=", "expected_dir=", "test=", "comparator=", "mingw-cross-env"])
+ opts, args = getopt.getopt(sys.argv[1:], "gs:e:c:t:f:m:x", ["generate", "convexec=", "suffix=", "expected_dir=", "test=", "file=", "comparator=", "mingw-cross-env"])
except getopt.GetoptError, err:
usage()
sys.exit(2)
@@ -199,6 +208,7 @@ if __name__ == '__main__':
options.regressiondir = os.path.join(os.path.split(sys.argv[0])[0], "regression")
options.generate = False
options.suffix = "txt"
+ options.comparator = ""
for o, a in opts:
if o in ("-g", "--generate"): options.generate = True
@@ -209,6 +219,8 @@ if __name__ == '__main__':
options.expecteddir = a
elif o in ("-t", "--test"):
options.testname = a
+ elif o in ("-f", "--file"):
+ options.filename = a
elif o in ("-c", "--convexec"):
options.convert_exec = os.path.normpath( a )
elif o in ("-m", "--comparator"):
@@ -225,16 +237,20 @@ if __name__ == '__main__':
# If only one test file, we can usually deduct the test name from the file
if len(args) == 2:
basename = os.path.splitext(args[1])[0]
- path, options.testname = os.path.split(basename)
+ path, options.filename = os.path.split(basename)
- if not hasattr(options, "testname"):
- print >> sys.stderr, "Test name cannot be deducted from arguments. Specify test name using the -t option"
+ if not hasattr(options, "filename"):
+ print >> sys.stderr, "Filename cannot be deducted from arguments. Specify test filename using the -f option"
sys.exit(2)
+ if not hasattr(options, "testname"):
+ options.testname = os.path.split(args[0])[1]
+
# Initialize and verify run-time environment
if not initialize_environment(): sys.exit(1)
- init_expected_filename(options.testname, options.cmd)
+ init_expected_filename()
+ init_actual_filename()
# Verify test environment
verification = verify_test(options.testname, options.cmd)
contact: Jan Huwald // Impressum