Re: SVN: Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py Suppress expected DeprecationWarning output in test.
Isn't a try: ... finally: ... needed here? Florent Tres Seaver wrote:
Log message for revision 40329: Suppress expected DeprecationWarning output in test.
Changed: U Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py
-=- Modified: Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py =================================================================== --- Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py 2005-11-22 18:18:17 UTC (rev 40328) +++ Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py 2005-11-22 18:18:36 UTC (rev 40329) @@ -25,6 +25,30 @@ if not here: here = os.getcwd()
+class WarningInterceptor: + + _old_stderr = None + _our_stderr_stream = None + + def _trap_warning_output( self ): + + if self._old_stderr is not None: + return + + import sys + from StringIO import StringIO + + self._old_stderr = sys.stderr + self._our_stderr_stream = sys.stderr = StringIO() + + def _free_warning_output( self ): + + if self._old_stderr is None: + return + + import sys + sys.stderr = self._old_stderr + # Test Classes
def readf(name): @@ -219,7 +243,7 @@ f = self._newPS(defn + "\n" + asn % name) self.assertRaises(TypeError, f)
-class TestPythonScriptGlobals(PythonScriptTestBase): +class TestPythonScriptGlobals(PythonScriptTestBase, WarningInterceptor): def _exec(self, script, bound_names=None, args=None, kws=None): if args is None: args = () @@ -241,8 +265,10 @@ def test_filepath(self): # This test is meant to raise a deprecation warning. # It used to fail mysteriously instead. + self._trap_warning_output() f = self._filePS('filepath') self.assertEqual(f(), [0]) + self._free_warning_output()
def test_suite(): suite = unittest.TestSuite()
_______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
-- Florent Guillaume, Nuxeo (Paris, France) Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Florent Guillaume wrote:
Isn't a try: ... finally: ... needed here?
Yup. Or else call '_free_warning_output' call in 'tearDown' (which I jsut checked in). Thanks for the catch! Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDg9G6+gerLs4ltQ4RAjEVAJ9LzGnjbzl8/J1INaA0oyu8LskSqACg3Iui 5RDdLqjmJ8NMJ1zzs/Ug77Q= =DVyQ -----END PGP SIGNATURE-----
participants (2)
-
Florent Guillaume -
Tres Seaver