upgrade to python3

This commit is contained in:
2026-02-08 11:23:34 +08:00
parent 487c041148
commit 9b20887cc2
9 changed files with 139 additions and 195 deletions

View File

@@ -298,8 +298,9 @@ class SimpleTester(TesterBase):
shutil.copyfile(os.path.join(rundir, submit_output_filename),
outfile)
except IOError:
f = file(outfile, 'w')
f.close()
with open(outfile, 'w') as f:
f.write('')
ret = [testcase.id, exitcode, sig, outfile, errfile, timeused, memused]
if timeused > testcase.timelimit:
@@ -484,21 +485,19 @@ class SimpleTesterTestCase(OJTestCase):
self.assertEqual(r[1], 'AC')
self.assertEqual(r[2], 0)
self.assertEqual(r[3], 0)
f = file(r[4], 'r')
o = string.join(f.readlines(), '\n')
f.close()
with open(r[4], 'rb') as f:
o = f.read().decode('latin1')
self.assertEqual(o, '3\n')
f = file(r[5], 'r')
o = string.join(f.readlines(), '\n')
f.close()
with open(r[5], 'rb') as f:
o = f.read().decode('latin1')
self.assertEqual(o, '')
r = self.st.run(submit, testcases[1])
f = file(r[4], 'r')
o = string.join(f.readlines(), '\n')
f.close()
with open(r[4], 'rb') as f:
o = f.read().decode('latin1')
self.assertEqual(o, '4\n')
self.st.cleanup(submit)
self.assertFalse(not self.config.no_cleanup and os.path.exists(datadir))
@@ -621,11 +620,11 @@ class SimpleTesterTestCase(OJTestCase):
self.assertTrue(r)
testcases = submit.get_testcases()
r = self.st.run(submit, testcases[0])
f = file(os.path.join(datadir, '0000000001.out'))
o = string.join(f.readlines(), '\n')
f.close()
with open(os.path.join(datadir, '0000000001.out'), 'rb') as f:
o = f.read().decode('latin1')
self.assertEqual(o, '3\0\n')
self.st.cleanup(submit)
self.assertFalse(not self.config.no_cleanup and os.path.exists(datadir))
@@ -640,11 +639,11 @@ class SimpleTesterTestCase(OJTestCase):
self.assertTrue(r)
testcases = submit.get_testcases()
r = self.st.run(submit, testcases[0])
f = file(os.path.join(datadir, '0000000001.out'))
o = string.join(f.readlines(), '\n')
f.close()
with open(os.path.join(datadir, '0000000001.out'), 'rb') as f:
o = f.read().decode('latin1')
self.assertEqual(o, '\xbb')
self.st.cleanup(submit)
self.assertFalse(not self.config.no_cleanup and os.path.exists(datadir))