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


Python sys.module方法代码示例

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


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

示例1: inline_runsource

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def inline_runsource(self, source, *cmdlineargs):
        """Run a test module in process using ``pytest.main()``.

        This run writes "source" into a temporary file and runs
        ``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance
        for the result.

        :param source: the source code of the test module

        :param cmdlineargs: any extra command line arguments to use

        :return: :py:class:`HookRecorder` instance of the result

        """
        p = self.makepyfile(source)
        values = list(cmdlineargs) + [p]
        return self.inline_run(*values) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:19,代码来源:pytester.py

示例2: getitem

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def getitem(self, source, funcname="test_func"):
        """Return the test item for a test function.

        This writes the source to a python file and runs pytest's collection on
        the resulting module, returning the test item for the requested
        function name.

        :param source: the module source

        :param funcname: the name of the test function for which to return a
            test item

        """
        items = self.getitems(source)
        for item in items:
            if item.name == funcname:
                return item
        assert 0, "{!r} item not found in module:\n{}\nitems: {}".format(
            funcname, source, items
        ) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:22,代码来源:pytester.py

示例3: _setWarningRegistryToNone

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def _setWarningRegistryToNone(modules):
    """
    Disable the per-module cache for every module found in C{modules}, typically
    C{sys.modules}.

    @param modules: Dictionary of modules, typically sys.module dict
    """
    for v in list(modules.values()):
        if v is not None:
            try:
                v.__warningregistry__ = None
            except:
                # Don't specify a particular exception type to handle in case
                # some wacky object raises some wacky exception in response to
                # the setattr attempt.
                pass 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:_synctest.py

示例4: run_module

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def run_module(mod_name, init_globals=None,
                         run_name=None, alter_sys=False):
    """Execute a module's code without importing it

       Returns the resulting top level namespace dictionary
    """
    loader = get_loader(mod_name)
    if loader is None:
        raise ImportError("No module named " + mod_name)
    code = loader.get_code(mod_name)
    if code is None:
        raise ImportError("No code object available for " + mod_name)
    filename = _get_filename(loader, mod_name)
    if run_name is None:
        run_name = mod_name
    return _run_module_code(code, init_globals, run_name,
                            filename, loader, alter_sys) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:19,代码来源:runpy.py

示例5: getitems

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def getitems(self, source):
        """Return all test items collected from the module.

        This writes the source to a python file and runs pytest's collection on
        the resulting module, returning all test items contained within.

        """
        modcol = self.getmodulecol(source)
        return self.genitems([modcol]) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:11,代码来源:pytester.py

示例6: getmodulecol

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def getmodulecol(self, source, configargs=(), withinit=False):
        """Return the module collection node for ``source``.

        This writes ``source`` to a file using :py:meth:`makepyfile` and then
        runs the pytest collection on it, returning the collection node for the
        test module.

        :param source: the source code of the module to collect

        :param configargs: any extra arguments to pass to
            :py:meth:`parseconfigure`

        :param withinit: whether to also write an ``__init__.py`` file to the
            same directory to ensure it is a package

        """
        if isinstance(source, Path):
            path = self.tmpdir.join(str(source))
            assert not withinit, "not supported for paths"
        else:
            kw = {self.request.function.__name__: Source(source).strip()}
            path = self.makepyfile(**kw)
        if withinit:
            self.makepyfile(__init__="#")
        self.config = config = self.parseconfigure(path, *configargs)
        return self.getnode(config, path) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:28,代码来源:pytester.py

