Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (38 sloc) 1.23 KB
import sys
import unittest
from cStringIO import StringIO
import boggle
_original_stdout = sys.stdout
_original_stderr = sys.stderr
def run(*args, **kwargs):
expect_exit = kwargs.get("exit", False)
sys.stdout = stdout = StringIO()
sys.stderr = stderr = StringIO()
sys.stdout = _original_stdout
outmsg = stdout.getvalue()
sys.stderr = _original_stderr
errmsg = stderr.getvalue()
except SystemExit:
if expect_exit:
# This failed, as expected
return outmsg, errmsg
# This failed, unexpectedly
raise AssertionError("Exited unexpectedly", outmsg, errmsg)
if expect_exit:
# It was supposed to exit, but didn't.
raise AssertionError("Expected SystemExit", outmsg, errmsg)
return outmsg, errmsg
class TestCommandLine(unittest.TestCase):
def test_board(self):
outmsg, errmsg = run("pyth asdo wern nmkl")
assert "python" in outmsg
class TestBoardLoading(unittest.TestCase):
def test_loadBoard(self):
self.assertEquals( len(boggle.random_board()), 16)
if __name__ == "__main__":
Jump to Line
Something went wrong with that request. Please try again.