[svn r37264] create the new development trunk

--HG--
branch : trunk
This commit is contained in:
hpk
2007-01-24 15:24:01 +01:00
commit 5992a8ef21
435 changed files with 58640 additions and 0 deletions

View File

@@ -0,0 +1 @@
#

View File

@@ -0,0 +1,160 @@
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

@@ -0,0 +1,45 @@
from py.test import raises
import py
import sys
import inspect
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')
assert_class('py.path', 'extpy')
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

@@ -0,0 +1,68 @@
import py
from py.__.misc.cache import BuildcostAccessCache, AgingCache
class BasicCacheAPITest:
cache = None
def test_getorbuild(self):
val = self.cache.getorbuild(-42, lambda: 42)
assert val == 42
val = self.cache.getorbuild(-42, lambda: 23)
assert val == 42
def test_cache_get_key_error(self):
assert self.cache.getentry(-23) == None
def test_delentry_non_raising(self):
val = self.cache.getorbuild(100, lambda: 100)
self.cache.delentry(100)
assert self.cache.getentry(100) is None
def test_delentry_raising(self):
val = self.cache.getorbuild(100, lambda: 100)
self.cache.delentry(100)
py.test.raises(KeyError, "self.cache.delentry(100, raising=True)")
class TestBuildcostAccess(BasicCacheAPITest):
cache = BuildcostAccessCache(maxentries=128)
def test_cache_works_somewhat_simple(self):
cache = BuildcostAccessCache()
for x in range(cache.maxentries):
y = cache.getorbuild(x, lambda: x)
assert x == y
for x in range(cache.maxentries):
assert cache.getorbuild(x, None) == x
for x in range(cache.maxentries/2):
assert cache.getorbuild(x, None) == x
assert cache.getorbuild(x, None) == x
assert cache.getorbuild(x, None) == x
val = cache.getorbuild(cache.maxentries * 2, lambda: 42)
assert val == 42
# check that recently used ones are still there
# and are not build again
for x in range(cache.maxentries/2):
assert cache.getorbuild(x, None) == x
assert cache.getorbuild(cache.maxentries*2, None) == 42
class TestAging(BasicCacheAPITest):
maxsecs = 0.02
cache = AgingCache(maxentries=128, maxseconds=maxsecs)
def test_cache_eviction(self):
self.cache.getorbuild(17, lambda: 17)
endtime = py.std.time.time() + self.maxsecs * 10
while py.std.time.time() < endtime:
if self.cache.getentry(17) is None:
break
py.std.time.sleep(self.maxsecs*0.3)
else:
py.test.fail("waiting for cache eviction failed")
def test_prune_lowestweight():
maxsecs = 0.05
cache = AgingCache(maxentries=10, maxseconds=maxsecs)
for x in range(cache.maxentries):
cache.getorbuild(x, lambda: x)
py.std.time.sleep(maxsecs*1.1)
cache.getorbuild(cache.maxentries+1, lambda: 42)

View File

@@ -0,0 +1,20 @@
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

View File

