Skip to content

Commit

Permalink
Fix string concatenation to os.path.join and add exception case
Browse files Browse the repository at this point in the history
  • Loading branch information
dongsam committed Dec 9, 2017
1 parent 4ef4dfe commit a3ac767
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/util/bitcoin-util-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def main():

def bctester(testDir, input_basename, buildenv):
""" Loads and parses the input file, runs all tests and reports results"""
input_filename = testDir + "/" + input_basename
input_filename = os.path.join(testDir, input_basename)
raw_data = open(input_filename).read()
input_data = json.loads(raw_data)

Expand Down Expand Up @@ -77,32 +77,36 @@ def bctest(testDir, testObj, buildenv):
are not as expected. Error is caught by bctester() and reported.
"""
# Get the exec names and arguments
execprog = buildenv["BUILDDIR"] + "/src/" + testObj['exec'] + buildenv["EXEEXT"]
execprog = os.path.join(buildenv["BUILDDIR"], "src", testObj["exec"] + buildenv["EXEEXT"])
execargs = testObj['args']
execrun = [execprog] + execargs

# Read the input data (if there is any)
stdinCfg = None
inputData = None
if "input" in testObj:
filename = testDir + "/" + testObj['input']
filename = os.path.join(testDir, testObj["input"])
inputData = open(filename).read()
stdinCfg = subprocess.PIPE

# Read the expected output data (if there is any)
outputFn = None
outputData = None
outputType = None
if "output_cmp" in testObj:
outputFn = testObj['output_cmp']
outputType = os.path.splitext(outputFn)[1][1:] # output type from file extension (determines how to compare)
try:
outputData = open(testDir + "/" + outputFn).read()
outputData = open(os.path.join(testDir, outputFn)).read()
except:
logging.error("Output file " + outputFn + " can not be opened")
raise
if not outputData:
logging.error("Output data missing for " + outputFn)
raise Exception
if not outputType:
logging.error("Output file %s does not have a file extension" % outputFn)
raise Exception

# Run the test
proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
Expand Down

0 comments on commit a3ac767

Please sign in to comment.