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


Python contextlib.__file__方法代码示例

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


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

示例1: setup_myfile

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def setup_myfile(self, testdir):
        testdir.makepyfile(
            myfile="""
            from pdbpp import set_trace

            def rewrite_file():
                with open(__file__, "w") as f:
                    f.write("something completely different")

            def after_settrace():
                import linecache
                linecache.checkcache()

            def fn():
                set_trace()
                after_settrace()
                set_trace()
                a = 3
            """)
        testdir.monkeypatch.setenv("PDBPP_COLORS", "0")
        testdir.syspathinsert() 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:23,代码来源:test_pdb.py

示例2: test_sticky_cutoff_with_tail

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_sticky_cutoff_with_tail():
    class MyConfig(ConfigTest):
        sticky_by_default = True

    def fn():
        set_trace(Config=MyConfig)
        print(1)
        # 1
        # 2
        # 3
        return

    check(fn, """
[NUM] > .*fn(), 5 frames hidden

NUM         def fn():
NUM             set_trace(Config=MyConfig)
NUM  ->         print(1)
NUM             # 1
NUM             # 2
...
# c
1
""", terminal_size=(len(__file__) + 50, 10)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:26,代码来源:test_pdb.py

示例3: test_position_of_obj_unwraps

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_position_of_obj_unwraps():
    import contextlib

    @contextlib.contextmanager
    def cm():
        raise NotImplementedError()

    pdb_ = PdbTest()
    pos = pdb_._get_position_of_obj(cm)

    if hasattr(inspect, "unwrap"):
        assert pos[0] == THIS_FILE_CANONICAL
        assert pos[2] == [
            "    @contextlib.contextmanager\n",
            "    def cm():\n",
            "        raise NotImplementedError()\n",
        ]
    else:
        contextlib_file = contextlib.__file__
        if sys.platform == 'win32':
            contextlib_file = contextlib_file.lower()
        assert pos[0] == contextlib_file.rstrip("c") 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:24,代码来源:test_pdb.py

示例4: is_py2_stdlib_module

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def is_py2_stdlib_module(m):
    """
    Tries to infer whether the module m is from the Python 2 standard library.
    This may not be reliable on all systems.
    """
    if PY3:
        return False
    if not 'stdlib_path' in is_py2_stdlib_module.__dict__:
        stdlib_files = [contextlib.__file__, os.__file__, copy.__file__]
        stdlib_paths = [os.path.split(f)[0] for f in stdlib_files]
        if not len(set(stdlib_paths)) == 1:
            # This seems to happen on travis-ci.org. Very strange. We'll try to
            # ignore it.
            flog.warn('Multiple locations found for the Python standard '
                         'library: %s' % stdlib_paths)
        # Choose the first one arbitrarily
        is_py2_stdlib_module.stdlib_path = stdlib_paths[0]

    if m.__name__ in sys.builtin_module_names:
        return True

    if hasattr(m, '__file__'):
        modpath = os.path.split(m.__file__)
        if (modpath[0].startswith(is_py2_stdlib_module.stdlib_path) and
            'site-packages' not in modpath[0]):
            return True

    return False 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:30,代码来源:__init__.py

示例5: test_longlist_displays_whole_function

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_longlist_displays_whole_function():
    """`ll` displays the whole function (no cutoff)."""
    def fn():
        set_trace()
        a = 1
        a = 1
        a = 1
        a = 1
        a = 1
        a = 1
        a = 1
        a = 1
        a = 1
        return a

    check(fn, """
[NUM] > .*fn()
-> a = 1
   5 frames hidden (try 'help hidden_frames')
# ll
NUM         def fn():
NUM             set_trace()
NUM  ->         a = 1
NUM             a = 1
NUM             a = 1
NUM             a = 1
NUM             a = 1
NUM             a = 1
NUM             a = 1
NUM             a = 1
NUM             a = 1
NUM             return a
# c

""", terminal_size=(len(__file__) + 50, 10)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:37,代码来源:test_pdb.py

示例6: test_sticky_cutoff_with_head

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_sticky_cutoff_with_head():
    class MyConfig(ConfigTest):
        sticky_by_default = True

    def fn():
        # 1
        # 2
        # 3
        # 4
        # 5
        set_trace(Config=MyConfig)
        print(1)
        return

    check(fn, """
[NUM] > .*fn(), 5 frames hidden

...
NUM             # 4
NUM             # 5
NUM             set_trace(Config=MyConfig)
NUM  ->         print(1)
NUM             return
# c
1
""", terminal_size=(len(__file__) + 50, 10)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:28,代码来源:test_pdb.py

示例7: test_sticky_cutoff_with_head_and_tail

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_sticky_cutoff_with_head_and_tail():
    class MyConfig(ConfigTest):
        sticky_by_default = True

    def fn():
        # 1
        # 2
        # 3
        set_trace(Config=MyConfig)
        print(1)
        # 1
        # 2
        # 3
        return

    check(fn, """
[NUM] > .*fn(), 5 frames hidden

...
NUM             set_trace(Config=MyConfig)
NUM  ->         print(1)
NUM             # 1
NUM             # 2
...
# c
1
""", terminal_size=(len(__file__) + 50, 10)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:29,代码来源:test_pdb.py

示例8: test_sticky_cutoff_with_decorator

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_sticky_cutoff_with_decorator():
    class MyConfig(ConfigTest):
        sticky_by_default = True

    def deco(f):
        return f

    @deco
    def fn():
        # 1
        # 2
        # 3
        # 4
        # 5
        set_trace(Config=MyConfig)
        print(1)
        return

    check(fn, """
[NUM] > .*fn(), 5 frames hidden

NUM         @deco
...
NUM             # 5
NUM             set_trace(Config=MyConfig)
NUM  ->         print(1)
NUM             return
# c
1
""", terminal_size=(len(__file__) + 50, 10)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:32,代码来源:test_pdb.py

示例9: test_sticky_cutoff_with_many_decorators

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_sticky_cutoff_with_many_decorators():
    class MyConfig(ConfigTest):
        sticky_by_default = True

    def deco(f):
        return f

    @deco
    @deco
    @deco
    @deco
    @deco
    @deco
    @deco
    @deco
    def fn():
        # 1
        # 2
        # 3
        # 4
        # 5
        set_trace(Config=MyConfig)
        print(1)
        return

    check(fn, """
[NUM] > .*fn(), 5 frames hidden

NUM         @deco
...
NUM         @deco
...
NUM  ->         print(1)
NUM             return
# c
1
""", terminal_size=(len(__file__) + 50, 10)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:39,代码来源:test_pdb.py

示例10: test_sticky_cutoff_with_decorator_colored

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_sticky_cutoff_with_decorator_colored():
    class MyConfig(ConfigWithPygmentsAndHighlight):
        sticky_by_default = True

    def deco(f):
        return f

    @deco
    @deco
    def fn():
        # 1
        # 2
        # 3
        # 4
        # 5
        set_trace(Config=MyConfig)
        print(1)
        return

    check(fn, """
[NUM] > .*fn(), 5 frames hidden

<COLORNUM>         ^[[38;5;129m@deco^[[39m
<COLORNUM>         ^[[38;5;129m@deco^[[39m
...
<COLORNUM>             set_trace.*
<COLORCURLINE>  ->         ^[[38;5;28.*;44mprint.*
<COLORNUM>             ^[[38;5;28;01mreturn^[[39;00m
# c
1
""", terminal_size=(len(__file__) + 50, 10)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:33,代码来源:test_pdb.py

示例11: test_sticky_cutoff_with_minimal_lines

# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import __file__ [as 别名]
def test_sticky_cutoff_with_minimal_lines():
    class MyConfig(ConfigTest):
        sticky_by_default = True

    def deco(f):
        return f

    @deco
    def fn():
        set_trace(Config=MyConfig)
        print(1)
        # 1
        # 2
        # 3
        return

    check(fn, """
[NUM] > .*fn(), 5 frames hidden

NUM         @deco
...
NUM  ->         print(1)
NUM             # 1
NUM             # 2
...
# c
1
""", terminal_size=(len(__file__) + 50, 3)) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:30,代码来源:test_pdb.py


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