22
22
def main ():
23
23
config = configparser .ConfigParser ()
24
24
config .optionxform = str
25
- config .read_file (open (os .path .join (os .path .dirname (__file__ ), "../config.ini" ), encoding = "utf8" ))
25
+ with open (os .path .join (os .path .dirname (__file__ ), "../config.ini" ), encoding = "utf8" ) as f :
26
+ config .read_file (f )
26
27
env_conf = dict (config .items ('environment' ))
27
28
28
29
parser = argparse .ArgumentParser (description = __doc__ )
@@ -43,7 +44,8 @@ def main():
43
44
def bctester (testDir , input_basename , buildenv ):
44
45
""" Loads and parses the input file, runs all tests and reports results"""
45
46
input_filename = os .path .join (testDir , input_basename )
46
- raw_data = open (input_filename , encoding = "utf8" ).read ()
47
+ with open (input_filename , encoding = "utf8" ) as f :
48
+ raw_data = f .read ()
47
49
input_data = json .loads (raw_data )
48
50
49
51
failed_testcases = []
@@ -80,7 +82,8 @@ def bctest(testDir, testObj, buildenv):
80
82
inputData = None
81
83
if "input" in testObj :
82
84
filename = os .path .join (testDir , testObj ["input" ])
83
- inputData = open (filename , encoding = "utf8" ).read ()
85
+ with open (filename , encoding = "utf8" ) as f :
86
+ inputData = f .read ()
84
87
stdinCfg = subprocess .PIPE
85
88
86
89
# Read the expected output data (if there is any)
@@ -91,7 +94,8 @@ def bctest(testDir, testObj, buildenv):
91
94
outputFn = testObj ['output_cmp' ]
92
95
outputType = os .path .splitext (outputFn )[1 ][1 :] # output type from file extension (determines how to compare)
93
96
try :
94
- outputData = open (os .path .join (testDir , outputFn ), encoding = "utf8" ).read ()
97
+ with open (os .path .join (testDir , outputFn ), encoding = "utf8" ) as f :
98
+ outputData = f .read ()
95
99
except :
96
100
logging .error ("Output file " + outputFn + " cannot be opened" )
97
101
raise
0 commit comments