• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python test_support.captured_output函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test.test_support.captured_output函数的典型用法代码示例。如果您正苦于以下问题:Python captured_output函数的具体用法?Python captured_output怎么用?Python captured_output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了captured_output函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_showwarning_missing

 def test_showwarning_missing(self):
     # Test that showwarning() missing is okay.
     text = 'del showwarning test'
     with original_warnings.catch_warnings(module=self.module):
         self.module.filterwarnings("always", category=UserWarning)
         del self.module.showwarning
         with test_support.captured_output('stderr') as stream:
             self.module.warn(text)
             result = stream.getvalue()
     self.assertIn(text, result)
开发者ID:Logotrop,项目名称:trida,代码行数:10,代码来源:test_warnings.py


示例2: test_showwarning_missing

 def test_showwarning_missing(self):
     if test_support.due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
         return
     # Test that showwarning() missing is okay.
     text = 'del showwarning test'
     with original_warnings.catch_warnings(module=self.module):
         self.module.filterwarnings("always", category=UserWarning)
         del self.module.showwarning
         with test_support.captured_output('stderr') as stream:
             self.module.warn(text)
             result = stream.getvalue()
     self.assertIn(text, result)
开发者ID:BillyboyD,项目名称:main,代码行数:12,代码来源:test_warnings.py


示例3: test_print_stack

 def test_print_stack(self):
     def prn():
         traceback.print_stack()
     with captured_output("stderr") as stderr:
         prn()
     lineno = prn.__code__.co_firstlineno
     file = prn.__code__.co_filename
     self.assertEqual(stderr.getvalue().splitlines()[-4:], [
         '  File "%s", line %d, in test_print_stack' % (file, lineno+3),
         '    prn()',
         '  File "%s", line %d, in prn' % (file, lineno+1),
         '    traceback.print_stack()',
     ])
开发者ID:mozillazg,项目名称:pypy,代码行数:13,代码来源:test_traceback.py


示例4: test_badisinstance

    def test_badisinstance(self):
        # Bug #2542: if issubclass(e, MyException) raises an exception,
        # it should be ignored
        class Meta(type):
            def __subclasscheck__(cls, subclass):
                raise ValueError()

        class MyException(Exception):
            __metaclass__ = Meta
            pass

        with captured_output("stderr") as stderr:
            try:
                raise KeyError()
            except MyException, e:
                self.fail("exception should not be a MyException")
            except KeyError:
                pass
开发者ID:Androtos,项目名称:toolchain_benchmark,代码行数:18,代码来源:test_exceptions.py


示例5: test_badisinstance

    def test_badisinstance(self):
        # Bug #2542: if issubclass(e, MyException) raises an exception,
        # it should be ignored
        class Meta(type):
            def __subclasscheck__(cls, subclass):
                raise ValueError()

        class MyException(Exception):
            __metaclass__ = Meta
            pass

        if due_to_ironpython_bug("http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21116"):
            return
        with captured_output("stderr") as stderr:
            try:
                raise KeyError()
            except MyException, e:
                self.fail("exception should not be a MyException")
            except KeyError:
                pass
开发者ID:BillyboyD,项目名称:main,代码行数:20,代码来源:test_exceptions.py


示例6: test_show_warning_output

 def test_show_warning_output(self):
     # With showarning() missing, make sure that output is okay.
     text = "test show_warning"
     with original_warnings.catch_warnings(module=self.module):
         self.module.filterwarnings("always", category=UserWarning)
         del self.module.showwarning
         with test_support.captured_output("stderr") as stream:
             warning_tests.inner(text)
             result = stream.getvalue()
     self.assertEqual(result.count("\n"), 2, "Too many newlines in %r" % result)
     first_line, second_line = result.split("\n", 1)
     expected_file = os.path.splitext(warning_tests.__file__)[0] + ".py"
     first_line_parts = first_line.rsplit(":", 3)
     path, line, warning_class, message = first_line_parts
     line = int(line)
     self.assertEqual(expected_file, path)
     self.assertEqual(warning_class, " " + UserWarning.__name__)
     self.assertEqual(message, " " + text)
     expected_line = "  " + linecache.getline(path, line).strip() + "\n"
     assert expected_line
     self.assertEqual(second_line, expected_line)
开发者ID:mlab-upenn,项目名称:arch-apex,代码行数:21,代码来源:test_warnings.py


示例7: test_save_exception_state_on_error

 def test_save_exception_state_on_error(self):
     # See issue #14474
     def task():
         started.release()
         raise SyntaxError
     def mywrite(self, *args):
         try:
             raise ValueError
         except ValueError:
             pass
         real_write(self, *args)
     c = thread._count()
     started = thread.allocate_lock()
     with test_support.captured_output("stderr") as stderr:
         real_write = stderr.write
         stderr.write = mywrite
         started.acquire()
         thread.start_new_thread(task, ())
         started.acquire()
         while thread._count() > c:
             time.sleep(0.01)
     self.assertIn("Traceback", stderr.getvalue())
开发者ID:dr4ke616,项目名称:custom_python,代码行数:22,代码来源:test_thread.py


