sys.modules.update

Here are the examples of the python api sys.modules.update taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

22 Examples 7

Example 1

View license
    def setUp(self):

        modules = {
            'win32api': mock.Mock(),
            'win32com': mock.Mock(),
            'win32com.shell': mock.Mock(),
            'win32serviceutil': mock.Mock(),
            'pywintypes': mock.Mock(),
            'win32service': mock.Mock()        
        }

        sys.modules.update(modules)

        
        from chalmers.service.win32_system_service import Win32SystemService

        self.modules = modules
        self.Win32SystemService = Win32SystemService

Example 2

View license
    def setUp(self):

        modules = {
            'win32api': mock.Mock(),
            'win32com': mock.Mock(),
            'win32com.shell': mock.Mock(),
            'win32serviceutil': mock.Mock(),
            'pywintypes': mock.Mock(),
            'win32service': mock.Mock()        
        }

        sys.modules.update(modules)

        
        from chalmers.service.win32_system_service import Win32SystemService

        self.modules = modules
        self.Win32SystemService = Win32SystemService

Example 3

Project: shapy
Source File: test_settings.py
View license
    def setUp(self):
        self.settings = imp.new_module('test_settings')
        sys.modules.update(test_settings=self.settings)
        setattr(self.settings, 'UNITS', 'override')
        setattr(self.settings, 'NEW_OPTION', 'new')

Example 4

Project: pymo
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 5

Project: imagrium
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 6

Project: github-cli
Source File: test_base.py
View license
    def tearDown(self):
        sys.modules.update(self.mods)

Example 7

Project: chipsec
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 8

Project: CNCGToolKit
Source File: Qt.py
View license
def init():
    """Try loading each binding in turn

    Please note: the entire Qt module is replaced with this code:
        sys.modules["Qt"] = binding()

    This means no functions or variables can be called after
    this has executed.

    For debugging and testing, this module may be accessed
    through `Qt.__shim__`.

    """

    preferred = os.getenv("QT_PREFERRED_BINDING")
    verbose = os.getenv("QT_VERBOSE") is not None
    bindings = (_pyside2, _pyqt5, _pyside, _pyqt4)

    if preferred:
        # Internal flag (used in installer)
        if preferred == "None":
            self.__wrapper_version__ = self.__version__
            return

        preferred = preferred.split(os.pathsep)
        available = {
            "PySide2": _pyside2,
            "PyQt5": _pyqt5,
            "PySide": _pyside,
            "PyQt4": _pyqt4
        }

        try:
            bindings = [available[binding] for binding in preferred]
        except KeyError:
            raise ImportError(
                "Available preferred Qt bindings: "
                "\n".join(preferred)
            )

    for binding in bindings:
        _log("Trying %s" % binding.__name__, verbose)

        try:
            binding = binding()

        except ImportError as e:
            _log(" - ImportError(\"%s\")" % e, verbose)
            continue

        else:
            # Reference to this module
            binding.__shim__ = self
            binding.QtCompat = self

            sys.modules.update({
                __name__: binding,

                # Fix #133, `from Qt.QtWidgets import QPushButton`
                __name__ + ".QtWidgets": binding.QtWidgets

            })

            return

    # If not binding were found, throw this error
    raise ImportError("No Qt binding were found.")

Example 9

Project: pikos
Source File: conf.py
View license
def mock_modules():

    from mock import MagicMock

    try:
        import yappi  # noqa
    except ImportError:
        MOCK_MODULES = ['yappi']
    else:
        MOCK_MODULES = []

    try:
        import zmq  # noqa
    except ImportError:
        MOCK_MODULES.append('zmq')

    try:
        import line_profiler  # noqa
    except ImportError:
        MOCK_MODULES.append('line_profiler')

    class Mock(MagicMock):

        @classmethod
        def __getattr__(cls, name):
            return Mock()

        def __call__(self, *args, **kwards):
            return Mock()

        def __name__(self, other):
            return 'Mock'

    sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
    print 'mocking {}'.format(MOCK_MODULES)

