當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。