Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: tests/super_mox.py

Issue 3473003: Add automated sys.stdout check. (Closed)
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/gclient_utils_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/super_mox.py
diff --git a/tests/super_mox.py b/tests/super_mox.py
index b8047cd26c4524244991ef24f4c5ceab203ce016..2620f8f5752deb81ddeaffbee532c376771c53cf 100644
--- a/tests/super_mox.py
+++ b/tests/super_mox.py
@@ -10,6 +10,7 @@ import os
import random
import shutil
import string
+import StringIO
import subprocess
import sys
@@ -86,7 +87,28 @@ class TestCaseUtils(object):
pass
-class SuperMoxTestBase(TestCaseUtils, mox.MoxTestBase):
+class StdoutCheck(object):
+ def setUp(self):
+ # Override the mock with a StringIO, it's much less painful to test.
+ self._old_stdout = sys.stdout
+ sys.stdout = StringIO.StringIO()
+ sys.stdout.flush = lambda: None
+
+ def tearDown(self):
+ try:
+ # If sys.stdout was used, self.checkstdout() must be called.
+ self.assertEquals('', sys.stdout.getvalue())
+ except AttributeError:
+ pass
+ sys.stdout = self._old_stdout
+
+ def checkstdout(self, expected):
+ value = sys.stdout.getvalue()
+ sys.stdout.close()
+ self.assertEquals(expected, value)
+
+
+class SuperMoxTestBase(TestCaseUtils, StdoutCheck, mox.MoxTestBase):
def setUp(self):
"""Patch a few functions with know side-effects."""
TestCaseUtils.setUp(self)
@@ -104,9 +126,11 @@ class SuperMoxTestBase(TestCaseUtils, mox.MoxTestBase):
self.MockList(shutil, ('rmtree'))
self.MockList(subprocess, ('call', 'Popen'))
# Don't mock stderr since it confuses unittests.
- self.MockList(sys, ('stdin', 'stdout'))
+ self.MockList(sys, ('stdin'))
+ StdoutCheck.setUp(self)
def tearDown(self):
+ StdoutCheck.tearDown(self)
TestCaseUtils.tearDown(self)
mox.MoxTestBase.tearDown(self)
« no previous file with comments | « tests/gclient_utils_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698