当前位置: 首页>>代码示例>>Python>>正文


Python pdb.py方法代码示例

本文整理汇总了Python中pdb.py方法的典型用法代码示例。如果您正苦于以下问题:Python pdb.py方法的具体用法?Python pdb.py怎么用?Python pdb.py使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pdb的用法示例。


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

示例1: _disable_pytest_capture_maybe

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def _disable_pytest_capture_maybe(self):
        try:
            import py.test
            # Force raising of ImportError if pytest is not installed.
            py.test.config
        except (ImportError, AttributeError):
            return
        try:
            capman = py.test.config.pluginmanager.getplugin('capturemanager')
            capman.suspendcapture()
        except KeyError:
            pass
        except AttributeError:
            # Newer pytest with support ready, or very old py.test for which
            # this hack does not work.
            pass 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:18,代码来源:pdbpp.py

示例2: do_edit

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def do_edit(self, arg):
        "Open an editor visiting the current file at the current line"
        if arg == '':
            filename, lineno = self._get_current_position()
        else:
            filename, lineno, _ = self._get_position_of_arg(arg)
            if filename is None:
                return
        # this case handles code generated with py.code.Source()
        # filename is something like '<0-codegen foo.py:18>'
        match = re.match(r'.*<\d+-codegen (.*):(\d+)>', filename)
        if match:
            filename = match.group(1)
            lineno = int(match.group(2))

        try:
            self._open_editor(self._get_editor_cmd(filename, lineno))
        except Exception as exc:
            self.error(exc) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:21,代码来源:pdbpp.py

示例3: test_py_code_source

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_py_code_source():  # noqa: F821
    src = py.code.Source("""
    def fn():
        x = 42
        set_trace()
        return x
    """)

    exec(src.compile(), globals())
    check(fn,  # noqa: F821
          """
[NUM] > .*fn()
-> return x
   5 frames hidden .*
# ll
NUM     def fn():
NUM         x = 42
NUM         set_trace()
NUM  ->     return x
# c
""") 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:23,代码来源:test_pdb.py