示例7: _collectWarnings

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def _collectWarnings(observeWarning, f, *args, **kwargs):
    """
    Call C{f} with C{args} positional arguments and C{kwargs} keyword arguments
    and collect all warnings which are emitted as a result in a list.

    @param observeWarning: A callable which will be invoked with a L{_Warning}
        instance each time a warning is emitted.

    @return: The return value of C{f(*args, **kwargs)}.
    """
    def showWarning(message, category, filename, lineno, file=None, line=None):
        assert isinstance(message, Warning)
        observeWarning(_Warning(
                str(message), category, filename, lineno))

    # Disable the per-module cache for every module otherwise if the warning
    # which the caller is expecting us to collect was already emitted it won't
    # be re-emitted by the call to f which happens below.
    _setWarningRegistryToNone(sys.modules)

    origFilters = warnings.filters[:]
    origShow = warnings.showwarning
    warnings.simplefilter('always')
    try:
        warnings.showwarning = showWarning
        result = f(*args, **kwargs)
    finally:
        warnings.filters[:] = origFilters
        warnings.showwarning = origShow
    return result 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:32,代码来源:_synctest.py

示例8: getSkip

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def getSkip(self):
        """
        Return the skip reason set on this test, if any is set. Checks on the
        instance first, then the class, then the module, then packages. As
        soon as it finds something with a C{skip} attribute, returns that.
        Returns L{None} if it cannot find anything. See L{TestCase} docstring
        for more details.
        """
        return util.acquireAttribute(self._parents, 'skip', None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:_synctest.py

示例9: getTodo

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def getTodo(self):
        """
        Return a L{Todo} object if the test is marked todo. Checks on the
        instance first, then the class, then the module, then packages. As
        soon as it finds something with a C{todo} attribute, returns that.
        Returns L{None} if it cannot find anything. See L{TestCase} docstring
        for more details.
        """
        todo = util.acquireAttribute(self._parents, 'todo', None)
        if todo is None:
            return None
        return makeTodo(todo) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:_synctest.py

示例10: _getSuppress

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def _getSuppress(self):
        """
        Returns any warning suppressions set for this test. Checks on the
        instance first, then the class, then the module, then packages. As
        soon as it finds something with a C{suppress} attribute, returns that.
        Returns any empty list (i.e. suppress no warnings) if it cannot find
        anything. See L{TestCase} docstring for more details.
        """
        return util.acquireAttribute(self._parents, 'suppress', []) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:_synctest.py

示例11: getmodulecol

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def getmodulecol(self, source, configargs=(), withinit=False):
        """Return the module collection node for ``source``.

        This writes ``source`` to a file using :py:meth:`makepyfile` and then
        runs the pytest collection on it, returning the collection node for the
        test module.

        :param source: the source code of the module to collect

        :param configargs: any extra arguments to pass to
            :py:meth:`parseconfigure`

        :param withinit: whether to also write an ``__init__.py`` file to the
            same directory to ensure it is a package

        """
        if isinstance(source, Path):
            path = self.tmpdir.join(str(source))
            assert not withinit, "not supported for paths"
        else:
            kw = {self._name: Source(source).strip()}
            path = self.makepyfile(**kw)
        if withinit:
            self.makepyfile(__init__="#")
        self.config = config = self.parseconfigure(path, *configargs)
        return self.getnode(config, path) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:28,代码来源:pytester.py

示例12: setUpClass

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def setUpClass(cls_, module=module):
            cls_._save_sys_modules = sys.modules.copy()
            sys.modules[TESTS] = module
            sys.modules['datetime'] = module.datetime_module
            sys.modules['_strptime'] = module._strptime 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_datetime.py

示例13: exec_module

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def exec_module(module):
        if module.__name__ == SUBMOD_NAME:
            raise ImportError('I cannot be loaded!') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_api.py

示例14: test_name_requires_rparition

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def test_name_requires_rparition(self):
        # Raise TypeError if a non-string is passed in for the module name.
        with self.assertRaises(TypeError):
            self.__import__(42) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_api.py

示例15: test_negative_level

# 需要导入模块: import sys [as 别名]
# 或者: from sys import module [as 别名]
def test_negative_level(self):
        # Raise ValueError when a negative level is specified.
        # PEP 328 did away with sys.module None entries and the ambiguity of
        # absolute/relative imports.
        with self.assertRaises(ValueError):
            self.__import__('os', globals(), level=-1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_api.py


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