コード例 #1
0
 def test_addpackage_import_bad_pth_file(self):
     # Issue 5258
     pth_dir, pth_fn = self.make_pth("abc\x00def\n")
     with captured_output("stderr") as err_out:
         site.addpackage(pth_dir, pth_fn, set())
     self.assertRegexpMatches(err_out.getvalue(), "line 1")
     self.assertRegexpMatches(err_out.getvalue(), re.escape(os.path.join(pth_dir, pth_fn)))
     # XXX: ditto previous XXX comment.
     self.assertRegexpMatches(err_out.getvalue(), "Traceback")
     self.assertRegexpMatches(err_out.getvalue(), "TypeError")
コード例 #2
0
ファイル: test_warnings.py プロジェクト: rrd257r/Thruster
 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)
コード例 #3
0
ファイル: test_warnings.py プロジェクト: Logotrop/trida
 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)
コード例 #4
0
 def test_addpackage_import_bad_exec(self):
     # Issue 10642
     pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
     with captured_output("stderr") as err_out:
         site.addpackage(pth_dir, pth_fn, set())
     self.assertRegexpMatches(err_out.getvalue(), "line 2")
     self.assertRegexpMatches(err_out.getvalue(), re.escape(os.path.join(pth_dir, pth_fn)))
     # XXX: ditto previous XXX comment.
     self.assertRegexpMatches(err_out.getvalue(), "Traceback")
     self.assertRegexpMatches(err_out.getvalue(), "ImportError")
コード例 #5
0
ファイル: test_site.py プロジェクト: lufengwei2010/AG35
 def test_addpackage_import_bad_pth_file(self):
     # Issue 5258
     pth_dir, pth_fn = self.make_pth("abc\x00def\n")
     with captured_output("stderr") as err_out:
         site.addpackage(pth_dir, pth_fn, set())
     self.assertRegexpMatches(err_out.getvalue(), "line 1")
     self.assertRegexpMatches(err_out.getvalue(),
                              re.escape(os.path.join(pth_dir, pth_fn)))
     # XXX: ditto previous XXX comment.
     self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
     self.assertRegexpMatches(err_out.getvalue(), 'TypeError')
コード例 #6
0
ファイル: test_site.py プロジェクト: lufengwei2010/AG35
 def test_addpackage_import_bad_exec(self):
     # Issue 10642
     pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
     with captured_output("stderr") as err_out:
         site.addpackage(pth_dir, pth_fn, set())
     self.assertRegexpMatches(err_out.getvalue(), "line 2")
     self.assertRegexpMatches(err_out.getvalue(),
                              re.escape(os.path.join(pth_dir, pth_fn)))
     # XXX: ditto previous XXX comment.
     self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
     self.assertRegexpMatches(err_out.getvalue(), 'ImportError')
コード例 #7
0
ファイル: test_warnings.py プロジェクト: BillyboyD/main
 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)
コード例 #8
0
ファイル: test_traceback.py プロジェクト: mozillazg/pypy
 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()',
     ])
コード例 #9
0
 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)
コード例 #10
0
 def test_addpackage_import_bad_syntax(self):
     # Issue 10642
     pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
     with captured_output("stderr") as err_out:
         site.addpackage(pth_dir, pth_fn, set())
     self.assertRegexpMatches(err_out.getvalue(), "line 1")
     self.assertRegexpMatches(err_out.getvalue(), re.escape(os.path.join(pth_dir, pth_fn)))
     # XXX: the previous two should be independent checks so that the
     # order doesn't matter.  The next three could be a single check
     # but my regex foo isn't good enough to write it.
     self.assertRegexpMatches(err_out.getvalue(), "Traceback")
     self.assertRegexpMatches(err_out.getvalue(), r"import bad\)syntax")
     self.assertRegexpMatches(err_out.getvalue(), "SyntaxError")
コード例 #11
0
 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()',
     ])
