2222def main ():
2323 config = configparser .ConfigParser ()
2424 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 )
2627 env_conf = dict (config .items ('environment' ))
2728
2829 parser = argparse .ArgumentParser (description = __doc__ )
@@ -43,7 +44,8 @@ def main():
4344def bctester (testDir , input_basename , buildenv ):
4445 """ Loads and parses the input file, runs all tests and reports results"""
4546 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 ()
4749 input_data = json .loads (raw_data )
4850
4951 failed_testcases = []
@@ -80,7 +82,8 @@ def bctest(testDir, testObj, buildenv):
8082 inputData = None
8183 if "input" in testObj :
8284 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 ()
8487 stdinCfg = subprocess .PIPE
8588
8689 # Read the expected output data (if there is any)
@@ -91,7 +94,8 @@ def bctest(testDir, testObj, buildenv):
9194 outputFn = testObj ['output_cmp' ]
9295 outputType = os .path .splitext (outputFn )[1 ][1 :] # output type from file extension (determines how to compare)
9396 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 ()
9599 except :
96100 logging .error ("Output file " + outputFn + " cannot be opened" )
97101 raise
0 commit comments