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


Python site.addpackage方法代碼示例

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


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

示例1: test_addpackage

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
def test_addpackage(self):
        # Make sure addpackage() imports if the line starts with 'import',
        # adds directories to sys.path for any line in the file that is not a
        # comment or import that is a valid directory name for where the .pth
        # file resides; invalid directories are not added
        pth_file = PthFile()
        pth_file.cleanup(prep=True)  # to make sure that nothing is
                                      # pre-existing that shouldn't be
        try:
            pth_file.create()
            site.addpackage(pth_file.base_dir, pth_file.filename, set())
            self.pth_file_tests(pth_file)
        finally:
            pth_file.cleanup() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_site.py

示例2: test_addpackage_import_bad_syntax

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
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') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_site.py

示例3: test_addpackage_import_bad_exec

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
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') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_site.py

示例4: test_addpackage_import_bad_pth_file

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
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') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_site.py

示例5: test_addsitedir

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
def test_addsitedir(self):
        # Same tests for test_addpackage since addsitedir() essentially just
        # calls addpackage() for every .pth file in the directory
        pth_file = PthFile()
        pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing
                                    # that is tested for
        try:
            pth_file.create()
            site.addsitedir(pth_file.base_dir, set())
            self.pth_file_tests(pth_file)
        finally:
            pth_file.cleanup() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_site.py

示例6: test_addpackage_import_bad_syntax

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
def test_addpackage_import_bad_syntax(self):
        # Issue 10642
        pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
        with captured_stderr() as err_out:
            site.addpackage(pth_dir, pth_fn, set())
        self.assertRegex(err_out.getvalue(), "line 1")
        self.assertRegex(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.assertRegex(err_out.getvalue(), 'Traceback')
        self.assertRegex(err_out.getvalue(), r'import bad\)syntax')
        self.assertRegex(err_out.getvalue(), 'SyntaxError') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:test_site.py

示例7: test_addpackage_import_bad_exec

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
def test_addpackage_import_bad_exec(self):
        # Issue 10642
        pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
        with captured_stderr() as err_out:
            site.addpackage(pth_dir, pth_fn, set())
        self.assertRegex(err_out.getvalue(), "line 2")
        self.assertRegex(err_out.getvalue(),
            re.escape(os.path.join(pth_dir, pth_fn)))
        # XXX: ditto previous XXX comment.
        self.assertRegex(err_out.getvalue(), 'Traceback')
        self.assertRegex(err_out.getvalue(), 'ImportError') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:test_site.py

示例8: test_addpackage_import_bad_pth_file

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
def test_addpackage_import_bad_pth_file(self):
        # Issue 5258
        pth_dir, pth_fn = self.make_pth("abc\x00def\n")
        with captured_stderr() as err_out:
            site.addpackage(pth_dir, pth_fn, set())
        self.assertRegex(err_out.getvalue(), "line 1")
        self.assertRegex(err_out.getvalue(),
            re.escape(os.path.join(pth_dir, pth_fn)))
        # XXX: ditto previous XXX comment.
        self.assertRegex(err_out.getvalue(), 'Traceback')
        self.assertRegex(err_out.getvalue(), 'ValueError') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:test_site.py

示例9: test_addpackage_import_bad_pth_file

# 需要導入模塊: import site [as 別名]
# 或者: from site import addpackage [as 別名]
def test_addpackage_import_bad_pth_file(self):
        # Issue 5258
        pth_dir, pth_fn = self.make_pth("abc\x00def\n")
        with captured_stderr() as err_out:
            site.addpackage(pth_dir, pth_fn, set())
        self.assertRegex(err_out.getvalue(), "line 1")
        self.assertRegex(err_out.getvalue(),
            re.escape(os.path.join(pth_dir, pth_fn)))
        # XXX: ditto previous XXX comment.
        self.assertRegex(err_out.getvalue(), 'Traceback')
        self.assertRegex(err_out.getvalue(), 'TypeError') 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:13,代碼來源:test_site.py


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