1 # Copyright 2014 BitPay, Inc.
2 # Distributed under the MIT/X11 software license, see the accompanying
3 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
10 def bctest(testDir, testObj):
11 execargs = testObj['exec']
15 if "input" in testObj:
16 filename = testDir + "/" + testObj['input']
17 inputData = open(filename).read()
18 stdinCfg = subprocess.PIPE
22 if "output_cmp" in testObj:
23 outputFn = testObj['output_cmp']
24 outputData = open(testDir + "/" + outputFn).read()
26 proc = subprocess.Popen(execargs, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
28 outs = proc.communicate(input=inputData)
30 print("OSError, Failed to execute " + execargs[0])
33 if outputData and (outs[0] != outputData):
34 print("Output data mismatch for " + outputFn)
38 if "return_code" in testObj:
39 wantRC = testObj['return_code']
40 if proc.returncode != wantRC:
41 print("Return code mismatch for " + outputFn)
44 def bctester(testDir, input_basename):
45 input_filename = testDir + "/" + input_basename
46 raw_data = open(input_filename).read()
47 input_data = json.loads(raw_data)
49 for testObj in input_data:
50 bctest(testDir, testObj)