Example 10

Project: pywin32-ctypes
Source File: mock_missing.py
View license
def mock_modules():
    """ Mock missing modules if necessary """

    MOCK_MODULES = []
    MOCK_TYPES = []

    try:
        import cffi
    except ImportError:
        MOCK_MODULES = ['cffi']
        MOCK_TYPES = []
    else:
        del cffi

    TYPES = {
        mock_type: type(mock_type, bases, {'__module__': path})
        for path, mock_type, bases in MOCK_TYPES}

    class DocMock(object):

        def __init__(self, *args, **kwds):
            if '__doc_mocked_name__' in kwds:
                self.__docmock_name__ = kwds['__docmocked_name__']
            else:
                self.__docmock_name__ = 'Unknown'

        def __getattr__(self, name):
            if name in ('__file__', '__path__'):
                return '/dev/null'
            elif name == '__all__':
                return []
            else:
                return TYPES.get(name, DocMock(__docmock_name__=name))

        def __call__(self, *args, **kwards):
            return DocMock()

        def __iter__(self):
            return self

        def __next__(self):
            raise StopIteration()

        def next(self):
            raise StopIteration()

        @property
        def __name__(self):
            return self.__docmock_name__

        def __repr__(self):
            return '<DocMock.{}>'.format(self.__name__)

    sys.modules.update(
        (mod_name, DocMock(mocked_name=mod_name)) for mod_name in MOCK_MODULES)
    print('mocking modules {} and types {}'.format(MOCK_MODULES, MOCK_TYPES))

Example 11

Project: openwrt-mt7620
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 12

Project: openwrt-mt7620
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 13

Project: xtraceback
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 14

Project: xtraceback
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 15

Project: xtraceback
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 16

Project: xtraceback
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 17

Project: xtraceback
Source File: support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 18

Project: xtraceback
Source File: support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)

Example 19

Project: Qt.py
Source File: Qt.py
View license
def init():
    """Try loading each binding in turn

    Please note: the entire Qt module is replaced with this code:
        sys.modules["Qt"] = binding()

    This means no functions or variables can be called after
    this has executed.

    For debugging and testing, this module may be accessed
    through `Qt.__shim__`.

    """

    bindings = (_pyside2, _pyqt5, _pyside, _pyqt4)

    if QT_PREFERRED_BINDING:
        # Internal flag (used in installer)
        if QT_PREFERRED_BINDING == "None":
            self.__wrapper_version__ = self.__version__
            return

        preferred = QT_PREFERRED_BINDING.split(os.pathsep)
        available = {
            "PySide2": _pyside2,
            "PyQt5": _pyqt5,
            "PySide": _pyside,
            "PyQt4": _pyqt4
        }

        try:
            bindings = [available[binding] for binding in preferred]
        except KeyError:
            raise ImportError(
                "Available preferred Qt bindings: "
                "\n".join(preferred)
            )

    for binding in bindings:
        _log("Trying %s" % binding.__name__, QT_VERBOSE)

        try:
            binding = binding()

        except ImportError as e:
            _log(" - ImportError(\"%s\")" % e, QT_VERBOSE)
            continue

        else:
            # Reference to this module
            binding.QtCompat = self
            binding.__shim__ = self  # DEPRECATED

            sys.modules.update({
                __name__: binding,

                # Fix #133, `from Qt.QtWidgets import QPushButton`
                __name__ + ".QtWidgets": binding.QtWidgets

            })

            return

    # If not binding were found, throw this error
    raise ImportError("No Qt binding were found.")

Example 20

Project: make.mozilla.org
Source File: __init__.py
View license
    def tearDown(self):
        sys.modules.update(self._prev)

Example 21

Project: make.mozilla.org
Source File: __init__.py
View license
    def tearDown(self):
        sys.modules.update(self._prev)

Example 22

Project: PyAutoC
Source File: test_support.py
View license
    def __exit__(self, *ignore_exc):
        sys.modules.update(self.original_modules)