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


Python support.import_fresh_module函数代码示例

本文整理汇总了Python中test.support.import_fresh_module函数的典型用法代码示例。如果您正苦于以下问题:Python import_fresh_module函数的具体用法?Python import_fresh_module怎么用?Python import_fresh_module使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: import_importlib

def import_importlib(module_name):
    """Import a module from importlib both w/ and w/o _frozen_importlib."""
    fresh = ('importlib',) if '.' in module_name else ()
    frozen = support.import_fresh_module(module_name)
    source = support.import_fresh_module(module_name, fresh=fresh,
                                         blocked=('_frozen_importlib', '_frozen_importlib_external'))
    return {'Frozen': frozen, 'Source': source}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:7,代码来源:util.py

示例2: import_importlib

def import_importlib(module_name):
    """Import a module from importlib both w/ and w/o _frozen_importlib."""
    fresh = ('importlib',) if '.' in module_name else ()
    frozen = support.import_fresh_module(module_name)
    source = support.import_fresh_module(module_name, fresh=fresh,
                                         blocked=('_frozen_importlib',))
    return frozen, source
开发者ID:0jpq0,项目名称:kbengine,代码行数:7,代码来源:util.py

示例3: test_environment

 def test_environment(self):
     webbrowser = support.import_fresh_module('webbrowser')
     try:
         browser = webbrowser.get().name
     except (webbrowser.Error, AttributeError) as err:
         self.skipTest(str(err))
     with support.EnvironmentVarGuard() as env:
         env["BROWSER"] = browser
         webbrowser = support.import_fresh_module('webbrowser')
         webbrowser.get()
开发者ID:Eyepea,项目名称:cpython,代码行数:10,代码来源:test_webbrowser.py

示例4: test_get

    def test_get(self):
        webbrowser = support.import_fresh_module('webbrowser')
        self.assertIsNone(webbrowser._tryorder)
        self.assertFalse(webbrowser._browsers)

        with self.assertRaises(webbrowser.Error):
            webbrowser.get('fakebrowser')
        self.assertIsNotNone(webbrowser._tryorder)
开发者ID:ammaraskar,项目名称:cpython,代码行数:8,代码来源:test_webbrowser.py

示例5: testWithoutThreading

 def testWithoutThreading(self):
     if not hasattr(support, "import_fresh_module"):
         return
     module = support.import_fresh_module("bz2file", blocked=("threading",))
     with module.BZ2File(self.filename, "wb") as f:
         f.write(b"abc")
     with module.BZ2File(self.filename, "rb") as f:
         self.assertEqual(f.read(), b"abc")
开发者ID:heni,项目名称:bz2file,代码行数:8,代码来源:test_bz2file.py

示例6: test_environment_preferred

    def test_environment_preferred(self):
        webbrowser = support.import_fresh_module('webbrowser')
        try:
            webbrowser.get()
            least_preferred_browser = webbrowser.get(webbrowser._tryorder[-1]).name
        except (webbrowser.Error, AttributeError, IndexError) as err:
            self.skipTest(str(err))

        with support.EnvironmentVarGuard() as env:
            env["BROWSER"] = least_preferred_browser
            webbrowser = support.import_fresh_module('webbrowser')
            self.assertEqual(webbrowser.get().name, least_preferred_browser)

        with support.EnvironmentVarGuard() as env:
            env["BROWSER"] = sys.executable
            webbrowser = support.import_fresh_module('webbrowser')
            self.assertEqual(webbrowser.get().name, sys.executable)
开发者ID:Eyepea,项目名称:cpython,代码行数:17,代码来源:test_webbrowser.py

示例7: test_register

    def test_register(self):
        webbrowser = support.import_fresh_module('webbrowser')
        self.assertIsNone(webbrowser._tryorder)
        self.assertFalse(webbrowser._browsers)

        class ExampleBrowser:
            pass
        webbrowser.register('Example1', ExampleBrowser)
        self.assertTrue(webbrowser._tryorder)
        self.assertEqual(webbrowser._tryorder[-1], 'Example1')
        self.assertTrue(webbrowser._browsers)
        self.assertIn('example1', webbrowser._browsers)
        self.assertEqual(webbrowser._browsers['example1'], [ExampleBrowser, None])
开发者ID:ammaraskar,项目名称:cpython,代码行数:13,代码来源:test_webbrowser.py

示例8: importable

import unittest.mock
from test import support
import builtins
import contextlib
import copy
import io
import os
import pickle
import shutil
import subprocess
import sys

py_uuid = support.import_fresh_module('uuid', blocked=['_uuid'])
c_uuid = support.import_fresh_module('uuid', fresh=['_uuid'])


def importable(name):
    try:
        __import__(name)
        return True
    except:
        return False


class BaseTestUUID:
    uuid = None

    def test_UUID(self):
        equal = self.assertEqual
        ascending = []
        for (string, curly, hex, bytes, bytes_le, fields, integer, urn,
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:31,代码来源:test_uuid.py

示例9: import_fresh_module

import unittest
import sys
from test.support import import_fresh_module, run_unittest
TESTS = 'test.datetimetester'
# XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
# XXX: but it does not, so we have to save and restore it ourselves.
save_sys_modules = sys.modules.copy()
try:
    pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
                                     blocked=['_datetime'])
    fast_tests = import_fresh_module(TESTS, fresh=['datetime',
                                                   '_datetime', '_strptime'])
finally:
    sys.modules.clear()
    sys.modules.update(save_sys_modules)
test_modules = [pure_tests, fast_tests]
test_suffixes = ["_Pure", "_Fast"]

