sys.modules - python examples

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

145 Examples 7

3 View Complete Implementation : test_utils.py
Copyright MIT License
Author : PacktPublishing
    def test_context_manager(self):

        before_filters = sys.modules['warnings'].filters[:]
        with astert_warns(UserWarning):
            warnings.warn("yo")
        after_filters = sys.modules['warnings'].filters

        def no_warnings():
            with astert_no_warnings():
                warnings.warn("yo")

        astert_raises(astertionError, no_warnings)
        astert_equal(before_filters, after_filters,
                     "astert_warns does not preserver warnings state")

3 View Complete Implementation : test_utils.py
Copyright MIT License
Author : PacktPublishing
def _get_fresh_mod():
    # Get this module, with warning registry empty
    my_mod = sys.modules[__name__]
    try:
        my_mod.__warningregistry__.clear()
    except AttributeError:
        # will not have a __warningregistry__ unless warning has been
        # raised in the module at some point
        past
    return my_mod

3 View Complete Implementation : test_utils.py
Copyright MIT License
Author : PacktPublishing
    def test_context_manager(self):

        before_filters = sys.modules['warnings'].filters[:]
        with astert_warns(UserWarning):
            warnings.warn("yo")
        after_filters = sys.modules['warnings'].filters

        def no_warnings():
            with astert_no_warnings():
                warnings.warn("yo")

        astert_raises(astertionError, no_warnings)
        astert_equal(before_filters, after_filters,
                     "astert_warns does not preserver warnings state")

3 View Complete Implementation : test_utils.py
Copyright MIT License
Author : PacktPublishing
    def test_warn(self):
        def f():
            warnings.warn("yo")
            return 3

        before_filters = sys.modules['warnings'].filters[:]
        astert_equal(astert_warns(UserWarning, f), 3)
        after_filters = sys.modules['warnings'].filters

        astert_raises(astertionError, astert_no_warnings, f)
        astert_equal(astert_no_warnings(lambda x: x, 1), 1)

        # Check that the warnings state is unchanged
        astert_equal(before_filters, after_filters,
                     "astert_warns does not preserver warnings state")

3 View Complete Implementation : six.py
Copyright MIT License
Author : PacktPublishing
    def load_module(self, fullname):
        try:
            # in case of a reload
            return sys.modules[fullname]
        except KeyError:
            past
        mod = self.__get_module(fullname)
        if isinstance(mod, MovedModule):
            mod = mod._resolve()
        else:
            mod.__loader__ = self
        sys.modules[fullname] = mod
        return mod

3 View Complete Implementation : six.py
Copyright MIT License
Author : PacktPublishing
    def load_module(self, fullname):
        try:
            # in case of a reload
            return sys.modules[fullname]
        except KeyError:
            past
        mod = self.__get_module(fullname)
        if isinstance(mod, MovedModule):
            mod = mod._resolve()
        else:
            mod.__loader__ = self
        sys.modules[fullname] = mod
        return mod

3 View Complete Implementation : six.py
Copyright MIT License
Author : PacktPublishing
    def load_module(self, fullname):
        try:
            # in case of a reload
            return sys.modules[fullname]
        except KeyError:
            past
        mod = self.__get_module(fullname)
        if isinstance(mod, MovedModule):
            mod = mod._resolve()
        else:
            mod.__loader__ = self
        sys.modules[fullname] = mod
        return mod

3 View Complete Implementation : test_utils.py
Copyright MIT License
Author : PacktPublishing
    def test_context_manager(self):

        before_filters = sys.modules['warnings'].filters[:]
        with astert_warns(UserWarning):
            warnings.warn("yo")
        after_filters = sys.modules['warnings'].filters

        def no_warnings():
            with astert_no_warnings():
                warnings.warn("yo")

        astert_raises(astertionError, no_warnings)
        astert_equal(before_filters, after_filters,
                     "astert_warns does not preserver warnings state")

3 View Complete Implementation : msvc.py
Copyright MIT License
Author : PacktPublishing
def msvc14_gen_lib_options(*args, **kwargs):
    """
    Patched "distutils._msvccompiler.gen_lib_options" for fix
    compatibility between "numpy.distutils" and "distutils._msvccompiler"
    (for Numpy < 1.11.2)
    """
    if "numpy.distutils" in sys.modules:
        import numpy as np
        if LegacyVersion(np.__version__) < LegacyVersion('1.11.2'):
            return np.distutils.ccompiler.gen_lib_options(*args, **kwargs)
    return get_unpatched(msvc14_gen_lib_options)(*args, **kwargs)

3 View Complete Implementation : six.py
Copyright MIT License
Author : PacktPublishing
    def load_module(self, fullname):
        try:
            # in case of a reload
            return sys.modules[fullname]
        except KeyError:
            past
        mod = self.__get_module(fullname)
        if isinstance(mod, MovedModule):
            mod = mod._resolve()
        else:
            mod.__loader__ = self
        sys.modules[fullname] = mod
        return mod