Python test.test_support.captured_stderr() Examples
The following are 23
code examples of test.test_support.captured_stderr().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
test.test_support
, or try the search function
.
Example #1
Source File: test_exceptions_jy.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_unicode_args(self): e = RuntimeError(u"Drink \u2615") # coffee emoji # Can take the repr of any object self.assertEqual(repr(e), "RuntimeError(u'Drink \u2615',)") # Cannot of course turn a non-ascii Unicode object into a str, even if it's an exception object with self.assertRaises(UnicodeEncodeError) as cm: str(e) self.assertEqual( str(cm.exception), "'ascii' codec can't encode character u'\u2615' in position 6: ordinal not in range(128)") # But the exception hook, via Py#displayException, does not fail when attempting to __str__ the exception args with test_support.captured_stderr() as s: sys.excepthook(RuntimeError, u"Drink \u2615", None) # At minimum, it tells us what kind of exception it was self.assertEqual(s.getvalue()[:12], "RuntimeError") # It is fine with ascii values, of course with test_support.captured_stderr() as s: sys.excepthook(RuntimeError, u"Drink java", None) self.assertEqual(s.getvalue(), "RuntimeError: Drink java\n")
Example #2
Source File: test_warnings.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_issue31285(self): # warn_explicit() shouldn't raise a SystemError in case the return # value of get_source() has a bad splitlines() method. class BadLoader: def get_source(self, fullname): class BadSource(str): def splitlines(self): return 42 return BadSource('spam') wmod = self.module with original_warnings.catch_warnings(module=wmod): wmod.filterwarnings('default', category=UserWarning) with test_support.captured_stderr() as stderr: wmod.warn_explicit( 'foo', UserWarning, 'bar', 1, module_globals={'__loader__': BadLoader(), '__name__': 'foobar'}) self.assertIn('UserWarning: foo', stderr.getvalue())
Example #3
Source File: test_tools.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_directory(self): os.mkdir(test_support.TESTFN) self.addCleanup(test_support.rmtree, test_support.TESTFN) c_filename = os.path.join(test_support.TESTFN, "file.c") with open(c_filename, "w") as file: file.write("int xx;\n") with open(os.path.join(test_support.TESTFN, "file.py"), "w") as file: file.write("xx = 'unaltered'\n") script = os.path.join(scriptsdir, "fixcid.py") # ignore dbg() messages with test_support.captured_stderr() as stderr: output = self.run_script(args=(test_support.TESTFN,)) self.assertMultiLineEqual(output, "{}:\n" "1\n" '< int xx;\n' '> int yy;\n'.format(c_filename), "stderr: %s" % stderr.getvalue() )
Example #4
Source File: test_ssl.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_sni_callback_wrong_return_type(self): # Returning the wrong return type terminates the TLS connection # with an internal error alert. server_context, other_context, client_context = self.sni_contexts() def cb_wrong_return_type(ssl_sock, server_name, initial_context): return "foo" server_context.set_servername_callback(cb_wrong_return_type) with self.assertRaises(ssl.SSLError) as cm, \ support.captured_stderr() as stderr: stats = server_params_test(client_context, server_context, chatty=False, sni_name='supermessage') self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_INTERNAL_ERROR') self.assertIn("TypeError", stderr.getvalue())
Example #5
Source File: test_ssl.py From oss-ftp with MIT License | 6 votes |
def test_sni_callback_wrong_return_type(self): # Returning the wrong return type terminates the TLS connection # with an internal error alert. server_context, other_context, client_context = self.sni_contexts() def cb_wrong_return_type(ssl_sock, server_name, initial_context): return "foo" server_context.set_servername_callback(cb_wrong_return_type) with self.assertRaises(ssl.SSLError) as cm, \ support.captured_stderr() as stderr: stats = server_params_test(client_context, server_context, chatty=False, sni_name='supermessage') self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_INTERNAL_ERROR') self.assertIn("TypeError", stderr.getvalue())
Example #6
Source File: test_exceptions_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_unicode_args(self): e = RuntimeError(u"Drink \u2615") # coffee emoji # Can take the repr of any object self.assertEqual(repr(e), "RuntimeError(u'Drink \u2615',)") # Cannot of course turn a non-ascii Unicode object into a str, even if it's an exception object with self.assertRaises(UnicodeEncodeError) as cm: str(e) self.assertEqual( str(cm.exception), "'ascii' codec can't encode character u'\u2615' in position 6: ordinal not in range(128)") # But the exception hook, via Py#displayException, does not fail when attempting to __str__ the exception args with test_support.captured_stderr() as s: sys.excepthook(RuntimeError, u"Drink \u2615", None) # At minimum, it tells us what kind of exception it was self.assertEqual(s.getvalue()[:12], "RuntimeError") # It is fine with ascii values, of course with test_support.captured_stderr() as s: sys.excepthook(RuntimeError, u"Drink java", None) self.assertEqual(s.getvalue(), "RuntimeError: Drink java\n")
Example #7
Source File: test_ssl.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_sni_callback_wrong_return_type(self): # Returning the wrong return type terminates the TLS connection # with an internal error alert. server_context, other_context, client_context = self.sni_contexts() def cb_wrong_return_type(ssl_sock, server_name, initial_context): return "foo" server_context.set_servername_callback(cb_wrong_return_type) with self.assertRaises(ssl.SSLError) as cm, \ support.captured_stderr() as stderr: stats = server_params_test(client_context, server_context, chatty=False, sni_name='supermessage') self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_INTERNAL_ERROR') self.assertIn("TypeError", stderr.getvalue())
Example #8
Source File: test_warning.py From oss-ftp with MIT License | 5 votes |
def test_shell_show(self): with captured_stderr() as f: shell.idle_showwarning( 'Test', UserWarning, 'test_warning.py', 99, f, 'Line of code') self.assertEqual(shellmsg.splitlines(), f.getvalue().splitlines())
Example #9
Source File: test_ssl.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_sni_callback_raising(self): # Raising fails the connection with a TLS handshake failure alert. server_context, other_context, client_context = self.sni_contexts() def cb_raising(ssl_sock, server_name, initial_context): 1.0/0.0 server_context.set_servername_callback(cb_raising) with self.assertRaises(ssl.SSLError) as cm, \ support.captured_stderr() as stderr: stats = server_params_test(client_context, server_context, chatty=False, sni_name='supermessage') self.assertEqual(cm.exception.reason, 'SSLV3_ALERT_HANDSHAKE_FAILURE') self.assertIn("ZeroDivisionError", stderr.getvalue())
Example #10
Source File: test_warning.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_shell_show(self): with captured_stderr() as f: shell.idle_showwarning( 'Test', UserWarning, 'test_warning.py', 99, f, 'Line of code') self.assertEqual(shellmsg.splitlines(), f.getvalue().splitlines())
Example #11
Source File: test_warning.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_run_show(self): with captured_stderr() as f: run.idle_showwarning_subproc( 'Test', UserWarning, 'test_warning.py', 99, f, 'Line of code') # The following uses .splitlines to erase line-ending differences self.assertEqual(idlemsg.splitlines(), f.getvalue().splitlines())
Example #12
Source File: test_ssl.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_sni_callback_raising(self): # Raising fails the connection with a TLS handshake failure alert. server_context, other_context, client_context = self.sni_contexts() def cb_raising(ssl_sock, server_name, initial_context): 1.0/0.0 server_context.set_servername_callback(cb_raising) with self.assertRaises(ssl.SSLError) as cm, \ support.captured_stderr() as stderr: stats = server_params_test(client_context, server_context, chatty=False, sni_name='supermessage') self.assertEqual(cm.exception.reason, 'SSLV3_ALERT_HANDSHAKE_FAILURE') self.assertIn("ZeroDivisionError", stderr.getvalue())
Example #13
Source File: test_warning.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def test_shell_show(self): with captured_stderr() as f: shell.idle_showwarning( 'Test', UserWarning, 'test_warning.py', 99, f, 'Line of code') self.assertEqual(shellmsg.splitlines(), f.getvalue().splitlines())
Example #14
Source File: test_warning.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def test_run_show(self): with captured_stderr() as f: run.idle_showwarning_subproc( 'Test', UserWarning, 'test_warning.py', 99, f, 'Line of code') # The following uses .splitlines to erase line-ending differences self.assertEqual(idlemsg.splitlines(), f.getvalue().splitlines())
Example #15
Source File: test_subprocess.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_invalid_args(self): # Popen() called with invalid arguments should raise TypeError # but Popen.__del__ should not complain (issue #12085) with test_support.captured_stderr() as s: self.assertRaises(TypeError, subprocess.Popen, invalid_arg_name=1) argcount = subprocess.Popen.__init__.__code__.co_argcount too_many_args = [0] * (argcount + 1) self.assertRaises(TypeError, subprocess.Popen, *too_many_args) self.assertEqual(s.getvalue(), '')
Example #16
Source File: test_timeit.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_main_exception(self): with captured_stderr() as error_stringio: s = self.run_main(switches=['1.0/0.0']) self.assert_exc_string(error_stringio.getvalue(), 'ZeroDivisionError')
Example #17
Source File: test_warning.py From oss-ftp with MIT License | 5 votes |
def test_run_show(self): with captured_stderr() as f: run.idle_showwarning_subproc( 'Test', UserWarning, 'test_warning.py', 99, f, 'Line of code') # The following uses .splitlines to erase line-ending differences self.assertEqual(idlemsg.splitlines(), f.getvalue().splitlines())
Example #18
Source File: test_subprocess.py From oss-ftp with MIT License | 5 votes |
def test_invalid_args(self): # Popen() called with invalid arguments should raise TypeError # but Popen.__del__ should not complain (issue #12085) with test_support.captured_stderr() as s: self.assertRaises(TypeError, subprocess.Popen, invalid_arg_name=1) argcount = subprocess.Popen.__init__.__code__.co_argcount too_many_args = [0] * (argcount + 1) self.assertRaises(TypeError, subprocess.Popen, *too_many_args) self.assertEqual(s.getvalue(), '')
Example #19
Source File: test_ssl.py From oss-ftp with MIT License | 5 votes |
def test_sni_callback_raising(self): # Raising fails the connection with a TLS handshake failure alert. server_context, other_context, client_context = self.sni_contexts() def cb_raising(ssl_sock, server_name, initial_context): 1/0 server_context.set_servername_callback(cb_raising) with self.assertRaises(ssl.SSLError) as cm, \ support.captured_stderr() as stderr: stats = server_params_test(client_context, server_context, chatty=False, sni_name='supermessage') self.assertEqual(cm.exception.reason, 'SSLV3_ALERT_HANDSHAKE_FAILURE') self.assertIn("ZeroDivisionError", stderr.getvalue())
Example #20
Source File: test_subprocess.py From BinderFilter with MIT License | 5 votes |
def test_invalid_args(self): # Popen() called with invalid arguments should raise TypeError # but Popen.__del__ should not complain (issue #12085) with test_support.captured_stderr() as s: self.assertRaises(TypeError, subprocess.Popen, invalid_arg_name=1) argcount = subprocess.Popen.__init__.__code__.co_argcount too_many_args = [0] * (argcount + 1) self.assertRaises(TypeError, subprocess.Popen, *too_many_args) self.assertEqual(s.getvalue(), '')
Example #21
Source File: test_subprocess.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_invalid_args(self): # Popen() called with invalid arguments should raise TypeError # but Popen.__del__ should not complain (issue #12085) with test_support.captured_stderr() as s: self.assertRaises(TypeError, subprocess.Popen, invalid_arg_name=1) argcount = subprocess.Popen.__init__.__code__.co_argcount too_many_args = [0] * (argcount + 1) self.assertRaises(TypeError, subprocess.Popen, *too_many_args) self.assertEqual(s.getvalue(), '')
Example #22
Source File: test_ssl.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_sni_callback_raising(self): # Raising fails the connection with a TLS handshake failure alert. server_context, other_context, client_context = self.sni_contexts() def cb_raising(ssl_sock, server_name, initial_context): 1.0/0.0 server_context.set_servername_callback(cb_raising) with self.assertRaises(ssl.SSLError) as cm, \ support.captured_stderr() as stderr: stats = server_params_test(client_context, server_context, chatty=False, sni_name='supermessage') self.assertEqual(cm.exception.reason, 'SSLV3_ALERT_HANDSHAKE_FAILURE') self.assertIn("ZeroDivisionError", stderr.getvalue())
Example #23
Source File: test_timeit.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_main_exception_fixed_reps(self): with captured_stderr() as error_stringio: s = self.run_main(switches=['-n1', '1.0/0.0']) self.assert_exc_string(error_stringio.getvalue(), 'ZeroDivisionError')