aboutsummaryrefslogtreecommitdiff
path: root/test/util
diff options
context:
space:
mode:
authorbrunoerg <brunoely.gc@gmail.com>2022-04-26 14:39:07 -0300
committerbrunoerg <brunoely.gc@gmail.com>2022-04-27 20:04:33 -0300
commit027aab663aaca32818051d456c3900326377281c (patch)
tree124f38ed34778b6d4c53af634c65017e52e6e862 /test/util
parent269dcad16e3d69f22c7a669c624beeb405111bbe (diff)
downloadbitcoin-027aab663aaca32818051d456c3900326377281c.tar.xz
test, contrib, refactor: use `with` when opening a file
Diffstat (limited to 'test/util')
-rwxr-xr-xtest/util/test_runner.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/test/util/test_runner.py b/test/util/test_runner.py
index a7fc3b1dc1..03db05c563 100755
--- a/test/util/test_runner.py
+++ b/test/util/test_runner.py
@@ -22,7 +22,8 @@ import sys
def main():
config = configparser.ConfigParser()
config.optionxform = str
- config.read_file(open(os.path.join(os.path.dirname(__file__), "../config.ini"), encoding="utf8"))
+ with open(os.path.join(os.path.dirname(__file__), "../config.ini"), encoding="utf8") as f:
+ config.read_file(f)
env_conf = dict(config.items('environment'))
parser = argparse.ArgumentParser(description=__doc__)
@@ -43,7 +44,8 @@ def main():
def bctester(testDir, input_basename, buildenv):
""" Loads and parses the input file, runs all tests and reports results"""
input_filename = os.path.join(testDir, input_basename)
- raw_data = open(input_filename, encoding="utf8").read()
+ with open(input_filename, encoding="utf8") as f:
+ raw_data = f.read()
input_data = json.loads(raw_data)
failed_testcases = []
@@ -80,7 +82,8 @@ def bctest(testDir, testObj, buildenv):
inputData = None
if "input" in testObj:
filename = os.path.join(testDir, testObj["input"])
- inputData = open(filename, encoding="utf8").read()
+ with open(filename, encoding="utf8") as f:
+ inputData = f.read()
stdinCfg = subprocess.PIPE
# Read the expected output data (if there is any)
@@ -91,7 +94,8 @@ def bctest(testDir, testObj, buildenv):
outputFn = testObj['output_cmp']
outputType = os.path.splitext(outputFn)[1][1:] # output type from file extension (determines how to compare)
try:
- outputData = open(os.path.join(testDir, outputFn), encoding="utf8").read()
+ with open(os.path.join(testDir, outputFn), encoding="utf8") as f:
+ outputData = f.read()
except:
logging.error("Output file " + outputFn + " cannot be opened")
raise