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:
holger krekel
2009-08-25 16:14:15 +02:00
parent 739edc26b4
commit d43d69e3db
33 changed files with 230 additions and 989 deletions

View File

@@ -1,160 +0,0 @@
SVN-fs-dump-format-version: 2
UUID: 9cb23565-b10c-0410-b2e2-dde77f08022e
Revision-number: 0
Prop-content-length: 56
Content-length: 56
K 8
svn:date
V 27
2006-02-13T18:39:13.605561Z
PROPS-END
Revision-number: 1
Prop-content-length: 111
Content-length: 111
K 7
svn:log
V 13
A testdir
K 10
svn:author
V 3
hpk
K 8
svn:date
V 27
2006-02-13T18:39:27.723346Z
PROPS-END
Node-path: testdir
Node-kind: dir
Node-action: add
Prop-content-length: 10
Content-length: 10
PROPS-END
Revision-number: 2
Prop-content-length: 111
Content-length: 111
K 7
svn:log
V 13
_M testdir
K 10
svn:author
V 3
hpk
K 8
svn:date
V 27
2006-02-13T18:39:48.595729Z
PROPS-END
Node-path: testdir
Node-kind: dir
Node-action: change
Prop-content-length: 28
Content-length: 28
K 4
key1
V 4
val2
PROPS-END
Revision-number: 3
Prop-content-length: 113
Content-length: 113
K 7
svn:log
V 15
AM testdir2
K 10
svn:author
V 3
hpk
K 8
svn:date
V 27
2006-02-13T18:40:53.307540Z
PROPS-END
Node-path: testdir2
Node-kind: dir
Node-action: add
Prop-content-length: 28
Content-length: 28
K 4
key2
V 4
val2
PROPS-END
Revision-number: 4
Prop-content-length: 113
Content-length: 113
K 7
svn:log
V 15
D testdir2
K 10
svn:author
V 3
hpk
K 8
svn:date
V 27
2006-02-13T18:41:07.188024Z
PROPS-END
Node-path: testdir2
Node-action: delete
Revision-number: 5
Prop-content-length: 112
Content-length: 112
K 7
svn:log
V 14
_M testdir
K 10
svn:author
V 3
hpk
K 8
svn:date
V 27
2006-02-13T18:42:03.179177Z
PROPS-END
Node-path: testdir
Node-kind: dir
Node-action: change
Prop-content-length: 10
Content-length: 10
PROPS-END

View File

@@ -1,55 +0,0 @@
from py.test import raises
import py
import sys
import inspect
def test_all_resolves():
seen = py.builtin.set([py])
lastlength = None
while len(seen) != lastlength:
lastlength = len(seen)
for item in py.builtin.frozenset(seen):
for value in item.__dict__.values():
if isinstance(value, type(py.test)):
seen.add(value)
class TestAPI_V0_namespace_consistence:
def test_path_entrypoints(self):
assert inspect.ismodule(py.path)
assert_class('py.path', 'local')
assert_class('py.path', 'svnwc')
assert_class('py.path', 'svnurl')
def test_magic_entrypoints(self):
assert_function('py.magic', 'invoke')
assert_function('py.magic', 'revoke')
assert_function('py.magic', 'patch')
assert_function('py.magic', 'revoke')
def test_process_entrypoints(self):
assert_function('py.process', 'cmdexec')
def XXXtest_utest_entrypoints(self):
# XXX TOBECOMPLETED
assert_function('py.test', 'main')
#assert_module('std.utest', 'collect')
def assert_class(modpath, name):
mod = __import__(modpath, None, None, [name])
obj = getattr(mod, name)
assert inspect.isclass(obj)
# we don't test anymore that the exported classes have
# the exported module path and name on them.
#fullpath = modpath + '.' + name
#assert obj.__module__ == modpath
#if sys.version_info >= (2,3):
# assert obj.__name__ == name
def assert_function(modpath, name):
mod = __import__(modpath, None, None, [name])
obj = getattr(mod, name)
assert hasattr(obj, 'func_doc')
#assert obj.func_name == name

View File

