fix test_importall to not stop on skipped plugins and fix the uncovered failure of genscript: standalone.py template is now safely importable

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-01-15 18:45:06 +01:00
parent 4a568f43fe
commit 76e49b57bf
2 changed files with 21 additions and 19 deletions

View File

@ -8,18 +8,10 @@ import base64
import zlib import zlib
import imp import imp
if sys.version_info >= (3,0):
exec("def do_exec(co, loc): exec(co, loc)\n")
import pickle
sources = sources.encode("ascii") # ensure bytes
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
else:
import cPickle as pickle
exec("def do_exec(co, loc): exec co in loc\n")
sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
class DictImporter(object): class DictImporter(object):
sources = sources def __init__(self, sources):
self.sources = sources
def find_module(self, fullname, path=None): def find_module(self, fullname, path=None):
if fullname in self.sources: if fullname in self.sources:
return self return self
@ -53,12 +45,19 @@ class DictImporter(object):
res = self.sources.get(name+'.__init__') res = self.sources.get(name+'.__init__')
return res return res
importer = DictImporter()
sys.meta_path.append(importer)
if __name__ == "__main__": if __name__ == "__main__":
if sys.version_info >= (3,0):
exec("def do_exec(co, loc): exec(co, loc)\n")
import pickle
sources = sources.encode("ascii") # ensure bytes
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
else:
import cPickle as pickle
exec("def do_exec(co, loc): exec co in loc\n")
sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
importer = DictImporter(sources)
sys.meta_path.append(importer)
import py import py
py.cmdline.pytest() py.cmdline.pytest()

View File

@ -1,6 +1,7 @@
import py import py
import types import types
import sys import sys
from py._test.outcome import Skipped
def checksubpackage(name): def checksubpackage(name):
obj = getattr(py, name) obj = getattr(py, name)
@ -29,7 +30,6 @@ def test_importall():
nodirs = [ nodirs = [
base.join('_path', 'gateway',), base.join('_path', 'gateway',),
base.join('_code', 'oldmagic.py'), base.join('_code', 'oldmagic.py'),
base.join('_compat', 'testing'),
] ]
if sys.version_info >= (3,0): if sys.version_info >= (3,0):
nodirs.append(base.join('_code', '_assertionold.py')) nodirs.append(base.join('_code', '_assertionold.py'))
@ -50,7 +50,10 @@ def test_importall():
else: else:
relpath = relpath.replace(base.sep, '.') relpath = relpath.replace(base.sep, '.')
modpath = 'py.%s' % relpath modpath = 'py.%s' % relpath
check_import(modpath) try:
check_import(modpath)
except Skipped:
pass
def check_import(modpath): def check_import(modpath):
py.builtin.print_("checking import", modpath) py.builtin.print_("checking import", modpath)