@@ -0,0 +1,241 @@
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 Module
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 Module
glob = []
class MyModule(Module):
def __init__(self, *args):
glob.append(self.__dict__)
assert isinstance(glob[-1], (dict, type(None)))
Module.__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.__package__._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', 'tkinter'),
base.join('test', 'testing', 'data'),
base.join('test', 'testing', 'test'),
base.join('magic', 'greenlet.py'),
base.join('path', 'extpy', 'testing', 'test_data'),
base.join('path', 'gateway',),
base.join('doc',),
base.join('test', 'testing', 'import_test'),
base.join('c-extension',),
base.join('magic', 'greenlet.py'),
base.join('bin'),
base.join('execnet', 'script'),
base.join('compat'),
)
for p in base.visit('*.py', lambda x: x.check(dotfile=0)):
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)
def test_shahexdigest():
hex = py.__package__.shahexdigest()
assert len(hex) == 40
def test_getzipdata():
s = py.__package__.getzipdata()
def test_getrev():
d = py.__package__.getrev()
svnversion = py.path.local.sysfind('svnversion')
if svnversion is None:
py.test.skip("cannot test svnversion, 'svnversion' binary not found")
v = svnversion.sysexec(py.path.local(py.__file__).dirpath())
assert v.startswith(str(d))
# the following test should abasically work in the future
def XXXtest_virtual_on_the_fly():
py.initpkg('my', {
'x.abspath' : 'os.path.abspath',
'x.local' : 'py.path.local',
'y' : 'smtplib',
'z.cmdexec' : 'py.process.cmdexec',
})
from my.x import abspath
from my.x import local
import smtplib
from my import y
assert y is smtplib
from my.z import cmdexec
from py.process import cmdexec as cmdexec2
assert cmdexec is cmdexec2
#
# 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': ('./testmodule.py', '*'),
})
"""))
tfile = pkgdir.join('testmodule.py')
tfile.write(py.code.Source("""
__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
#class TestStdHook:
# """Tests imports for the standard Python library hook."""
#
# def setup_method(self, *args):
# """Unload the test modules before each test."""
# module_names = ['py.std.StringIO', 'py.std', 'py']
# for modname in module_names:
# if modname in sys.modules:
# del sys.modules[modname]
#
# def test_std_import_simple(self):
# import py
# StringIO = py.std.StringIO
# assert 'py' in sys.modules
# assert 'py.std' in sys.modules
# assert 'py.std.StringIO' in sys.modules
# assert hasattr(py.std.StringIO, 'StringIO')
#
# def test_std_import0(self):
# """Testing 'import py.std.StringIO'."""
# import py.std.StringIO
# assert 'py' in sys.modules
# assert 'py.std' in sys.modules
# assert 'py.std.StringIO' in sys.modules
# assert hasattr(py.std.StringIO, 'StringIO')
#
# def test_std_import1(self):
# """Testing 'from py import std'."""
# from py import std
# assert 'py' in sys.modules
# assert 'py.std' in sys.modules
#
# def test_std_from(self):
# """Testing 'from py.std import StringIO'."""
# from py.std import StringIO
# assert getattr(StringIO, 'StringIO')
#
# def test_std_star(self):
# "Test from py.std.string import *"
# """Testing 'from test.module import *'."""
# tmpdir = py.test.ensuretemp('test_initpkg')
# tfile = tmpdir.join('stdstartest.py')
# tfile.write(py.code.Source("""if True:
# from realtest.module import *
# globals()['mytest0']
# globals()['mytest1']
# globals()['MyTest']
# """))
# import stdstartest # an exception will be raise if an error occurs
##def test_help():
# help(std.path)
# #assert False

View File

@@ -0,0 +1,92 @@
import os, sys
import py
from py.__.misc.simplecapture import SimpleOutErrCapture, callcapture
from py.__.misc.capture import Capture, FDCapture
class TestFDCapture:
def test_basic(self):
tmpfile = py.std.os.tmpfile()
fd = tmpfile.fileno()
cap = FDCapture(fd)
os.write(fd, "hello")
f = cap.done()
s = f.read()
assert s == "hello"
def test_stderr(self):
cap = FDCapture(2, 'stderr')
print >>sys.stderr, "hello"
f = cap.done()
s = f.read()
assert s == "hello\n"
class TestCapturingOnSys:
def getcapture(self):
return SimpleOutErrCapture()
def test_capturing_simple(self):
cap = self.getcapture()
print "hello world"
print >>sys.stderr, "hello error"
out, err = cap.reset()
assert out == "hello world\n"
assert err == "hello error\n"
def test_capturing_twice_error(self):
cap = self.getcapture()
print "hello"
cap.reset()
py.test.raises(AttributeError, "cap.reset()")
def test_capturing_modify_sysouterr_in_between(self):
oldout = sys.stdout
olderr = sys.stderr
cap = self.getcapture()
print "hello",
print >>sys.stderr, "world",
sys.stdout = py.std.StringIO.StringIO()
sys.stderr = py.std.StringIO.StringIO()
print "not seen"
print >>sys.stderr, "not seen"
out, err = cap.reset()
assert out == "hello"
assert err == "world"
assert sys.stdout == oldout
assert sys.stderr == olderr
def test_capturing_error_recursive(self):
cap1 = self.getcapture()
print "cap1"
cap2 = self.getcapture()
print "cap2"
out2, err2 = cap2.reset()
py.test.raises(AttributeError, "cap2.reset()")
out1, err1 = cap1.reset()
assert out1 == "cap1\n"
assert out2 == "cap2\n"
def test_reading_stdin_while_captured_doesnt_hang(self):
cap = self.getcapture()
try:
py.test.raises(IOError, raw_input)
finally:
cap.reset()
def test_callcapture():
def func(x, y):
print x
print >>py.std.sys.stderr, y
return 42
res, out, err = callcapture(func, 3, y=4)
assert res == 42
assert out.startswith("3")
assert err.startswith("4")
class TestCapturingOnFDs(TestCapturingOnSys):
def test_reading_stdin_while_captured_doesnt_hang(self):
py.test.skip("Hangs in py.test --session=R")
def getcapture(self):
return Capture()

View File

@@ -0,0 +1,13 @@
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

@@ -0,0 +1,60 @@
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/"