Пример #1
0
def checkmodule(*modnames, **kwds):
    translate_startup = kwds.pop('translate_startup', True)
    ignore = set(kwds.pop('ignore', ()))
    assert not kwds
    config = get_pypy_config(translating=True)
    space = FakeObjSpace(config)
    seeobj_w = []
    modules = []
    for modname in modnames:
        mod = __import__('pypy.module.%s' % modname, None, None, ['__doc__'])
        # force computation and record what we wrap
        module = mod.Module(space, W_Root())
        module.setup_after_space_initialization()
        module.init(space)
        modules.append(module)
        for name in module.loaders:
            if name in ignore:
                continue
            seeobj_w.append(module._load_lazily(space, name))
        if hasattr(module, 'submodules'):
            for cls in module.submodules.itervalues():
                submod = cls(space, W_Root())
                for name in submod.loaders:
                    seeobj_w.append(submod._load_lazily(space, name))
    #
    def func():
        for mod in modules:
            mod.startup(space)

    if not translate_startup:
        func()  # call it now
        func = None
    space.translates(func,
                     seeobj_w=seeobj_w,
                     **{'translation.list_comprehension_operations': True})
Пример #2
0
def checkmodule(modname):
    config = get_pypy_config(translating=True)
    space = FakeObjSpace(config)
    mod = __import__('pypy.module.%s' % modname, None, None, ['__doc__'])
    # force computation and record what we wrap
    module = mod.Module(space, W_Root())
    for name in module.loaders:
        module._load_lazily(space, name)
    #
    space.translates(**{'translation.list_comprehension_operations':True})
Пример #3
0
def checkmodule(*modnames):
    config = get_pypy_config(translating=True)
    space = FakeObjSpace(config)
    seeobj_w = []
    for modname in modnames:
        mod = __import__('pypy.module.%s' % modname, None, None, ['__doc__'])
        # force computation and record what we wrap
        module = mod.Module(space, W_Root())
        module.startup(space)
        for name in module.loaders:
            seeobj_w.append(module._load_lazily(space, name))
        if hasattr(module, 'submodules'):
            for cls in module.submodules.itervalues():
                submod = cls(space, W_Root())
                for name in submod.loaders:
                    seeobj_w.append(submod._load_lazily(space, name))
    #
    space.translates(seeobj_w=seeobj_w,
                     **{'translation.list_comprehension_operations': True})
Пример #4
0
 def test_methodtable(self):
     space = self.space
     for fixed_arity in [1, 2, 3, 4]:
         #
         methodtable = [name for (name, _, arity, _) in space.MethodTable
                             if arity == fixed_arity]
         methodtable = unrolling_iterable(methodtable)
         args_w = (W_Root(),) * fixed_arity
         #
         def f():
             for name in methodtable:
                 getattr(space, name)(*args_w)
         #
         space.translates(f)
Пример #5
0
def checkmodule(modname,
                translate_startup=True,
                ignore=(),
                c_compile=False,
                extra_func=None,
                rpython_opts=None,
                pypy_opts=None,
                show_pdbplus=False):
    """
    Check that the module 'modname' translates.

    Options:
      translate_startup: TODO, document me

      ignore:       list of module interpleveldefs/appleveldefs to ignore

      c_compile:    determine whether to inokve the C compiler after rtyping

      extra_func:   extra function which will be annotated and called. It takes
                    a single "space" argment

      rpython_opts: dictionariy containing extra configuration options
      pypy_opts:    dictionariy containing extra configuration options

      show_pdbplus: show Pdb+ prompt on error. Useful for pdb commands such as
                    flowg, callg, etc.
    """
    config = get_pypy_config(translating=True)
    if pypy_opts:
        config.set(**pypy_opts)
    space = FakeObjSpace(config)
    seeobj_w = []
    modules = []
    modnames = [modname]
    for modname in modnames:
        mod = __import__('pypy.module.%s.moduledef' % modname, None, None,
                         ['__doc__'])
        # force computation and record what we wrap
        module = mod.Module(space, W_Root())
        module.setup_after_space_initialization()
        module.init(space)
        modules.append(module)
        for name in module.loaders:
            if name in ignore:
                continue
            seeobj_w.append(module._load_lazily(space, name))
        if hasattr(module, 'submodules'):
            for cls in module.submodules.itervalues():
                submod = cls(space, W_Root())
                for name in submod.loaders:
                    seeobj_w.append(submod._load_lazily(space, name))
    #
    def func():
        for mod in modules:
            mod.startup(space)

    if not translate_startup:
        func()  # call it now
        func = None

    opts = {'translation.list_comprehension_operations': True}
    if rpython_opts:
        opts.update(rpython_opts)

    try:
        space.translates(func,
                         seeobj_w=seeobj_w,
                         c_compile=c_compile,
                         extra_func=extra_func,
                         **opts)
    except:
        if not show_pdbplus:
            raise
        print
        exc, val, tb = sys.exc_info()
        traceback.print_exc()
        sys.pdbplus = p = PdbPlusShow(space.t)
        p.start(tb)
    else:
        if show_pdbplus:
            sys.pdbplus = p = PdbPlusShow(space.t)
            p.start(None)
Пример #6
0
 def test_default_values(self):
     # the __get__ method takes either 2 or 3 arguments
     space = self.space
     space.translates(lambda: (space.get(W_Root(), W_Root()),
                               space.get(W_Root(), W_Root(), W_Root())))
Пример #7
0
 def test_newlist(self):
     self.space.newlist([W_Root(), W_Root()])
Пример #8
0
 def test_unpackiterable(self):
     space = self.space
     space.translates(lambda: (space.unpackiterable(W_Root()),
                               space.unpackiterable(W_Root(), 42)))
Пример #9
0
 def test_is_true(self):
     space = self.space
     space.translates(lambda: space.is_true(W_Root()))
     py.test.raises(AssertionError, space.translates,
                    lambda: space.is_true(42))
Пример #10
0
 def test_call_args(self):
     space = self.space
     args = Arguments(space, [W_Root()])
     space.translates(lambda: space.call_args(W_Root(), args))