示例8: test_show_warning_output

 def test_show_warning_output(self):
     # With showarning() missing, make sure that output is okay.
     text = 'test show_warning'
     with original_warnings.catch_warnings(module=self.module):
         self.module.filterwarnings("always", category=UserWarning)
         del self.module.showwarning
         with test_support.captured_output('stderr') as stream:
             warning_tests.inner(text)
             result = stream.getvalue()
     self.assertEqual(result.count('\n'), 2,
                          "Too many newlines in %r" % result)
     first_line, second_line = result.split('\n', 1)
     expected_file = warning_tests_py
     first_line_parts = first_line.rsplit(':', 3)
     path, line, warning_class, message = first_line_parts
     line = int(line)
     self.assertEqual(expected_file, path)
     self.assertEqual(warning_class, ' ' + UserWarning.__name__)
     self.assertEqual(message, ' ' + text)
     expected_line = '  ' + linecache.getline(path, line).strip() + '\n'
     assert expected_line
     self.assertEqual(second_line, expected_line)
开发者ID:Britefury,项目名称:jython,代码行数:22,代码来源:test_warnings.py


示例9: testInfiniteRecursion

    def testInfiniteRecursion(self):
        def f():
            return f()
        self.assertRaises(RuntimeError, f)

        def g():
            try:
                return g()
            except ValueError:
                return -1

        # The test prints an unraisable recursion error when
        # doing "except ValueError", this is because subclass
        # checking has recursion checking too.
        with captured_output("stderr"):
            try:
                g()
            except RuntimeError:
                pass
            except:
                self.fail("Should have raised KeyError")
            else:
                self.fail("Should have raised KeyError")
开发者ID:Androtos,项目名称:toolchain_benchmark,代码行数:23,代码来源:test_exceptions.py


示例10: testInfiniteRecursion

    def testInfiniteRecursion(self):
        if is_cli64:
            print "Dev10 Bug 409568"
            return
            
        if is_cli: 
            import sys
            import System
            _cli_saved_limit = sys.getrecursionlimit()
            sys.setrecursionlimit(1001)
            
        def f():
            return f()
        self.assertRaises(RuntimeError, f)

        def g():
            try:
                return g()
            except ValueError:
                return -1

        # The test prints an unraisable recursion error when
        # doing "except ValueError", this is because subclass
        # checking has recursion checking too.
        with captured_output("stderr"):
            try:
                g()
            except RuntimeError:
                pass
            except:
                self.fail("Should have raised KeyError")
            else:
                self.fail("Should have raised KeyError")

        if is_cli:
            import sys
            sys.setrecursionlimit(_cli_saved_limit)
开发者ID:BillyboyD,项目名称:main,代码行数:37,代码来源:test_exceptions.py


示例11: test_after_stop_fails

 def test_after_stop_fails(self):
     with captured_output('stdout'):
         self._test_hooks(behavior=ERROR, status='stopped',
                          hook_name='after_stop',
                          call=self._stop)
开发者ID:nightshade427,项目名称:circus,代码行数:5,代码来源:test_watcher.py


示例12: captured_output

            __metaclass__ = Meta
            pass

        with captured_output("stderr") as stderr:
            try:
                raise KeyError()
            except MyException, e:
                self.fail("exception should not be a MyException")
            except KeyError:
                pass
            except:
                self.fail("Should have raised KeyError")
            else:
                self.fail("Should have raised KeyError")

        with captured_output("stderr") as stderr:
            def g():
                try:
                    return g()
                except RuntimeError:
                    return sys.exc_info()
            e, v, tb = g()
            self.assert_(e is RuntimeError, e)
            self.assert_("maximum recursion depth exceeded" in str(v), v)



# Helper class used by TestSameStrAndUnicodeMsg
class ExcWithOverriddenStr(Exception):
    """Subclass of Exception that accepts a keyword 'msg' arg that is
    returned by __str__. 'msg' won't be included in self.args"""
开发者ID:Androtos,项目名称:toolchain_benchmark,代码行数:31,代码来源:test_exceptions.py


示例13: test_print_function

 def test_print_function(self):
     with test_support.captured_output("stderr") as s:
         print("foo", file=sys.stderr)
     self.assertEqual(s.getvalue(), "foo\n")
开发者ID:Daetalus,项目名称:pyston,代码行数:4,代码来源:test_future5.py


示例14: test_after_start_fails

 def test_after_start_fails(self):
     with captured_output('stderr'):
         yield self._test_hooks(behavior=ERROR, status='stopped',
                                hook_name='after_start')
开发者ID:amarandon,项目名称:circus,代码行数:4,代码来源:test_watcher.py


示例15: test_before_spawn_failure

 def test_before_spawn_failure(self):
     with captured_output("stdout"):
         self._test_hooks(behavior=ERROR, status="stopped", hook_name="before_spawn", call=self._stop)
开发者ID:victorpoluceno,项目名称:circus,代码行数:3,代码来源:test_watcher.py


示例16: test_before_spawn_failure

 def test_before_spawn_failure(self):
     with captured_output('stdout'):
         self._test_hooks(behavior=ERROR, status='stopped',
                          hook_name='before_spawn',
                          call=self._stop)
开发者ID:nightshade427,项目名称:circus,代码行数:5,代码来源:test_watcher.py


示例17: test_after_stop_fails

 def test_after_stop_fails(self):
     with captured_output("stdout"):
         self._test_hooks(behavior=ERROR, status="stopped", hook_name="after_stop", call=self._stop)
开发者ID:victorpoluceno,项目名称:circus,代码行数:3,代码来源:test_watcher.py



注:本文中的test.test_support.captured_output函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_support.captured_stderr函数代码示例发布时间:2022-05-27
下一篇:
Python test_support.bytes函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap