Skip to content

Commit

Permalink
Change the output checking method in test_func.py. (#18)
Browse files Browse the repository at this point in the history
* Change the output checking method in test_func.py.

Use redirect_stdout method in test_func.py.
Change the `venv/` into `venv*/` in .gitignore.

* Delete a package that is not used in test_func.py
  • Loading branch information
ste1hi authored Jun 15, 2024
1 parent 604d46e commit 2bf649d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ celerybeat.pid
.env
.venv
env/
venv/
venv*/
ENV/
env.bak/
venv.bak/
Expand Down
14 changes: 6 additions & 8 deletions tests/test_func.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from contextlib import redirect_stdout
import io
import unittest
import os
import sys
import shutil
from OiRunner import BetterRunner
from .util import GARBAGE, FILEOUT, FREOPEN, clean
Expand All @@ -19,15 +20,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)
Expand Down

0 comments on commit 2bf649d

Please sign in to comment.