示例4: test_edit_py_code_source

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_edit_py_code_source():
    src = py.code.Source("""
    def bar():
        set_trace()
        return 42
    """)
    _, base_lineno = inspect.getsourcelines(test_edit_py_code_source)
    dic = {'set_trace': set_trace}
    exec(src.compile(), dic)  # 8th line from the beginning of the function
    bar = dic['bar']
    src_compile_lineno = base_lineno + 8

    check(bar, r"""
[NUM] > .*bar()
-> return 42
   5 frames hidden .*
# edit bar
RUN emacs \+%d %s
# c
""" % (src_compile_lineno, RE_THIS_FILE_CANONICAL_QUOTED)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:22,代码来源:test_pdb.py

示例5: test_do_bt_highlight

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_do_bt_highlight():
    def fn():
        set_trace(Config=ConfigWithHighlight)

    expected_bt = []
    for i, entry in enumerate(traceback.extract_stack()[:-3]):
        expected_bt.append("  [%2d] .*" % i)
        expected_bt.append("  .*")

    check(fn, r"""
--Return--
[NUM] > .*fn()->None
-> set_trace(Config=ConfigWithHighlight)
   5 frames hidden .*
# bt
{expected}
  [NUM] ^[[33;01m.*\.py^[[00m(^[[36;01mNUM^[[00m)runpdb()
       func()
> [NUM] ^[[33;01m.*\.py^[[00m(^[[36;01mNUM^[[00m)fn()->None
       set_trace(Config=ConfigWithHighlight)
# c
""".format(expected="\n".join(expected_bt))) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:24,代码来源:test_pdb.py

示例6: test_do_bt_pygments

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_do_bt_pygments():
    def fn():
        set_trace(Config=ConfigWithPygments)

    expected_bt = []
    for i, entry in enumerate(traceback.extract_stack()[:-3]):
        expected_bt.append("  [%2d] .*" % i)
        expected_bt.append("  .*")

    check(fn, r"""
--Return--
[NUM] > .*fn()->None
-> set_trace(Config^[[38;5;241m=^[[39mConfigWithPygments)
   5 frames hidden .*
# bt
{expected}
  [NUM] .*(NUM)runpdb()
       func()
> [NUM] .*\.py(NUM)fn()->None
       set_trace(Config^[[38;5;241m=^[[39mConfigWithPygments)
# c
""".format(expected="\n".join(expected_bt))) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:24,代码来源:test_pdb.py

示例7: test_exception_info_main

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_exception_info_main(testdir):
    """Test that interaction adds __exception__ similar to user_exception."""
    p1 = testdir.makepyfile(
        """
        def f():
            raise ValueError("foo")

        f()
        """
    )
    testdir.monkeypatch.setenv("PDBPP_COLORS", "0")
    result = testdir.run(
        sys.executable, "-m", "pdb", str(p1),
        stdin=b"cont\nsticky\n",
    )
    result.stdout.fnmatch_lines(
        [
            '*Uncaught exception. Entering post mortem debugging',
            "*[[]5[]] > *test_exception_info_main.py(2)f()",
            "",
            "1     def f():",
            '2  ->     raise ValueError("foo")',
            "ValueError: foo",
        ]
    ) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:27,代码来源:test_pdb.py

示例8: lookupmodule

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def lookupmodule(self, filename):
        """Helper function for break/clear parsing -- may be overridden.

        lookupmodule() translates (possibly incomplete) file or module name
        into an absolute file name.
        """
        if os.path.isabs(filename) and  os.path.exists(filename):
            return filename
        f = os.path.join(sys.path[0], filename)
        if  os.path.exists(f) and self.canonic(f) == self.mainpyfile:
            return f
        root, ext = os.path.splitext(filename)
        if ext == '':
            filename = filename + '.py'
        if os.path.isabs(filename):
            return filename
        for dirname in sys.path:
            while os.path.islink(dirname):
                dirname = os.readlink(dirname)
            fullname = os.path.join(dirname, filename)
            if os.path.exists(fullname):
                return fullname
        return None 
开发者ID:glmcdona,项目名称:meddle,代码行数:25,代码来源:pdb.py

示例9: test_early_hook_error_issue38_1

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_early_hook_error_issue38_1(self, testdir):
        testdir.makeconftest(
            """
            def pytest_sessionstart():
                0 / 0
        """
        )
        result = testdir.runpytest(testdir.tmpdir)
        assert result.ret != 0
        # tracestyle is native by default for hook failures
        result.stdout.fnmatch_lines(
            ["*INTERNALERROR*File*conftest.py*line 2*", "*0 / 0*"]
        )
        result = testdir.runpytest(testdir.tmpdir, "--fulltrace")
        assert result.ret != 0
        # tracestyle is native by default for hook failures
        result.stdout.fnmatch_lines(
            ["*INTERNALERROR*def pytest_sessionstart():*", "*INTERNALERROR*0 / 0*"]
        ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:21,代码来源:acceptance_test.py

示例10: test_namespace_import_doesnt_confuse_import_hook

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_namespace_import_doesnt_confuse_import_hook(self, testdir):
        """
        Ref #383. Python 3.3's namespace package messed with our import hooks
        Importing a module that didn't exist, even if the ImportError was
        gracefully handled, would make our test crash.

        Use recwarn here to silence this warning in Python 2.7:
            ImportWarning: Not importing directory '...\not_a_package': missing __init__.py
        """
        testdir.mkdir("not_a_package")
        p = testdir.makepyfile(
            """
            try:
                from not_a_package import doesnt_exist
            except ImportError:
                # We handle the import error gracefully here
                pass

            def test_whatever():
                pass
        """
        )
        res = testdir.runpytest(p.basename)
        assert res.ret == 0 
开发者ID:pytest-dev,项目名称:pytest,代码行数:26,代码来源:acceptance_test.py

示例11: test_import_star_py_dot_test

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_import_star_py_dot_test(self, testdir):
        p = testdir.makepyfile(
            """
            from py.test import *
            #collect
            #cmdline
            #Item
            # assert collect.Item is Item
            # assert collect.Collector is Collector
            main
            skip
            xfail
        """
        )
        result = testdir.runpython(p)
        assert result.ret == 0 
开发者ID:pytest-dev,项目名称:pytest,代码行数:18,代码来源:acceptance_test.py

示例12: test_zipimport_hook

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_zipimport_hook(testdir, tmpdir):
    """Test package loader is being used correctly (see #1837)."""
    zipapp = pytest.importorskip("zipapp")
    testdir.tmpdir.join("app").ensure(dir=1)
    testdir.makepyfile(
        **{
            "app/foo.py": """
            import pytest
            def main():
                pytest.main(['--pyargs', 'foo'])
        """
        }
    )
    target = tmpdir.join("foo.zip")
    zipapp.create_archive(str(testdir.tmpdir.join("app")), str(target), main="foo:main")
    result = testdir.runpython(target)
    assert result.ret == 0
    result.stderr.fnmatch_lines(["*not found*foo*"])
    result.stdout.no_fnmatch_line("*INTERNALERROR>*") 
开发者ID:pytest-dev,项目名称:pytest,代码行数:21,代码来源:acceptance_test.py

示例13: test_warn_on_async_gen_function

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def test_warn_on_async_gen_function(testdir):
    testdir.makepyfile(
        test_async="""
        async def test_1():
            yield
        async def test_2():
            yield
        def test_3():
            return test_2()
    """
    )
    result = testdir.runpytest()
    result.stdout.fnmatch_lines(
        [
            "test_async.py::test_1",
            "test_async.py::test_2",
            "test_async.py::test_3",
            "*async def functions are not natively supported*",
            "*3 skipped, 3 warnings in*",
        ]
    )
    # ensure our warning message appears only once
    assert (
        result.stdout.str().count("async def functions are not natively supported") == 1
    ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:27,代码来源:acceptance_test.py

示例14: _complete_location

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def _complete_location(self, text, line, begidx, endidx):
        # Complete a file/module/function location for break/tbreak/clear.
        if line.strip().endswith((':', ',')):
            # Here comes a line number or a condition which we can't complete.
            return []
        # First, try to find matching functions (i.e. expressions).
        try:
            ret = self._complete_expression(text, line, begidx, endidx)
        except Exception:
            ret = []
        # Then, try to complete file names as well.
        globs = glob.glob(text + '*')
        for fn in globs:
            if os.path.isdir(fn):
                ret.append(fn + '/')
            elif os.path.isfile(fn) and fn.lower().endswith(('.py', '.pyw')):
                ret.append(fn + ':')
        return ret 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:pdb.py

示例15: import_from_stdlib

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import py [as 别名]
def import_from_stdlib(name):
    import code  # arbitrary module which stays in the same dir as pdb
    result = types.ModuleType(name)

    stdlibdir, _ = os.path.split(code.__file__)
    pyfile = os.path.join(stdlibdir, name + '.py')
    with open(pyfile) as f:
        src = f.read()
    co_module = compile(src, pyfile, 'exec', dont_inherit=True)
    exec(co_module, result.__dict__)

    return result 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:14,代码来源:pdbpp.py


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