for module, suffix in zip(test_modules, test_suffixes):
    for name, cls in module.__dict__.items():
        if isinstance(cls, type) and issubclass(cls, unittest.TestCase):
            name += suffix
            cls.__name__ = name
            globals()[name] = cls
            def setUp(self, module=module, setup=cls.setUp):
                self._save_sys_modules = sys.modules.copy()
                sys.modules[TESTS] = module
                sys.modules['datetime'] = module.datetime_module
                sys.modules['_strptime'] = module._strptime
                setup(self)
            def tearDown(self, teardown=cls.tearDown):
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:31,代码来源:test_datetime.py

示例10: import_fresh_module

#

#
# Usage: python deccheck.py [--short|--medium|--long|--all]
#

import sys, random
from copy import copy
from collections import defaultdict
from test.support import import_fresh_module
from randdec import randfloat, all_unary, all_binary, all_ternary
from randdec import unary_optarg, binary_optarg, ternary_optarg
from formathelper import rand_format, rand_locale
from _pydecimal import _dec_from_triple

C = import_fresh_module("decimal", fresh=["_decimal"])
P = import_fresh_module("decimal", blocked=["_decimal"])
EXIT_STATUS = 0


# Contains all categories of Decimal methods.
Functions = {
    # Plain unary:
    "unary": (
        "__abs__",
        "__bool__",
        "__ceil__",
        "__complex__",
        "__copy__",
        "__floor__",
        "__float__",
开发者ID:ChanChiChoi,项目名称:cpython,代码行数:31,代码来源:deccheck.py

示例11: get_tk_patchlevel

import unittest
import sys
import os
from test import support

# Skip this test if the _tkinter module wasn't built.
_tkinter = support.import_module("_tkinter")

# Make sure tkinter._fix runs to set up the environment
support.import_fresh_module("tkinter")

from tkinter import Tcl
from _tkinter import TclError

try:
    from _testcapi import INT_MAX, PY_SSIZE_T_MAX
except ImportError:
    INT_MAX = PY_SSIZE_T_MAX = sys.maxsize

tcl_version = _tkinter.TCL_VERSION.split(".")
try:
    for i in range(len(tcl_version)):
        tcl_version[i] = int(tcl_version[i])
except ValueError:
    pass
tcl_version = tuple(tcl_version)

_tk_patchlevel = None


def get_tk_patchlevel():
开发者ID:TheYear2015,项目名称:TextWorldEditor,代码行数:31,代码来源:test_tcl.py

示例12: import_fresh_module

# xml.etree test for cElementTree
import sys, struct
from test import support
from test.support import import_fresh_module
import types
import unittest

cET = import_fresh_module('xml.etree.ElementTree',
                          fresh=['_elementtree'])
cET_alias = import_fresh_module('xml.etree.cElementTree',
                                fresh=['_elementtree', 'xml.etree'])


class MiscTests(unittest.TestCase):
    # Issue #8651.
    @support.bigmemtest(size=support._2G + 100, memuse=1, dry_run=False)
    def test_length_overflow(self, size):
        data = b'x' * size
        parser = cET.XMLParser()
        try:
            self.assertRaises(OverflowError, parser.feed, data)
        finally:
            data = None

    def test_del_attribute(self):
        element = cET.Element('tag')

        element.tag = 'TAG'
        with self.assertRaises(AttributeError):
            del element.tag
        self.assertEqual(element.tag, 'TAG')
开发者ID:chidea,项目名称:GoPythonDLLWrapper,代码行数:31,代码来源:test_xml_etree_c.py

示例13: import_module

import unittest
from test.support import import_module, import_fresh_module

# Skip test if _thread or _tkinter wasn't built or idlelib was deleted.
import_module('threading')  # imported by PyShell, imports _thread
tk = import_module('tkinter')  # imports _tkinter
idletest = import_module('idlelib.idle_test')
# Make sure TCL_LIBRARY is set properly on Windows.  Note that this will
# cause a warning about test_idle modifying the environment
import_fresh_module('tkinter._fix')

# Without test_main present, regrtest.runtest_inner (line1219) calls
# unittest.TestLoader().loadTestsFromModule(this_module) which calls
# load_tests() if it finds it. (Unittest.main does the same.)
load_tests = idletest.load_tests

if __name__ == '__main__':
    unittest.main(verbosity=2, exit=False)
开发者ID:chidea,项目名称:GoPythonDLLWrapper,代码行数:18,代码来源:test_idle.py

示例14: testWithoutThreading

 def testWithoutThreading(self):
     bz2 = support.import_fresh_module("bz2", blocked=("threading",))
     with bz2.BZ2File(self.filename, "wb") as f:
         f.write(b"abc")
     with bz2.BZ2File(self.filename, "rb") as f:
         self.assertEqual(f.read(), b"abc")
开发者ID:timm,项目名称:timmnix,代码行数:6,代码来源:test_bz2.py

示例15: TestModules

"""Unittests for heapq."""

import sys
import random
import unittest

from test import support
from unittest import TestCase, skipUnless

py_heapq = support.import_fresh_module('heapq', blocked=['_heapq'])
c_heapq = support.import_fresh_module('heapq', fresh=['_heapq'])

# _heapq.nlargest/nsmallest are saved in heapq._nlargest/_smallest when
# _heapq is imported, so check them there
func_names = ['heapify', 'heappop', 'heappush', 'heappushpop',
              'heapreplace', '_heapreplace_max']

class TestModules(TestCase):
    def test_py_functions(self):
        for fname in func_names:
            self.assertEqual(getattr(py_heapq, fname).__module__, 'heapq')

    @skipUnless(c_heapq, 'requires _heapq')
    def test_c_functions(self):
        for fname in func_names:
            self.assertEqual(getattr(c_heapq, fname).__module__, '_heapq')


class TestHeap:

    def test_push_pop(self):
开发者ID:OffByOneStudios,项目名称:cpython,代码行数:31,代码来源:test_heapq.py


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