コード例 #12
0
ファイル: test_site.py プロジェクト: lufengwei2010/AG35
 def test_addpackage_import_bad_syntax(self):
     # Issue 10642
     pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
     with captured_output("stderr") as err_out:
         site.addpackage(pth_dir, pth_fn, set())
     self.assertRegexpMatches(err_out.getvalue(), "line 1")
     self.assertRegexpMatches(err_out.getvalue(),
                              re.escape(os.path.join(pth_dir, pth_fn)))
     # XXX: the previous two should be independent checks so that the
     # order doesn't matter.  The next three could be a single check
     # but my regex foo isn't good enough to write it.
     self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
     self.assertRegexpMatches(err_out.getvalue(), r'import bad\)syntax')
     self.assertRegexpMatches(err_out.getvalue(), 'SyntaxError')
コード例 #13
0
    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
コード例 #14
0
    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
コード例 #15
0
    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
コード例 #16
0
ファイル: test_warnings.py プロジェクト: mlab-upenn/arch-apex
 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)
コード例 #17
0
ファイル: test_thread.py プロジェクト: dr4ke616/custom_python
 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())
コード例 #18
0
 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())
コード例 #19
0
ファイル: test_warnings.py プロジェクト: rrd257r/Thruster
 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)
コード例 #20
0
ファイル: test_warnings.py プロジェクト: Britefury/jython
 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)
コード例 #21
0
    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)
コード例 #22
0
    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")
コード例 #23
0
    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")
コード例 #24
0
ファイル: test_exceptions.py プロジェクト: BillyboyD/main
    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)
コード例 #25
0
ファイル: test_watcher.py プロジェクト: nightshade427/circus
 def test_after_stop_fails(self):
     with captured_output('stdout'):
         self._test_hooks(behavior=ERROR, status='stopped',
                          hook_name='after_stop',
                          call=self._stop)
コード例 #26
0
 def test_after_start_fails(self):
     with captured_output('stderr'):
         yield self._test_hooks(behavior=ERROR,
                                status='stopped',
                                hook_name='after_start')
コード例 #27
0
ファイル: test_watcher.py プロジェクト: victorpoluceno/circus
 def test_after_stop_fails(self):
     with captured_output("stdout"):
         self._test_hooks(behavior=ERROR, status="stopped", hook_name="after_stop", call=self._stop)
コード例 #28
0
ファイル: test_watcher.py プロジェクト: victorpoluceno/circus
 def test_before_spawn_failure(self):
     with captured_output("stdout"):
         self._test_hooks(behavior=ERROR, status="stopped", hook_name="before_spawn", call=self._stop)
コード例 #29
0
ファイル: test_watcher.py プロジェクト: amarandon/circus
 def test_after_start_fails(self):
     with captured_output('stderr'):
         yield self._test_hooks(behavior=ERROR, status='stopped',
                                hook_name='after_start')
コード例 #30
0
            __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"""
コード例 #31
0
ファイル: test_future5.py プロジェクト: Daetalus/pyston
 def test_print_function(self):
     with test_support.captured_output("stderr") as s:
         print("foo", file=sys.stderr)
     self.assertEqual(s.getvalue(), "foo\n")
コード例 #32
0
            __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.assertTrue(e is RuntimeError, e)
            self.assertIn("maximum recursion depth exceeded", str(v))

    def test_new_returns_invalid_instance(self):
        # See issue #11627.
        class MyException(Exception):
            def __new__(cls, *args):
コード例 #33
0
ファイル: test_watcher.py プロジェクト: slok/circus
 def test_after_stop_fails(self):
     with captured_output('stdout'):
         self._test_hooks(behavior=ERROR, status='stopped',
                          hook_name='after_stop',
                          call=self._stop)
コード例 #34
0
 def test_before_spawn_failure(self):
     with captured_output('stdout'):
         self._test_hooks(behavior=ERROR,
                          status='stopped',
                          hook_name='before_spawn',
                          call=self._stop)
コード例 #35
0
ファイル: test_watcher.py プロジェクト: nightshade427/circus
 def test_before_spawn_failure(self):
     with captured_output('stdout'):
         self._test_hooks(behavior=ERROR, status='stopped',
                          hook_name='before_spawn',
                          call=self._stop)
コード例 #36
0
 def test_print_function(self):
     with test_support.captured_output("stderr") as s:
         print("foo", file=sys.stderr)
     self.assertEqual(s.getvalue(), "foo\n")