當前位置: 首頁>>代碼示例>>Python>>正文


Python test_support.__name__方法代碼示例

本文整理匯總了Python中test.test_support.__name__方法的典型用法代碼示例。如果您正苦於以下問題:Python test_support.__name__方法的具體用法?Python test_support.__name__怎麽用?Python test_support.__name__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在test.test_support的用法示例。


在下文中一共展示了test_support.__name__方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_replace_parent_in_sys_modules

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import __name__ [as 別名]
def test_replace_parent_in_sys_modules(self):
        dir_name = os.path.abspath(TESTFN)
        os.mkdir(dir_name)
        self.addCleanup(rmtree, dir_name)
        pkg_dir = os.path.join(dir_name, 'sa')
        os.mkdir(pkg_dir)
        with open(os.path.join(pkg_dir, '__init__.py'), 'w') as init_file:
            init_file.write("import v1")
        with open(os.path.join(pkg_dir, 'v1.py'), 'w') as v1_file:
            v1_file.write("import sys;"
                          "sys.modules['sa'] = sys.modules[__name__];"
                          "import sa")
        sys.path.insert(0, dir_name)
        self.addCleanup(sys.path.pop, 0)
        # a segfault means the test failed!
        import sa 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_import.py

示例2: test_import_name_binding

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import __name__ [as 別名]
def test_import_name_binding(self):
        # import x.y.z binds x in the current namespace.
        import test as x
        import test.test_support
        self.assertIs(x, test, x.__name__)
        self.assertTrue(hasattr(test.test_support, "__file__"))

        # import x.y.z as w binds z as w.
        import test.test_support as y
        self.assertIs(y, test.test_support, y.__name__) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_import.py

示例3: test_issue3221

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import __name__ [as 別名]
def test_issue3221(self):
        # Regression test for http://bugs.python.org/issue3221.
        def check_absolute():
            exec "from os import path" in ns
        def check_relative():
            exec "from . import relimport" in ns

        # Check both OK with __package__ and __name__ correct
        ns = dict(__package__='test', __name__='test.notarealmodule')
        check_absolute()
        check_relative()

        # Check both OK with only __name__ wrong
        ns = dict(__package__='test', __name__='notarealpkg.notarealmodule')
        check_absolute()
        check_relative()

        # Check relative fails with only __package__ wrong
        ns = dict(__package__='foo', __name__='test.notarealmodule')
        with check_warnings(('.+foo', RuntimeWarning)):
            check_absolute()
        self.assertRaises(SystemError, check_relative)

        # Check relative fails with __package__ and __name__ wrong
        ns = dict(__package__='foo', __name__='notarealpkg.notarealmodule')
        with check_warnings(('.+foo', RuntimeWarning)):
            check_absolute()
        self.assertRaises(SystemError, check_relative)

        # Check both fail with package set to a non-string
        ns = dict(__package__=object())
        self.assertRaises(ValueError, check_absolute)
        self.assertRaises(ValueError, check_relative) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:35,代碼來源:test_import.py

示例4: test_import_name_binding

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import __name__ [as 別名]
def test_import_name_binding():
    # import x.y.z binds x in the current namespace
    import test as x
    import test.test_support
    assert x is test, x.__name__
    assert hasattr(test.test_support, "__file__")

    # import x.y.z as w binds z as w
    import test.test_support as y
    assert y is test.test_support, y.__name__ 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:12,代碼來源:test_import.py


注:本文中的test.test_support.__name__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。