[svn r57321] merging the event branch:
* moving in test, misc, code, io directories and py/__init__.py * py/bin/_find.py does not print to stderr anymore * a few fixes to conftest files in other dirs some more fixes and adjustments pending --HG-- branch : trunk
This commit is contained in:
1
py/misc/testing/__init__.py
Normal file
1
py/misc/testing/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
#
|
||||
160
py/misc/testing/data/svnlookrepo.dump
Normal file
160
py/misc/testing/data/svnlookrepo.dump
Normal 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
|
||||
|
||||
|
||||
44
py/misc/testing/test_api.py
Normal file
44
py/misc/testing/test_api.py
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
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')
|
||||
|
||||
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
|
||||
68
py/misc/testing/test_cache.py
Normal file
68
py/misc/testing/test_cache.py
Normal 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)
|
||||
20
py/misc/testing/test_error.py
Normal file
20
py/misc/testing/test_error.py
Normal 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
|
||||
|
||||
267
py/misc/testing/test_initpkg.py
Normal file
267
py/misc/testing/test_initpkg.py
Normal file
@@ -0,0 +1,267 @@
|
||||
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.__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'),
|
||||
)
|
||||
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.__pkg__.shahexdigest()
|
||||
assert len(hex) == 40
|
||||
|
||||
def test_getzipdata():
|
||||
s = py.__pkg__.getzipdata()
|
||||
|
||||
def test_getrev():
|
||||
if not py.path.local(py.__file__).dirpath('.svn').check():
|
||||
py.test.skip("py package is not a svn checkout")
|
||||
d = py.__pkg__.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.__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'
|
||||
|
||||
#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
|
||||
|
||||
def test_url_of_version():
|
||||
#py.test.skip("FAILING! - provide a proper URL or upload pylib tgz")
|
||||
from urllib import URLopener
|
||||
url = py.__pkg__.download_url
|
||||
if url.lower() == "xxx":
|
||||
assert py.__pkg__.version.find("alpha") != -1
|
||||
else:
|
||||
URLopener().open(url)
|
||||
|
||||
|
||||
19
py/misc/testing/test_oskill.py
Normal file
19
py/misc/testing/test_oskill.py
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
import py, sys
|
||||
|
||||
from py.__.misc.killproc import killproc
|
||||
|
||||
def test_win_killsubprocess():
|
||||
if sys.platform == 'win32' and not py.path.local.sysfind('taskkill'):
|
||||
py.test.skip("you\'re using an older version of windows, which "
|
||||
"doesn\'t support 'taskkill' - py.misc.killproc is not "
|
||||
"available")
|
||||
tmp = py.test.ensuretemp("test_win_killsubprocess")
|
||||
t = tmp.join("t.py")
|
||||
t.write("import time ; time.sleep(100)")
|
||||
proc = py.std.subprocess.Popen([sys.executable, str(t)])
|
||||
assert proc.poll() is None # no return value yet
|
||||
killproc(proc.pid)
|
||||
ret = proc.wait()
|
||||
assert ret != 0
|
||||
|
||||
13
py/misc/testing/test_std.py
Normal file
13
py/misc/testing/test_std.py
Normal 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__
|
||||
60
py/misc/testing/test_svnlook.py
Normal file
60
py/misc/testing/test_svnlook.py
Normal 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/"
|
||||
25
py/misc/testing/test_terminal.py
Normal file
25
py/misc/testing/test_terminal.py
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
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
|
||||
75
py/misc/testing/test_update_website.py
Normal file
75
py/misc/testing/test_update_website.py
Normal file
@@ -0,0 +1,75 @@
|
||||
import py
|
||||
import sys
|
||||
|
||||
here = py.magic.autopath().dirpath()
|
||||
update_website = here.join('../../bin/_update_website.py').pyimport()
|
||||
|
||||
def test_rsync():
|
||||
temp = py.test.ensuretemp('update_website_rsync')
|
||||
pkgpath = temp.join('pkg')
|
||||
apipath = temp.join('apigen')
|
||||
pkgpath.ensure('foo/bar.txt', file=True).write('baz')
|
||||
pkgpath.ensure('spam/eggs.txt', file=True).write('spam')
|
||||
apipath.ensure('api/foo.html', file=True).write('<html />')
|
||||
apipath.ensure('source/spam.html', file=True).write('<html />')
|
||||
|
||||
rsyncpath = temp.join('rsync')
|
||||
assert not rsyncpath.check()
|
||||
gateway = py.execnet.PopenGateway()
|
||||
update_website.rsync(pkgpath, apipath, gateway, rsyncpath.strpath)
|
||||
assert rsyncpath.check(dir=True)
|
||||
assert rsyncpath.join('pkg').check(dir=True)
|
||||
assert rsyncpath.join('pkg/spam/eggs.txt').read() == 'spam'
|
||||
assert rsyncpath.join('apigen').check(dir=True)
|
||||
assert rsyncpath.join('apigen/api/foo.html').read() == '<html />'
|
||||
|
||||
def setup_pkg(testname):
|
||||
temp = py.test.ensuretemp(testname)
|
||||
pkgpath = temp.ensure('pkg', dir=True)
|
||||
pyfile = pkgpath.ensure('mod.py').write(py.code.Source("""
|
||||
def foo(x):
|
||||
return x + 1
|
||||
"""))
|
||||
testfile = pkgpath.ensure('test/test_mod.py').write(py.code.Source("""
|
||||
from pkg.sub import foo
|
||||
def test_foo():
|
||||
assert foo(1) == 2
|
||||
"""))
|
||||
initfile = pkgpath.ensure('__init__.py').write(py.code.Source("""
|
||||
import py
|
||||
from py.__.initpkg import initpkg
|
||||
initpkg(__name__, exportdefs={
|
||||
'sub.foo': ('./mod.py', 'foo'),
|
||||
})
|
||||
"""))
|
||||
initfile = pkgpath.ensure('apigen/apigen.py').write(py.code.Source("""
|
||||
from py.__.apigen.apigen import build, \
|
||||
get_documentable_items_pkgdir as get_documentable_items
|
||||
"""))
|
||||
return pkgpath
|
||||
|
||||
def test_run_tests():
|
||||
if py.std.sys.platform == "win32":
|
||||
py.test.skip("update_website is not supposed to be run from win32")
|
||||
pkgpath = setup_pkg('update_website_run_tests')
|
||||
errors = update_website.run_tests(pkgpath,
|
||||
pkgpath.dirpath().join('apigen'),
|
||||
captureouterr=True)
|
||||
print errors
|
||||
assert not errors
|
||||
py.test.skip("Apigen turned off")
|
||||
assert pkgpath.join('../apigen').check(dir=True)
|
||||
assert pkgpath.join('../apigen/api/sub.foo.html').check(file=True)
|
||||
|
||||
def test_run_tests_failure():
|
||||
if py.std.sys.platform == "win32":
|
||||
py.test.skip("update_website is not supposed to be run from win32")
|
||||
pkgpath = setup_pkg('update_website_run_tests_failure')
|
||||
assert not pkgpath.join('../apigen').check(dir=True)
|
||||
py.test.skip("Apigen turned off")
|
||||
pkgpath.ensure('../apigen', file=True)
|
||||
errors = update_website.run_tests(pkgpath,
|
||||
pkgpath.dirpath().join('apigen'),
|
||||
captureouterr=True)
|
||||
assert errors # some error message
|
||||
|
||||
Reference in New Issue
Block a user