diff --git a/.gitignore b/.gitignore index 11f27de..5485bba 100755 --- a/.gitignore +++ b/.gitignore @@ -125,7 +125,7 @@ celerybeat.pid .env .venv env/ -venv/ +venv*/ ENV/ env.bak/ venv.bak/ diff --git a/tests/test_func.py b/tests/test_func.py index cc9c64b..37c0a0a 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +from contextlib import redirect_stdout +import io +import unittest import os -import sys import shutil import unittest from OiRunner import BetterRunner @@ -20,15 +22,12 @@ def tearDown(self): def test_modify_file(self): for i in range(1, 3): - out = sys.stdout with self.assertRaises(SystemExit): - with open("~temp", "w") as f: - sys.stdout = f + with io.StringIO() as buf, redirect_stdout(buf): self.func._modify_file(f"empty{i}.in", "in") - self.assertFalse(os.path.exists("~tmp")) - with open("~temp", "r") as f: - self.assertEqual(f.read(), f"error:empty{i}.in is empty.\n") - sys.stdout = out + self.assertFalse(os.path.exists("~tmp")) + output = buf.getvalue() + self.assertEqual(output, f"error:empty{i}.in is empty.\n") ret_code = self.func._modify_file("a.in", "in") self.assertEqual(ret_code, 3)