Skip to content

Commit a3ac767

Browse files
committed
Fix string concatenation to os.path.join and add exception case
1 parent 4ef4dfe commit a3ac767

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

test/util/bitcoin-util-test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main():
4848

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

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

8484
# Read the input data (if there is any)
8585
stdinCfg = None
8686
inputData = None
8787
if "input" in testObj:
88-
filename = testDir + "/" + testObj['input']
88+
filename = os.path.join(testDir, testObj["input"])
8989
inputData = open(filename).read()
9090
stdinCfg = subprocess.PIPE
9191

9292
# Read the expected output data (if there is any)
9393
outputFn = None
9494
outputData = None
95+
outputType = None
9596
if "output_cmp" in testObj:
9697
outputFn = testObj['output_cmp']
9798
outputType = os.path.splitext(outputFn)[1][1:] # output type from file extension (determines how to compare)
9899
try:
99-
outputData = open(testDir + "/" + outputFn).read()
100+
outputData = open(os.path.join(testDir, outputFn)).read()
100101
except:
101102
logging.error("Output file " + outputFn + " can not be opened")
102103
raise
103104
if not outputData:
104105
logging.error("Output data missing for " + outputFn)
105106
raise Exception
107+
if not outputType:
108+
logging.error("Output file %s does not have a file extension" % outputFn)
109+
raise Exception
106110

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

0 commit comments

Comments
 (0)