@@ -1,194 +0,0 @@
import py
import os
from py.__._com import Registry, MultiCall, HookRelay, varnames
def test_varnames():
def f(x):
pass
class A:
def f(self, y):
pass
assert varnames(f) == ("x",)
assert varnames(A.f) == ('y',)
assert varnames(A().f) == ('y',)
class TestMultiCall:
def test_uses_copy_of_methods(self):
l = [lambda: 42]
mc = MultiCall(l, {})
repr(mc)
l[:] = []
res = mc.execute()
return res == 42
def test_call_passing(self):
class P1:
def m(self, __multicall__, x):
assert len(__multicall__.results) == 1
assert not __multicall__.methods
return 17
class P2:
def m(self, __multicall__, x):
assert __multicall__.results == []
assert __multicall__.methods
return 23
p1 = P1()
p2 = P2()
multicall = MultiCall([p1.m, p2.m], {'x': 23})
assert "23" in repr(multicall)
reslist = multicall.execute()
assert len(reslist) == 2
# ensure reversed order
assert reslist == [23, 17]
def test_keyword_args(self):
def f(x):
return x + 1
class A:
def f(self, x, y):
return x + y
multicall = MultiCall([f, A().f], dict(x=23, y=24))
assert "'x': 23" in repr(multicall)
assert "'y': 24" in repr(multicall)
reslist = multicall.execute()
assert reslist == [24+23, 24]
assert "2 results" in repr(multicall)
def test_keywords_call_error(self):
multicall = MultiCall([lambda x: x], {})
py.test.raises(TypeError, "multicall.execute()")
def test_call_subexecute(self):
def m(__multicall__):
subresult = __multicall__.execute()
return subresult + 1
def n():
return 1
call = MultiCall([n, m], {}, firstresult=True)
res = call.execute()
assert res == 2
def test_call_none_is_no_result(self):
def m1():
return 1
def m2():
return None
res = MultiCall([m1, m2], {}, firstresult=True).execute()
assert res == 1
res = MultiCall([m1, m2], {}).execute()
assert res == [1]
class TestRegistry:
def test_register(self):
registry = Registry()
class MyPlugin:
pass
my = MyPlugin()
registry.register(my)
assert list(registry) == [my]
my2 = MyPlugin()
registry.register(my2)
assert list(registry) == [my, my2]
assert registry.isregistered(my)
assert registry.isregistered(my2)
registry.unregister(my)
assert not registry.isregistered(my)
assert list(registry) == [my2]
def test_listattr(self):
plugins = Registry()
class api1:
x = 41
class api2:
x = 42
class api3:
x = 43
plugins.register(api1())
plugins.register(api2())
plugins.register(api3())
l = list(plugins.listattr('x'))
assert l == [41, 42, 43]
l = list(plugins.listattr('x', reverse=True))
assert l == [43, 42, 41]
class api4:
x = 44
l = list(plugins.listattr('x', extra=(api4,)))
assert l == range(41, 45)
assert len(list(plugins)) == 3 # otherwise extra added
def test_api_and_defaults():
assert isinstance(py._com.comregistry, Registry)
class TestHookRelay:
def test_happypath(self):
registry = Registry()
class Api:
def hello(self, arg):
pass
mcm = HookRelay(hookspecs=Api, registry=registry)
assert hasattr(mcm, 'hello')
assert repr(mcm.hello).find("hello") != -1
class Plugin:
def hello(self, arg):
return arg + 1
registry.register(Plugin())
l = mcm.hello(arg=3)
assert l == [4]
assert not hasattr(mcm, 'world')
def test_only_kwargs(self):
registry = Registry()
class Api:
def hello(self, arg):
pass
mcm = HookRelay(hookspecs=Api, registry=registry)
py.test.raises(TypeError, "mcm.hello(3)")
def test_firstresult_definition(self):
registry = Registry()
class Api:
def hello(self, arg): pass
hello.firstresult = True
mcm = HookRelay(hookspecs=Api, registry=registry)
class Plugin:
def hello(self, arg):
return arg + 1
registry.register(Plugin())
res = mcm.hello(arg=3)
assert res == 4
def test_default_plugins(self):
class Api: pass
mcm = HookRelay(hookspecs=Api, registry=py._com.comregistry)
assert mcm._registry == py._com.comregistry
def test_hooks_extra_plugins(self):
registry = Registry()
class Api:
def hello(self, arg):
pass
hookrelay = HookRelay(hookspecs=Api, registry=registry)
hook_hello = hookrelay.hello
class Plugin:
def hello(self, arg):
return arg + 1
registry.register(Plugin())
class Plugin2:
def hello(self, arg):
return arg + 2
newhook = hookrelay._makecall("hello", extralookup=Plugin2())
l = newhook(arg=3)
assert l == [5, 4]
l2 = hook_hello(arg=3)
assert l2 == [4]

View File

