Ejemplo n.º 1
0
    def test_whacking_at_loaders(self):
        """Some MixedModules change 'self.loaders' in __init__(), but doing
        so they incorrectly mutated a class attribute.  'loaders' is now a
        per-instance attribute, holding a fresh copy of the dictionary.
        """
        from pypy.interpreter.mixedmodule import MixedModule
        from pypy.conftest import maketestobjspace

        class MyModule(MixedModule):
            interpleveldefs = {}
            appleveldefs = {}
            def __init__(self, space, w_name):
                def loader(myspace):
                    assert myspace is space
                    return myspace.wrap("hello")
                MixedModule.__init__(self, space, w_name)
                self.loaders["hi"] = loader

        space1 = self.space
        w_mymod1 = MyModule(space1, space1.wrap('mymod'))

        space2 = maketestobjspace()
        w_mymod2 = MyModule(space2, space2.wrap('mymod'))

        w_str = space1.getattr(w_mymod1, space1.wrap("hi"))
        assert space1.str_w(w_str) == "hello"
Ejemplo n.º 2
0
    def test_whacking_at_loaders(self):
        """Some MixedModules change 'self.loaders' in __init__(), but doing
        so they incorrectly mutated a class attribute.  'loaders' is now a
        per-instance attribute, holding a fresh copy of the dictionary.
        """
        from pypy.interpreter.mixedmodule import MixedModule
        from pypy.conftest import maketestobjspace

        class MyModule(MixedModule):
            interpleveldefs = {}
            appleveldefs = {}

            def __init__(self, space, w_name):
                def loader(myspace):
                    assert myspace is space
                    return myspace.wrap("hello")

                MixedModule.__init__(self, space, w_name)
                self.loaders["hi"] = loader

        space1 = self.space
        w_mymod1 = MyModule(space1, space1.wrap('mymod'))

        space2 = maketestobjspace()
        w_mymod2 = MyModule(space2, space2.wrap('mymod'))

        w_str = space1.getattr(w_mymod1, space1.wrap("hi"))
        assert space1.str_w(w_str) == "hello"
Ejemplo n.º 3
0
    def setup_class(cls):
        from pypy import conftest
        from pypy.objspace.std import multimethod

        cls.prev_installer = multimethod.Installer
        multimethod.Installer = multimethod.InstallerVersion2
        config = conftest.make_config(conftest.option, **cls.OPTIONS)
        cls.space = conftest.maketestobjspace(config)
Ejemplo n.º 4
0
    def setup_class(cls):
        from pypy import conftest
        from pypy.objspace.std import multimethod

        cls.prev_installer = multimethod.Installer
        multimethod.Installer = multimethod.InstallerVersion2
        config = conftest.make_config(conftest.option, **cls.OPTIONS)
        cls.space = conftest.maketestobjspace(config)
Ejemplo n.º 5
0
    def setup_class(cls):
        from pypy import conftest
        from pypy.objspace.std import multimethod

        cls.prev_installer = multimethod.Installer
        multimethod.Installer = multimethod.InstallerVersion2
        if conftest.option.runappdirect:
            py.test.skip("Cannot run different installers when runappdirect")
        config = conftest.make_config(conftest.option, **cls.OPTIONS)
        cls.space = conftest.maketestobjspace(config)
Ejemplo n.º 6
0
    def setup_class(cls):
        from pypy import conftest
        from pypy.objspace.std import multimethod

        cls.prev_installer = multimethod.Installer
        multimethod.Installer = multimethod.InstallerVersion2
        if conftest.option.runappdirect:
            py.test.skip("Cannot run different installers when runappdirect")
        config = conftest.make_config(conftest.option, **cls.OPTIONS)
        cls.space = conftest.maketestobjspace(config)
Ejemplo n.º 7
0
def setup_module(mod):
    if option.runappdirect:
        py.test.skip("messes up the internal state of the compiler")
    # we NEED a fresh space, otherwise the messed-up compiler might
    # show up for the other test files and then we get extremely
    # confused (speaking from experience here)
    space = maketestobjspace()
    mod.space = space
    p = udir.join('test_aop')
    p.ensure(dir=1)
    # Note that sample_aop_code.py expects the temp dir to be in sys.path[0].
    space.call_method(space.sys.get('path'), 'insert',
                      space.wrap(0),
                      space.wrap(str(p)))