death to "misc" directories. moved most files out of py/misc, either to a
private attic or to other places in the lib. --HG-- branch : trunk
This commit is contained in:
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import py
|
||||
import inspect
|
||||
import types
|
||||
|
||||
def report_strange_docstring(name, obj):
|
||||
if obj.__doc__ is None:
|
||||
print "%s misses a docstring" % (name, )
|
||||
elif obj.__doc__ == "":
|
||||
print "%s has an empty" % (name, )
|
||||
elif "XXX" in obj.__doc__:
|
||||
print "%s has an 'XXX' in its docstring" % (name, )
|
||||
|
||||
def find_code(method):
|
||||
return getattr(getattr(method, "im_func", None), "func_code", None)
|
||||
|
||||
def report_different_parameter_names(name, cls):
|
||||
bases = cls.__mro__
|
||||
for base in bases:
|
||||
for attr in dir(base):
|
||||
meth1 = getattr(base, attr)
|
||||
code1 = find_code(meth1)
|
||||
if code1 is None:
|
||||
continue
|
||||
if not callable(meth1):
|
||||
continue
|
||||
if not hasattr(cls, attr):
|
||||
continue
|
||||
meth2 = getattr(cls, attr)
|
||||
code2 = find_code(meth2)
|
||||
if not callable(meth2):
|
||||
continue
|
||||
if code2 is None:
|
||||
continue
|
||||
args1 = inspect.getargs(code1)[0]
|
||||
args2 = inspect.getargs(code2)[0]
|
||||
for a1, a2 in zip(args1, args2):
|
||||
if a1 != a2:
|
||||
print "%s.%s have different argument names %s, %s than the version in %s" % (name, attr, a1, a2, base)
|
||||
|
||||
|
||||
def find_all_exported():
|
||||
stack = [(name, getattr(py, name)) for name in dir(py)[::-1]
|
||||
if not name.startswith("_") and name != "compat"]
|
||||
seen = {}
|
||||
exported = []
|
||||
while stack:
|
||||
name, obj = stack.pop()
|
||||
if id(obj) in seen:
|
||||
continue
|
||||
else:
|
||||
seen[id(obj)] = True
|
||||
exported.append((name, obj))
|
||||
if isinstance(obj, type) or isinstance(obj, type(py)):
|
||||
stack.extend([("%s.%s" % (name, s), getattr(obj, s)) for s in dir(obj)
|
||||
if len(s) <= 1 or not (s[0] == '_' and s[1] != '_')])
|
||||
return exported
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
all_exported = find_all_exported()
|
||||
print "strange docstrings"
|
||||
print "=================="
|
||||
print
|
||||
for name, obj in all_exported:
|
||||
if callable(obj):
|
||||
report_strange_docstring(name, obj)
|
||||
print "\n\ndifferent parameters"
|
||||
print "===================="
|
||||
print
|
||||
for name, obj in all_exported:
|
||||
if isinstance(obj, type):
|
||||
report_different_parameter_names(name, obj)
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import py
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
|
||||
#
|
||||
# experimental funcargs for venv/install-tests
|
||||
#
|
||||
|
||||
pytest_plugins = 'pytest_pytester',
|
||||
|
||||
def pytest_funcarg__venv(request):
|
||||
p = request.config.mktemp(request.function.__name__, numbered=True)
|
||||
venv = VirtualEnv(str(p))
|
||||
return venv
|
||||
|
||||
def pytest_funcarg__py_setup(request):
|
||||
testdir = request.getfuncargvalue('testdir')
|
||||
rootdir = py.path.local(py.__file__).dirpath().dirpath()
|
||||
setup = rootdir.join('setup.py')
|
||||
if not setup.check():
|
||||
py.test.skip("not found: %r" % setup)
|
||||
return SetupBuilder(setup, testdir.tmpdir)
|
||||
|
||||
class SetupBuilder:
|
||||
def __init__(self, setup_path, tmpdir):
|
||||
self.setup_path = setup_path
|
||||
self.tmpdir = tmpdir
|
||||
assert setup_path.check()
|
||||
|
||||
def make_sdist(self, destdir=None):
|
||||
temp = self.tmpdir.mkdir('dist')
|
||||
args = ['python', 'setup.py', 'sdist', '--dist-dir', str(temp)]
|
||||
old = self.setup_path.dirpath().chdir()
|
||||
try:
|
||||
subcall(args)
|
||||
finally:
|
||||
old.chdir()
|
||||
l = temp.listdir('py-*')
|
||||
assert len(l) == 1
|
||||
sdist = l[0]
|
||||
if destdir is None:
|
||||
destdir = self.setup_path.dirpath('build')
|
||||
assert destdir.check()
|
||||
else:
|
||||
destdir = py.path.local(destdir)
|
||||
target = destdir.join(sdist.basename)
|
||||
sdist.copy(target)
|
||||
return target
|
||||
|
||||
def subcall(args):
|
||||
if hasattr(subprocess, 'check_call'):
|
||||
subprocess.check_call(args)
|
||||
else:
|
||||
subprocess.call(args)
|
||||
# code taken from Ronny Pfannenschmidt's virtualenvmanager
|
||||
|
||||
class VirtualEnv(object):
|
||||
def __init__(self, path):
|
||||
#XXX: supply the python executable
|
||||
self.path = path
|
||||
|
||||
def __repr__(self):
|
||||
return "<VirtualEnv at %r>" %(self.path)
|
||||
|
||||
def _cmd(self, name):
|
||||
return os.path.join(self.path, 'bin', name)
|
||||
|
||||
def ensure(self):
|
||||
if not os.path.exists(self._cmd('python')):
|
||||
self.create()
|
||||
|
||||
def create(self, sitepackages=False):
|
||||
args = ['virtualenv', self.path]
|
||||
if not sitepackages:
|
||||
args.append('--no-site-packages')
|
||||
subcall(args)
|
||||
|
||||
def makegateway(self):
|
||||
python = self._cmd('python')
|
||||
return py.execnet.makegateway("popen//python=%s" %(python,))
|
||||
|
||||
def pcall(self, cmd, *args, **kw):
|
||||
self.ensure()
|
||||
return subprocess.call([
|
||||
self._cmd(cmd)
|
||||
] + list(args),
|
||||
**kw)
|
||||
|
||||
|
||||
def easy_install(self, *packages, **kw):
|
||||
args = []
|
||||
if 'index' in kw:
|
||||
index = kw['index']
|
||||
if isinstance(index, (list, tuple)):
|
||||
for i in index:
|
||||
args.extend(['-i', i])
|
||||
else:
|
||||
args.extend(['-i', index])
|
||||
|
||||
args.extend(packages)
|
||||
self.pcall('easy_install', *args)
|
||||
|
||||
|
||||
def test_make_sdist_and_run_it(py_setup, venv):
|
||||
sdist = py_setup.make_sdist(venv.path)
|
||||
venv.easy_install(str(sdist))
|
||||
gw = venv.makegateway()
|
||||
ch = gw.remote_exec("import py ; channel.send(py.__version__)")
|
||||
version = ch.receive()
|
||||
assert version == py.__version__
|
||||
Reference in New Issue
Block a user