@@ -1,26 +0,0 @@
import py
import errno
def test_error_classes():
for name in errno.errorcode.values():
x = getattr(py.error, name)
assert issubclass(x, py.error.Error)
assert issubclass(x, EnvironmentError)
def test_unknown_error():
num = 3999
cls = py.error._geterrnoclass(num)
assert cls.__name__ == 'UnknownErrno%d' % (num,)
assert issubclass(cls, py.error.Error)
assert issubclass(cls, EnvironmentError)
cls2 = py.error._geterrnoclass(num)
assert cls is cls2
def test_error_conversion_ENOTDIR(testdir):
p = testdir.makepyfile("")
excinfo = py.test.raises(py.error.Error, py.error.checked_call, p.listdir)
assert isinstance(excinfo.value, EnvironmentError)
assert isinstance(excinfo.value, py.error.Error)
assert "ENOTDIR" in repr(excinfo.value)

View File

@@ -1,176 +0,0 @@
from __future__ import generators
import py
import types
import sys
def checksubpackage(name):
obj = getattr(py, name)
if hasattr(obj, '__map__'): # isinstance(obj, Module):
keys = dir(obj)
assert len(keys) > 0
assert getattr(obj, '__map__') == {}
def test_dir():
from py.__.initpkg import ApiModule
for name in dir(py):
if name == 'magic': # greenlets don't work everywhere, we don't care here
continue
if not name.startswith('_'):
yield checksubpackage, name
from py.initpkg import ApiModule
glob = []
class MyModule(ApiModule):
def __init__(self, *args):
glob.append(self.__dict__)
assert isinstance(glob[-1], (dict, type(None)))
ApiModule.__init__(self, *args)
def test_early__dict__access():
mymod = MyModule("whatever", "myname")
assert isinstance(mymod.__dict__, dict)
def test_resolve_attrerror():
extpyish = "./initpkg.py", "hello"
excinfo = py.test.raises(AttributeError, "py.__pkg__._resolve(extpyish)")
s = str(excinfo.value)
assert s.find(extpyish[0]) != -1
assert s.find(extpyish[1]) != -1
def test_virtual_module_identity():
from py import path as path1
from py import path as path2
assert path1 is path2
from py.path import local as local1
from py.path import local as local2
assert local1 is local2
def test_importall():
base = py.path.local(py.__file__).dirpath()
nodirs = (
base.join('test', 'testing', 'data'),
base.join('apigen', 'tracer', 'testing', 'package'),
base.join('test', 'testing', 'test'),
base.join('test', 'rsession', 'webjs.py'),
base.join('apigen', 'source', 'server.py'),
base.join('magic', 'greenlet.py'),
base.join('path', 'gateway',),
base.join('doc',),
base.join('rest', 'directive.py'),
base.join('test', 'testing', 'import_test'),
base.join('c-extension',),
base.join('test', 'report', 'web.py'),
base.join('test', 'report', 'webjs.py'),
base.join('test', 'report', 'rest.py'),
base.join('magic', 'greenlet.py'),
base.join('bin'),
base.join('execnet', 'script'),
base.join('compat', 'testing'),
)
def recurse(p):
return p.check(dotfile=0) and p.basename != "attic"
for p in base.visit('*.py', recurse):
if p.basename == '__init__.py':
continue
relpath = p.new(ext='').relto(base)
if base.sep in relpath: # not py/*.py itself
for x in nodirs:
if p == x or p.relto(x):
break
else:
relpath = relpath.replace(base.sep, '.')
modpath = 'py.__.%s' % relpath
yield check_import, modpath
def check_import(modpath):
print "checking import", modpath
assert __import__(modpath)
#
# test support for importing modules
#
class TestRealModule:
def setup_class(cls):
cls.tmpdir = py.test.ensuretemp('test_initpkg')
sys.path = [str(cls.tmpdir)] + sys.path
pkgdir = cls.tmpdir.ensure('realtest', dir=1)
tfile = pkgdir.join('__init__.py')
tfile.write(py.code.Source("""
import py
py.initpkg('realtest', {
'x.module.__doc__': ('./testmodule.py', '__doc__'),
'x.module': ('./testmodule.py', '*'),
})
"""))
tfile = pkgdir.join('testmodule.py')
tfile.write(py.code.Source("""
'test module'
__all__ = ['mytest0', 'mytest1', 'MyTest']
def mytest0():
pass
def mytest1():
pass
class MyTest:
pass
"""))
import realtest # need to mimic what a user would do
#py.initpkg('realtest', {
# 'module': ('./testmodule.py', None)
#})
def setup_method(self, *args):
"""Unload the test modules before each test."""
module_names = ['realtest', 'realtest.x', 'realtest.x.module']
for modname in module_names:
if modname in sys.modules:
del sys.modules[modname]
def test_realmodule(self):
"""Testing 'import realtest.x.module'"""
import realtest.x.module
assert 'realtest.x.module' in sys.modules
assert getattr(realtest.x.module, 'mytest0')
def test_realmodule_from(self):
"""Testing 'from test import module'."""
from realtest.x import module
assert getattr(module, 'mytest1')
def test_realmodule_star(self):
"""Testing 'from test.module import *'."""
tfile = self.tmpdir.join('startest.py')
tfile.write(py.code.Source("""
from realtest.x.module import *
globals()['mytest0']
globals()['mytest1']
globals()['MyTest']
"""))
import startest # an exception will be raise if an error occurs
def test_realmodule_dict_import(self):
"Test verifying that accessing the __dict__ invokes the import"
import realtest.x.module
moddict = realtest.x.module.__dict__
assert 'mytest0' in moddict
assert 'mytest1' in moddict
assert 'MyTest' in moddict
def test_realmodule___doc__(self):
"""test whether the __doc__ attribute is set properly from initpkg"""
import realtest.x.module
assert realtest.x.module.__doc__ == 'test module'
def test_autoimport():
from py.initpkg import autoimport
py.std.os.environ['AUTOTEST_AUTOIMPORT'] = "nonexistmodule"
py.test.raises(ImportError, "autoimport('autotest')")

