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 committed Jun 16, 2024
1 parent 80d0d1e commit 1e12e0a
Show file tree
Hide file tree
Showing 2 changed files with 8 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
15 changes: 7 additions & 8 deletions tests/test_func.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 1e12e0a

Please sign in to comment.