]> Git Repo - VerusCoin.git/blob - src/test/bctest.py
Merge pull request #4969
[VerusCoin.git] / src / test / bctest.py
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.
4
5 import subprocess
6 import os
7 import json
8 import sys
9
10 def bctest(testDir, testObj):
11         execargs = testObj['exec']
12
13         stdinCfg = None
14         inputData = None
15         if "input" in testObj:
16                 filename = testDir + "/" + testObj['input']
17                 inputData = open(filename).read()
18                 stdinCfg = subprocess.PIPE
19
20         outputFn = None
21         outputData = None
22         if "output_cmp" in testObj:
23                 outputFn = testObj['output_cmp']
24                 outputData = open(testDir + "/" + outputFn).read()
25
26         proc = subprocess.Popen(execargs, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
27         try:
28                 outs = proc.communicate(input=inputData)
29         except OSError:
30                 print("OSError, Failed to execute " + execargs[0])
31                 sys.exit(1)
32
33         if outputData and (outs[0] != outputData):
34                 print("Output data mismatch for " + outputFn)
35                 sys.exit(1)
36
37         wantRC = 0
38         if "return_code" in testObj:
39                 wantRC = testObj['return_code']
40         if proc.returncode != wantRC:
41                 print("Return code mismatch for " + outputFn)
42                 sys.exit(1)
43
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)
48
49         for testObj in input_data:
50                 bctest(testDir, testObj)
51
52         sys.exit(0)
53
This page took 0.027447 seconds and 4 git commands to generate.