View File

@@ -1,16 +0,0 @@
import py
def test_make_sdist_and_run_it(capfd, py_setup, venv):
try:
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__
except KeyboardInterrupt:
raise
except:
print capfd.readouterr()
raise
capfd.close()

View File

@@ -1,13 +0,0 @@
import py
def test_os():
import os
assert py.std.os is os
def test_import_error_converts_to_attributeerror():
py.test.raises(AttributeError, "py.std.xyzalskdj")
def test_std_gets_it():
for x in py.std.sys.modules:
assert x in py.std.__dict__

View File

@@ -1,60 +0,0 @@
import py
from py.__.misc import svnlook
data = py.magic.autopath().dirpath('data')
if py.path.local.sysfind('svnlook') is None or \
py.path.local.sysfind('svnadmin') is None:
py.test.skip("cannot test py.misc.svnlook, svn binaries not found")
def test_svnlook():
tempdir = py.test.ensuretemp("svnlook")
repo = tempdir.join("repo")
py.process.cmdexec('svnadmin create --fs-type fsfs "%s"' % repo)
py.process.cmdexec('svnadmin load "%s" < "%s"' %(repo,
data.join("svnlookrepo.dump")))
author = svnlook.author(repo, 1)
assert author == "hpk"
for item in svnlook.changed(repo, 1):
svnurl = item.svnurl()
assert item.revision == 1
assert (svnurl.strpath + "/") == "file://%s/%s" %(repo, item.path)
assert item.added
assert not item.modified
assert not item.propchanged
assert not item.deleted
assert item.path == "testdir/"
for item in svnlook.changed(repo, 2):
assert item.revision == 2
assert not item.added
assert not item.modified
assert item.propchanged
assert not item.deleted
assert item.path == "testdir/"
for item in svnlook.changed(repo, 3):
assert item.revision == 3
assert item.added
assert not item.modified
assert not item.propchanged
assert not item.deleted
assert item.path == "testdir2/"
for item in svnlook.changed(repo, 4):
assert item.revision == 4
assert not item.added
assert not item.modified
assert not item.propchanged
assert item.deleted
assert item.path == "testdir2/"
for item in svnlook.changed(repo, 5):
assert item.revision == 5
assert not item.added
assert not item.modified
assert item.propchanged
assert not item.deleted
assert item.path == "testdir/"

View File

@@ -1,25 +0,0 @@
import os
import py
from py.__.misc.terminal_helper import get_terminal_width
def test_terminal_width():
""" Dummy test for get_terminal_width
"""
assert get_terminal_width()
try:
import fcntl
except ImportError:
py.test.skip('fcntl not supported on this platform')
def f(*args):
raise ValueError
ioctl = fcntl.ioctl
fcntl.ioctl = f
try:
cols = os.environ.get('COLUMNS', None)
os.environ['COLUMNS'] = '42'
assert get_terminal_width() == 41
finally:
fcntl.ioctl = ioctl
if cols:
os.environ['COLUMNS'] = cols