[py-svn] r16241 - in py/dist/py: . bin documentation misc/testing path path/extpy path/extpy/testing path/local path/local/testing path/svn path/testing test test/terminal test/testing test/tkinter
hpk at codespeak.net
hpk at codespeak.net
Tue Aug 23 10:12:25 CEST 2005
Author: hpk
Date: Tue Aug 23 10:12:13 2005
New Revision: 16241
Added:
py/dist/py/test/deprecate.py (contents, props changed)
py/dist/py/test/testing/test_deprecated.py (contents, props changed)
Removed:
py/dist/py/test/testing/test_api.py
Modified:
py/dist/py/__init__.py
py/dist/py/bin/py.cleanup
py/dist/py/bin/py.countloc
py/dist/py/bin/py.lookup
py/dist/py/bin/py.rest
py/dist/py/documentation/test.txt
py/dist/py/misc/testing/test_initpkg.py
py/dist/py/path/common.py
py/dist/py/path/extpy/extpy.py
py/dist/py/path/extpy/testing/test_extpy.py
py/dist/py/path/local/local.py
py/dist/py/path/local/posix.py
py/dist/py/path/local/testing/test_posix.py
py/dist/py/path/svn/svncommon.py
py/dist/py/path/svn/wccommand.py
py/dist/py/path/testing/common.py
py/dist/py/path/testing/fscommon.py
py/dist/py/path/testing/test_api.py
py/dist/py/test/item.py
py/dist/py/test/terminal/remote.py
py/dist/py/test/testing/test_collect.py
py/dist/py/test/tkinter/util.py
Log:
- add a new py.test.deprecated_call method to test if
a given callable with args/kwargs produces a deprecation
warning.
- deprecate
py.path.checker(...)
use functions or lambda x: x.check(...) instead
- deprecate
py.path.X().get(commaseparatestring) in favour
of using the 'basename', 'purebasename' etc.pp. attributes
directly.
Modified: py/dist/py/__init__.py
==============================================================================
--- py/dist/py/__init__.py (original)
+++ py/dist/py/__init__.py Tue Aug 23 10:12:13 2005
@@ -23,10 +23,10 @@
# helpers for use from test functions or collectors
'test.raises' : ('./test/raises.py', 'raises'),
+ 'test.deprecated_call' : ('./test/deprecate.py', 'deprecated_call'),
'test.skip' : ('./test/item.py', 'skip'),
'test.fail' : ('./test/item.py', 'fail'),
'test.exit' : ('./test/session.py', 'exit'),
- 'test.skip_on_error' : ('./test/item.py', 'skip_on_error'),
'test.compat.TestCase' : ('./test/compat.py', 'TestCase'),
# configuration/initialization related test api
@@ -62,9 +62,9 @@
'path.svnurl' : ('./path/svn/urlcommand.py', 'SvnCommandPath'),
'path.local' : ('./path/local/local.py', 'LocalPath'),
'path.extpy' : ('./path/extpy/extpy.py', 'Extpy'),
- 'path.checker' : ('./path/common.py', 'checker'),
+ 'path.checker' : ('./path/common.py', 'checker'), # deprecated
- # some nice more or less magic APIs
+ # some nice slightly magic APIs
'magic.greenlet' : ('./magic/greenlet.py', 'greenlet'),
'magic.invoke' : ('./magic/invoke.py', 'invoke'),
'magic.revoke' : ('./magic/invoke.py', 'revoke'),
@@ -74,7 +74,7 @@
'magic.View' : ('./magic/viewtype.py', 'View'),
'magic.AssertionError' : ('./magic/assertion.py', 'AssertionError'),
- # generalized inspection API
+ # python inspection/code-generation API
'code.compile' : ('./code/source.py', 'compile_'),
'code.Source' : ('./code/source.py', 'Source'),
'code.Code' : ('./code/code.py', 'Code'),
@@ -116,6 +116,7 @@
'log.STDOUT' : ('./log/consumer.py', 'STDOUT'),
'log.STDERR' : ('./log/consumer.py', 'STDERR'),
+ # compatibility modules (taken from 2.4.1)
'compat.doctest' : ('./compat/doctest.py', '*'),
'compat.optparse' : ('./compat/optparse.py', '*'),
'compat.textwrap' : ('./compat/textwrap.py', '*'),
Modified: py/dist/py/bin/py.cleanup
==============================================================================
--- py/dist/py/bin/py.cleanup (original)
+++ py/dist/py/bin/py.cleanup Tue Aug 23 10:12:13 2005
@@ -8,5 +8,5 @@
else:
path = py.path.local()
print "cleaning path", path
-for x in path.visit('*.pyc', py.path.checker(dotfile=0)):
+for x in path.visit('*.pyc', lambda x: x.check(dotfile=0)):
x.remove()
Modified: py/dist/py/bin/py.countloc
==============================================================================
--- py/dist/py/bin/py.countloc (original)
+++ py/dist/py/bin/py.countloc Tue Aug 23 10:12:13 2005
@@ -29,8 +29,11 @@
args = ['.']
locations = [py.path.local(x) for x in args]
+ def nodot(p):
+ return p.check(dotfile=0)
+
for loc in locations:
- for x in loc.visit('*.py', py.path.checker(dotfile=0)):
+ for x in loc.visit('*.py', nodot):
bn = x.basename
if bn.startswith('test_') or bn.endswith('_test.py'):
testcounter.count(x)
Modified: py/dist/py/bin/py.lookup
==============================================================================
--- py/dist/py/bin/py.lookup (original)
+++ py/dist/py/bin/py.lookup Tue Aug 23 10:12:13 2005
@@ -5,7 +5,10 @@
string = py.std.sys.argv[1]
curdir = py.path.local()
-for x in curdir.visit('*.py', py.path.checker(dotfile=0)):
+def rec(p):
+ return p.check(dotfile=0)
+
+for x in curdir.visit('*.py', rec):
s = x.read()
if s.find(string) != -1:
lines = x.readlines()
Modified: py/dist/py/bin/py.rest
==============================================================================
--- py/dist/py/bin/py.rest (original)
+++ py/dist/py/bin/py.rest Tue Aug 23 10:12:13 2005
@@ -27,9 +27,12 @@
if not p.check():
log("path %s not found, ignoring" % p)
continue
+ def fil(p):
+ return p.check(fnmatch='*.txt', versioned=True)
+ def rec(p):
+ return p.check(dotfile=0)
if p.check(dir=1):
- for x in p.visit(fil=py.path.checker(fnmatch='*.txt', versioned=True),
- rec=py.path.checker(dotfile=0)):
+ for x in p.visit(fil, rec):
rest.process(x)
elif p.check(file=1):
rest.process(p)
Modified: py/dist/py/documentation/test.txt
==============================================================================
--- py/dist/py/documentation/test.txt (original)
+++ py/dist/py/documentation/test.txt Tue Aug 23 10:12:13 2005
@@ -224,6 +224,13 @@
def test_xxx(self):
...
+testing for deprecated APIs
+------------------------------
+
+In your tests you can use ``py.test.deprecated_call(func, *args, **kwargs)``
+to test that a particular function call triggers a DeprecationWarning.
+This is useful for testing phasing out of old APIs in your projects.
+
Managing test state across test modules, classes and methods
------------------------------------------------------------
Modified: py/dist/py/misc/testing/test_initpkg.py
==============================================================================
--- py/dist/py/misc/testing/test_initpkg.py (original)
+++ py/dist/py/misc/testing/test_initpkg.py Tue Aug 23 10:12:13 2005
@@ -51,7 +51,7 @@
base.join('execnet', 'script'),
base.join('compat'),
)
- for p in base.visit('*.py', py.path.checker(dotfile=0)):
+ for p in base.visit('*.py', lambda x: x.check(dotfile=0)):
relpath = p.new(ext='').relto(base)
if base.sep in relpath: # not py/*.py itself
for x in nodirs:
Modified: py/dist/py/path/common.py
==============================================================================
--- py/dist/py/path/common.py (original)
+++ py/dist/py/path/common.py Tue Aug 23 10:12:13 2005
@@ -17,7 +17,13 @@
return True
class checker:
+ """ deprecated: return checker callable checking for the given
+ kwargs-specified specification.
+ """
def __init__(self, **kwargs):
+ py.std.warnings.warn("py.path.checker is deprecated, construct "
+ "calls to pathobj.check() instead",
+ DeprecationWarning)
self.kwargs = kwargs
def __call__(self, p):
return p.check(**self.kwargs)
@@ -109,7 +115,7 @@
return p.check()
def basename(self):
- return self.get('basename')[0]
+ return self._getbyspec('basename')[0]
basename = property(basename, None, None, 'basename part of path')
def relto(self, relpath):
@@ -165,6 +171,12 @@
def __repr__(self):
return repr(str(self))
+ def get(self, spec):
+ """ deprecated, use _getbyspec if you really need it. """
+ py.std.warnings.warn("path.get() is deprecated",
+ DeprecationWarning)
+ return self._getbyspec(spec)
+
def visit(self, fil=None, rec=None, ignore=_dummyclass):
if isinstance(fil, str):
fil = fnmatch(fil)
@@ -273,11 +285,11 @@
return self.new(basename='').join(*args, **kwargs)
def ext(self):
- return self.get('ext')[0]
+ return self._getbyspec('ext')[0]
ext = property(ext, None, None, 'extension part of path')
def purebasename(self):
- return self.get('purebasename')[0]
+ return self._getbyspec('purebasename')[0]
purebasename = property(purebasename, None, None, 'basename without extension')
def read(self, mode='rb'):
Modified: py/dist/py/path/extpy/extpy.py
==============================================================================
--- py/dist/py/path/extpy/extpy.py (original)
+++ py/dist/py/path/extpy/extpy.py Tue Aug 23 10:12:13 2005
@@ -72,7 +72,7 @@
return cls(self.root, kw['basename'])
return cls(self.root, self.modpath)
- def get(self, spec):
+ def _getbyspec(self, spec):
l = []
modparts = self.modpath.split(self.sep)
for name in spec.split(','):
@@ -108,7 +108,7 @@
def listdir(self, fil=None, sort=True, **kw):
if kw:
if fil is None:
- fil = py.path.checker(**kw)
+ fil = lambda x: x.check(**kw)
else:
raise TypeError, "cannot take filter and keyword arguments"
elif isinstance(fil, str):
Modified: py/dist/py/path/extpy/testing/test_extpy.py
==============================================================================
--- py/dist/py/path/extpy/testing/test_extpy.py (original)
+++ py/dist/py/path/extpy/testing/test_extpy.py Tue Aug 23 10:12:13 2005
@@ -48,7 +48,7 @@
assert l[0] == path
def test_visit(self):
- l = list(self.root.visit(py.path.checker(basename='borgfunc')))
+ l = list(self.root.visit(lambda x: x.basename == 'borgfunc'))
assert len(l) == 1
obj = l[0]
assert str(obj).endswith('Nested.Class.borgfunc')
Modified: py/dist/py/path/local/local.py
==============================================================================
--- py/dist/py/path/local/local.py (original)
+++ py/dist/py/path/local/local.py Tue Aug 23 10:12:13 2005
@@ -85,7 +85,7 @@
|--| ext
"""
obj = object.__new__(self.__class__)
- drive, dirname, basename, purebasename,ext = self.get(
+ drive, dirname, basename, purebasename,ext = self._getbyspec(
"drive,dirname,basename,purebasename,ext")
if 'basename' in kw:
if 'purebasename' in kw or 'ext' in kw:
@@ -108,7 +108,7 @@
"%(drive)s%(dirname)s%(sep)s%(basename)s" % kw)
return obj
- def get(self, spec):
+ def _getbyspec(self, spec):
""" return a sequence of specified path parts. 'spec' is
a comma separated string containing path part names.
according to the following convention:
Modified: py/dist/py/path/local/posix.py
==============================================================================
--- py/dist/py/path/local/posix.py (original)
+++ py/dist/py/path/local/posix.py Tue Aug 23 10:12:13 2005
@@ -51,7 +51,7 @@
uid = getuserid(user)
gid = getgroupid(group)
if rec:
- for x in self.visit(rec=py.path.checker(link=0)):
+ for x in self.visit(rec=lambda x: x.check(link=0)):
if x.check(link=0):
self._callex(os.chown, str(x), uid, gid)
self._callex(os.chown, str(self), uid, gid)
Modified: py/dist/py/path/local/testing/test_posix.py
==============================================================================
--- py/dist/py/path/local/testing/test_posix.py (original)
+++ py/dist/py/path/local/testing/test_posix.py Tue Aug 23 10:12:13 2005
@@ -54,7 +54,7 @@
tmpdir = self.tmpdir
linkpath = tmpdir.join('test')
linkpath.mksymlinkto(tmpdir)
- visitor = tmpdir.visit(None, py.path.checker(link=0))
+ visitor = tmpdir.visit(None, lambda x: x.check(link=0))
assert list(visitor) == [linkpath]
def test_symlink_isdir(self):
@@ -138,7 +138,7 @@
def test_chmod_rec_int(self):
# XXX fragile test
print "self.root is", self.root
- recfilter = py.path.checker(dotfile=0, link=0)
+ recfilter = lambda x: x.check(dotfile=0, link=0)
oldmodes = {}
for x in self.root.visit(rec=recfilter):
oldmodes[x] = x.mode()
Modified: py/dist/py/path/svn/svncommon.py
==============================================================================
--- py/dist/py/path/svn/svncommon.py (original)
+++ py/dist/py/path/svn/svncommon.py Tue Aug 23 10:12:13 2005
@@ -5,6 +5,18 @@
import py
from py.__.path import common
+
+# XXX this helper not used yet (but should be for testing
+# if the underlying svn binary supports certain features)
+def _getsvnversion(ver=[]):
+ try:
+ return ver[0]
+ except:
+ v = py.process.cmdexec("svn -q --version")
+ v.strip()
+ ver.append(v)
+ return v
+
#_______________________________________________________________
class SvnPathBase(common.FSPathBase):
@@ -35,7 +47,7 @@
"""
obj = object.__new__(self.__class__)
obj.rev = kw.get('rev', self.rev)
- dirname, basename, purebasename, ext = self.get(
+ dirname, basename, purebasename, ext = self._getbyspec(
"dirname,basename,purebasename,ext")
if 'basename' in kw:
if 'purebasename' in kw or 'ext' in kw:
@@ -55,7 +67,7 @@
obj.strpath = "%(dirname)s" % kw
return obj
- def get(self, spec):
+ def _getbyspec(self, spec):
""" get specified parts of the path. 'arg' is a string
with comma separated path parts. The parts are returned
in exactly the order of the specification.
Modified: py/dist/py/path/svn/wccommand.py
==============================================================================
--- py/dist/py/path/svn/wccommand.py (original)
+++ py/dist/py/path/svn/wccommand.py Tue Aug 23 10:12:13 2005
@@ -157,13 +157,16 @@
if externals:
raise ValueError("XXX cannot perform status() "
"on external items yet")
+ else:
+ externals = ''
if rec:
rec= ''
else:
rec = '--non-recursive'
- if not externals:
- externals = '--ignore-externals'
+ # XXX does not work on all subversion versions
+ #if not externals:
+ # externals = '--ignore-externals'
if updates:
updates = '-u'
@@ -368,8 +371,8 @@
def open(self, mode='r'):
return open(self.strpath, mode)
- def get(self, spec):
- return self.localpath.get(spec)
+ def _getbyspec(self, spec):
+ return self.localpath._getbyspec(spec)
class Checkers(py.path.local.Checkers):
def __init__(self, path):
Modified: py/dist/py/path/testing/common.py
==============================================================================
--- py/dist/py/path/testing/common.py (original)
+++ py/dist/py/path/testing/common.py Tue Aug 23 10:12:13 2005
@@ -4,6 +4,9 @@
class CommonPathTests:
root = None # subclasses have to setup a 'root' attribute
+ def test_get_deprecation(self):
+ py.test.deprecated_call(self.root.get, "basename")
+
def test_constructor_equality(self):
p = self.root.__class__(self.root)
assert p == self.root
Modified: py/dist/py/path/testing/fscommon.py
==============================================================================
--- py/dist/py/path/testing/fscommon.py (original)
+++ py/dist/py/path/testing/fscommon.py Tue Aug 23 10:12:13 2005
@@ -1,8 +1,6 @@
import py
from py.__.path.testing import common
-checker = py.path.checker
-
def setuptestfs(path):
if path.join('samplefile').check():
return
@@ -60,7 +58,7 @@
def test_multiple_parts(self):
newpath = self.root.join('samplefile.py')
- dirname, purebasename, basename, ext = newpath.get(
+ dirname, purebasename, basename, ext = newpath._getbyspec(
'dirname,purebasename,basename,ext')
assert str(self.root).endswith(dirname) # be careful with win32 'drive'
assert purebasename == 'samplefile'
@@ -123,7 +121,7 @@
def test_visit_filesonly(self):
l = []
- for i in self.root.visit(checker(file=1)):
+ for i in self.root.visit(lambda x: x.check(file=1)):
l.append(i.relto(self.root))
assert not "sampledir" in l
assert self.root.sep.join(["sampledir", "otherfile"]) in l
@@ -136,14 +134,15 @@
def test_visit_nodotfiles(self):
l = []
- for i in self.root.visit(checker(dotfile=0)):
+ for i in self.root.visit(lambda x: x.check(dotfile=0)):
l.append(i.relto(self.root))
assert "sampledir" in l
assert self.root.sep.join(["sampledir", "otherfile"]) in l
assert not ".dotfile" in l
def test_endswith(self):
- chk = checker(endswith='pickle')
+ def chk(p):
+ return p.check(endswith="pickle")
assert not chk(self.root)
assert not chk(self.root.join('samplefile'))
assert chk(self.root.join('somepickle'))
Modified: py/dist/py/path/testing/test_api.py
==============================================================================
--- py/dist/py/path/testing/test_api.py (original)
+++ py/dist/py/path/testing/test_api.py Tue Aug 23 10:12:13 2005
@@ -13,6 +13,9 @@
y = eval(r)
assert y == p
+ def test_deprecated_checker(self):
+ py.test.deprecated_call(py.path.checker)
+
def test_defaultlocal(self):
p = path.local()
assert hasattr(p, 'atime')
Added: py/dist/py/test/deprecate.py
==============================================================================
--- (empty file)
+++ py/dist/py/test/deprecate.py Tue Aug 23 10:12:13 2005
@@ -0,0 +1,36 @@
+import py
+
+def deprecated_call(func, *args, **kwargs):
+ """ assert that calling func(*args, **kwargs)
+ triggers a DeprecationWarning.
+ """
+ oldfilters = py.std.warnings.filters[:]
+ onceregistry = py.std.warnings.onceregistry.copy()
+ try:
+ py.std.warnings.onceregistry.clear()
+ py.std.warnings.filterwarnings("error", category=DeprecationWarning)
+ try:
+ _ = func(*args, **kwargs)
+ except DeprecationWarning:
+ pass
+ else:
+ print __warningregistry__
+ raise AssertionError("%s not deprecated" % (func,))
+ finally:
+ py.std.warnings.filters[:] = oldfilters
+ py.std.warnings.onceregistry.clear()
+ py.std.warnings.onceregistry.update(onceregistry)
+
+def deprecated_call(func, *args, **kwargs):
+ l = []
+ oldwarn = py.std.warnings.warn_explicit
+ def warn_explicit(*args, **kwargs):
+ l.append(args)
+ oldwarn(*args, **kwargs)
+
+ py.magic.patch(py.std.warnings, 'warn_explicit', warn_explicit)
+ try:
+ _ = func(*args, **kwargs)
+ finally:
+ py.magic.revert(py.std.warnings, 'warn_explicit')
+ assert l
Modified: py/dist/py/test/item.py
==============================================================================
--- py/dist/py/test/item.py (original)
+++ py/dist/py/test/item.py Tue Aug 23 10:12:13 2005
@@ -106,16 +106,6 @@
__tracebackhide__ = True
raise py.test.Item.Skipped(msg=msg)
-def skip_on_error(func, *args, **kwargs):
- """ skip test if the given call fails. """
- __tracebackhide__ = True
- try:
- return func(*args, **kwargs)
- except Exception, e:
- s = py.code.ExceptionInfo().exconly()
- name = getattr(func, '__name__', func)
- py.test.skip("%s(...) -> %s" %(name, s.rstrip(), ))
-
def fail(msg="unknown failure"):
""" fail with the given Message. """
__tracebackhide__ = True
Modified: py/dist/py/test/terminal/remote.py
==============================================================================
--- py/dist/py/test/terminal/remote.py (original)
+++ py/dist/py/test/terminal/remote.py Tue Aug 23 10:12:13 2005
@@ -7,8 +7,9 @@
""" wait until project files are changed. """
def fil(p):
return p.ext in ('.py', '.c', '.h')
- #fil = py.path.checker(fnmatch='*.py')
- rec = py.path.checker(dotfile=0)
+ #fil = lambda x: x.check(fnmatch='*.py')
+ def rec(p):
+ return p.check(dotfile=0)
changed = False
for path in rootdir.visit(fil, rec):
oldstat = statcache.get(path, None)
Deleted: /py/dist/py/test/testing/test_api.py
==============================================================================
--- /py/dist/py/test/testing/test_api.py Tue Aug 23 10:12:13 2005
+++ (empty file)
@@ -1,16 +0,0 @@
-
-import py
-
-def test_skipfailure():
- def f():
- raise ValueError()
- excinfo = py.test.raises(
- py.test.Item.Skipped,
- "py.test.skip_on_error(f)")
- print excinfo
- assert str(excinfo).find("ValueError") != -1
-
-def test_skip_on_error_with_no_failure():
- def f():
- return 42
- assert py.test.skip_on_error(f) == 42
Modified: py/dist/py/test/testing/test_collect.py
==============================================================================
--- py/dist/py/test/testing/test_collect.py (original)
+++ py/dist/py/test/testing/test_collect.py Tue Aug 23 10:12:13 2005
@@ -49,7 +49,8 @@
def test_failing_import_directory():
class MyDirectory(py.test.collect.Directory):
- filefilter = py.path.checker(fnmatch='testspecial*.py')
+ def filefilter(self, p):
+ return p.check(fnmatch='testspecial*.py')
mydir = MyDirectory(datadir)
l = mydir.run()
assert len(l) == 1
Added: py/dist/py/test/testing/test_deprecated.py
==============================================================================
--- (empty file)
+++ py/dist/py/test/testing/test_deprecated.py Tue Aug 23 10:12:13 2005
@@ -0,0 +1,35 @@
+import py
+
+def dep(i):
+ if i == 0:
+ py.std.warnings.warn("is deprecated", DeprecationWarning)
+
+reg = {}
+def dep_explicit(i):
+ if i == 0:
+ py.std.warnings.warn_explicit("dep_explicit", category=DeprecationWarning,
+ filename="hello", lineno=3)
+
+def test_deprecated_call_raises():
+ py.test.raises(AssertionError,
+ "py.test.deprecated_call(dep, 3)")
+
+def test_deprecated_call():
+ py.test.deprecated_call(dep, 0)
+
+def test_deprecated_call_preserves():
+ r = py.std.warnings.onceregistry.copy()
+ f = py.std.warnings.filters[:]
+ test_deprecated_call_raises()
+ test_deprecated_call()
+ assert r == py.std.warnings.onceregistry
+ assert f == py.std.warnings.filters
+
+def test_deprecated_explicit_call_raises():
+ py.test.raises(AssertionError,
+ "py.test.deprecated_call(dep_explicit, 3)")
+
+def test_deprecated_explicit_call():
+ py.test.deprecated_call(dep_explicit, 0)
+ py.test.deprecated_call(dep_explicit, 0)
+
Modified: py/dist/py/test/tkinter/util.py
==============================================================================
--- py/dist/py/test/tkinter/util.py (original)
+++ py/dist/py/test/tkinter/util.py Tue Aug 23 10:12:13 2005
@@ -263,9 +263,10 @@
def check_files(self):
'''returns (changed files, deleted files)'''
- fil = py.path.checker(fnmatch='[!.]*.py')
- rec = py.path.checker(dotfile=0)
-
+ def fil(p):
+ return p.check(fnmatch='[!.]*.py')
+ def rec(p):
+ return p.check(dotfile=0)
files = []
for path in self.paths:
if path.check(file=1):
More information about the pytest-commit
mailing list