[svn r37641] removing py.path.extpy after all

--HG--
branch : trunk
This commit is contained in:
hpk 2007-01-30 23:22:15 +01:00
parent e7c684eb37
commit e721d85278
14 changed files with 6 additions and 514 deletions

View File

@ -9,8 +9,8 @@ version = "0.8.80-alpha2"
initpkg(__name__, initpkg(__name__,
description = "py.test and the py lib", description = "py.test and the py lib",
revision = int('$LastChangedRevision: 37278 $'.split(':')[1][:-1]), revision = int('$LastChangedRevision: 37641 $'.split(':')[1][:-1]),
lastchangedate = '$LastChangedDate: 2007-01-24 17:46:46 +0100 (Wed, 24 Jan 2007) $', lastchangedate = '$LastChangedDate: 2007-01-30 23:22:15 +0100 (Tue, 30 Jan 2007) $',
version = version, version = version,
url = "http://codespeak.net/py", url = "http://codespeak.net/py",
download_url = "http://codespeak.net/download/py/%s.tar.gz" %(version,), download_url = "http://codespeak.net/download/py/%s.tar.gz" %(version,),
@ -61,7 +61,6 @@ initpkg(__name__,
'path.svnwc' : ('./path/svn/wccommand.py', 'SvnWCCommandPath'), 'path.svnwc' : ('./path/svn/wccommand.py', 'SvnWCCommandPath'),
'path.svnurl' : ('./path/svn/urlcommand.py', 'SvnCommandPath'), 'path.svnurl' : ('./path/svn/urlcommand.py', 'SvnCommandPath'),
'path.local' : ('./path/local/local.py', 'LocalPath'), 'path.local' : ('./path/local/local.py', 'LocalPath'),
'path.extpy' : ('./path/extpy/extpy.py', 'Extpy'),
# some nice slightly magic APIs # some nice slightly magic APIs
'magic.greenlet' : ('./magic/greenlet.py', 'greenlet'), 'magic.greenlet' : ('./magic/greenlet.py', 'greenlet'),

View File

@ -32,9 +32,9 @@ streamline exported API
* remove from public namespace: * remove from public namespace:
XXX consider py.magic. invoke/revoke/patch/revert XXX consider py.magic. invoke/revoke/patch/revert
(DONE) remove py.path.extpy
* make "_" namespace: * make "_" namespace:
py.path.extpy -> py.path._extpy
py.log -> py._log (pypy!) py.log -> py._log (pypy!)
* review py.io and write py.io.dupfile docstring * review py.io and write py.io.dupfile docstring
@ -97,7 +97,7 @@ testing
(guido tested all on win32, everything works except --dist (requires (guido tested all on win32, everything works except --dist (requires
os.fork to work)) os.fork to work))
* see why startcapture() does not use FD-based * see why startcapture() used to not use FD-based
"py.io.OutErrCapture" to isolate standard output. "py.io.OutErrCapture" to isolate standard output.
use that check if all py and PyPy tests pass use that check if all py and PyPy tests pass
as good as they do without. as good as they do without.
@ -118,7 +118,6 @@ distributed testing / RSession
------------------------------------ ------------------------------------
* (DONE, except apigen) cleanup initialisation of config / get rid of pkgdir * (DONE, except apigen) cleanup initialisation of config / get rid of pkgdir
* unify option names (dist_*)
* (optional) see if more of py/test/session.py's Session can be reused * (optional) see if more of py/test/session.py's Session can be reused
* (DONE, but slightly different way) * (DONE, but slightly different way)
have dist_rsyncroots be relative to the conftest.py file have dist_rsyncroots be relative to the conftest.py file
@ -291,25 +290,6 @@ Missing docstrings
path.local.__cmp__ misses a docstring path.local.__cmp__ misses a docstring
path.local.__add__ misses a docstring path.local.__add__ misses a docstring
path.local.Checkers misses a docstring path.local.Checkers misses a docstring
path.extpy.visit misses a docstring
path.extpy.samefile misses a docstring
path.extpy.relto misses a docstring
path.extpy.listobj misses a docstring
path.extpy.listdir misses a docstring
path.extpy.join misses a docstring
path.extpy.getpymodule misses a docstring
path.extpy.getfilelineno misses a docstring
path.extpy.dirpath misses a docstring
path.extpy.check misses a docstring
path.extpy.__str__ misses a docstring
path.extpy.__repr__ misses a docstring
path.extpy.__new__ misses a docstring
path.extpy.__iter__ misses a docstring
path.extpy.__hash__ misses a docstring
path.extpy.__contains__ misses a docstring
path.extpy.__cmp__ misses a docstring
path.extpy.__add__ misses a docstring
path.extpy.Checkers misses a docstring
test.rest.RestReporter misses a docstring test.rest.RestReporter misses a docstring
test.rest.RestReporter.summary misses a docstring test.rest.RestReporter.summary misses a docstring
test.rest.RestReporter.skips misses a docstring test.rest.RestReporter.skips misses a docstring

View File

@ -69,10 +69,6 @@ Example usage of :api:`py.path.svnwc`::
.. _`Subversion`: http://subversion.tigris.org/ .. _`Subversion`: http://subversion.tigris.org/
:api:`py.path.extpy`/gateway?
-----------------------------
XXX do we want any of this?
Common vs. specific API Common vs. specific API
======================= =======================

View File

@ -10,7 +10,6 @@ class TestAPI_V0_namespace_consistence:
assert_class('py.path', 'local') assert_class('py.path', 'local')
assert_class('py.path', 'svnwc') assert_class('py.path', 'svnwc')
assert_class('py.path', 'svnurl') assert_class('py.path', 'svnurl')
assert_class('py.path', 'extpy')
def test_magic_entrypoints(self): def test_magic_entrypoints(self):
assert_function('py.magic', 'invoke') assert_function('py.magic', 'invoke')

View File

@ -7,7 +7,7 @@ import os, sys
import py import py
def checktype(pathinstance, kw): def checktype(pathinstance, kw):
names = ('local', 'svnwc', 'svnurl', 'py', 'extpy') names = ('local', 'svnwc', 'svnurl', 'py', )
for name,value in kw.items(): for name,value in kw.items():
if name in names: if name in names:
cls = getattr(py.path, name) cls = getattr(py.path, name)

View File

@ -1 +0,0 @@
#

View File

@ -1,237 +0,0 @@
"""
A path to python objects located in filesystems.
Note: this is still experimental and may be removed
for the first stable release!
"""
from __future__ import generators
import py
from py.__.path import common
import sys
import inspect
moduletype = type(py)
class Extpy(common.PathBase):
""" path object for addressing python objects. """
sep = '.'
def __new__(cls, root, modpath=''):
if not isinstance(modpath, str):
raise TypeError("second 'modpath' argument must be a dotted name.")
if isinstance(root, str):
root = py.path.local(root)
self = object.__new__(cls)
if isinstance(root, Extpy):
# we don't want it nested, do we?
assert not modpath
root = root.root
self.modpath = modpath
self.root = root
return self
def __hash__(self):
return hash((self.root, self.modpath))
def __repr__(self):
return 'extpy(%r, %r)' % (self.root, self.modpath)
def __str__(self):
return "%s%s.%s" %(self.root, self.root.sep, self.modpath)
def join(self, *args):
for arg in args:
if not isinstance(arg, str):
raise TypeError, "non-strings not allowed in %r" % args
modpath = [x.strip('.') for x in ((self.modpath,)+args) if x]
modpath = self.sep.join(modpath)
return self.__class__(self.root, modpath)
def relto(self, other):
if self.root != other.root:
return ''
return super(Extpy, self).relto(other)
def dirpath(self, *args):
modpath = self.modpath.split(self.sep) [:-1]
modpath = self.sep.join(modpath+list(args))
return self.__class__(self.root, modpath)
def new(self, **kw):
""" create a modified version of this path.
the following keyword arguments modify various path parts:
modpath substitute module path
"""
cls = self.__class__
if 'modpath' in kw:
return cls(self.root, kw['modpath'])
if 'basename' in kw:
i = self.modpath.rfind('.')
if i != -1:
return cls(self.root, self.modpath[i+1:] + kw['basename'])
else:
return cls(self.root, kw['basename'])
return cls(self.root, self.modpath)
def _getbyspec(self, spec):
l = []
modparts = self.modpath.split(self.sep)
for name in spec.split(','):
if name == 'basename':
l.append(modparts[-1])
return l
def resolve(self):
"""return the python object, obtained from traversing from
the root along the modpath.
"""
rest = filter(None, self.modpath.split('.'))
target = self.getpymodule()
for name in rest:
try:
target = getattr(target, name)
except AttributeError:
raise py.error.ENOENT(target, name)
return target
def getpymodule(self):
if hasattr(self.root, 'resolve'):
return self.root.resolve()
else:
return self.root.getpymodule()
def listobj(self, fil=None, **kw):
l = []
for x in self.listdir(fil, **kw):
l.append(x.resolve())
return l
def listdir(self, fil=None, sort=True, **kw):
if kw:
if fil is None:
fil = lambda x: x.check(**kw)
else:
raise TypeError, "cannot take filter and keyword arguments"
elif isinstance(fil, str):
fil = common.fnmatch(fil)
obj = self.resolve()
l = []
#print "listdir on", self
if not hasattr(obj, '__dict__'):
raise py.error.ENOTDIR(self, "does not have a __dict__ attribute")
for name in dir(obj):
sub = self.join(name)
if not fil or fil(sub):
l.append(sub)
#print "listdir(%r) -> %r" %(self, l)
#print "listdir on", repr(self)
return l
def getfilelineno(self, scrapinit=0):
x = obj = self.resolve()
if inspect.ismodule(obj):
return obj.__file__, 0
if inspect.ismethod(obj):
obj = obj.im_func
if inspect.isfunction(obj):
obj = obj.func_code
if inspect.iscode(obj):
return py.path.local(obj.co_filename), obj.co_firstlineno - 1
else:
source, lineno = inspect.findsource(obj)
return x.getfile(), lineno - 1
def visit(self, fil=None, rec=None, ignore=None, seen=None):
def myrec(p, seen={id(self): True}):
if id(p) in seen:
return False
seen[id(p)] = True
if self.samefile(p):
return True
for x in super(Extpy, self).visit(fil=fil, rec=rec, ignore=ignore):
yield x
return
if seen is None:
seen = {id(self): True}
if isinstance(fil, str):
fil = common.fnmatch(fil)
if isinstance(rec, str):
rec = common.fnmatch(fil)
if ignore:
try:
l = self.listdir()
except ignore:
return
else:
l = self.listdir()
reclist = []
for p in l:
if fil is None or fil(p):
yield p
if id(p) not in seen:
try:
obj = p.resolve()
if inspect.isclass(obj) or inspect.ismodule(obj):
reclist.append(p)
finally:
seen[id(p)] = p
for p in reclist:
for i in p.visit(fil, rec, seen):
yield i
def samefile(self, other):
otherobj = other.resolve()
try:
x = inspect.getfile(otherobj)
except TypeError:
return False
if x.endswith('.pyc'):
x = x[:-1]
if str(self.root) == x:
return True
def read(self, mode='ignored'):
""" return a bytestring from looking at our underlying object.
mode parmeter exists for consistency, but is ignored."""
return str(self.resolve())
class Checkers(common.Checkers):
_depend_on_existence = (common.Checkers._depend_on_existence +
('func', 'class_', 'exists', 'dir'))
def _obj(self):
self._obj = self.path.resolve()
return self._obj
def exists(self):
obj = self._obj()
return True
def func(self):
ob = self._obj()
return inspect.isfunction(ob) or inspect.ismethod(ob)
def class_(self):
ob = self._obj()
return inspect.isclass(ob)
def isinstance(self, args):
return isinstance(self._obj(), args)
def dir(self):
obj = self._obj()
return inspect.isclass(obj) or inspect.ismodule(obj)
def file(self):
return not self.dir()
def genfunc(self):
try:
return self._obj().func_code.co_flags & 32
except AttributeError:
return False

View File

@ -1 +0,0 @@
#

View File

@ -1,12 +0,0 @@
samplefile = 'samplefile\n'
samplepickle = {}
class sampledir:
otherfile = 'otherfile'
class otherdir:
init = 42
class execfile:
x = 42

View File

@ -1,18 +0,0 @@
from __future__ import generators
class A:
x1 = 42
def func(self):
pass
def genfunc(self):
yield 2
class B:
x2 = 23
class Nested:
class Class:
def borgfunc(self): pass

View File

@ -1,7 +0,0 @@
test = True
if __name__ == '__main__':
pass
#############################################################################
# 2004 M.E.Farmer Jr.
# Python license

View File

@ -1,201 +0,0 @@
import os
import py
from py.__.path.testing import common
mypath = py.magic.autopath().dirpath('inc_test_extpy.py')
class TestExtPyCommonTests(common.CommonPathTests):
def setup_class(cls):
cls.root = py.path.extpy(
py.magic.autopath().dirpath('inc_pseudofs.py'))
def test_file(self):
assert self.root.join('samplefile').check(file=1)
assert self.root.join('otherdir').check(file=0)
class TestExtPy:
def setup_class(cls):
cls.root = py.path.extpy(mypath)
def test_join(self):
p = self.root.join('A')
obj = p.resolve()
assert hasattr(obj, '__bases__')
assert obj.x1 == 42
def test_listdir_module(self):
l = self.root.listdir()
basenames = [x.basename for x in l]
dlist = dir(self.root.resolve())
for name in dlist:
assert name in basenames
for name in basenames:
assert name in dlist
def test_listdir_class(self):
l = self.root.join('A').listdir()
basenames = [x.basename for x in l]
dlist = dir(self.root.resolve().A)
for name in dlist:
assert name in basenames
for name in basenames:
assert name in dlist
def listobj(self):
l = self.root.listobj(basestarts='path')
assert len(l) == 1
assert l[0] == path
def test_visit(self):
l = list(self.root.visit(lambda x: x.basename == 'borgfunc'))
assert len(l) == 1
obj = l[0]
assert str(obj).endswith('Nested.Class.borgfunc')
assert obj.resolve() == self.root.resolve().Nested.Class.borgfunc
def test_visit_fnmatch(self):
l = list(self.root.visit('borg*'))
assert len(l) == 1
obj = l[0]
assert str(obj).endswith('Nested.Class.borgfunc')
assert obj.resolve() == self.root.resolve().Nested.Class.borgfunc
#def test_join_from_empty(self):
# p = path.py('')
# n = p.join('tokenize')
# assert str(n) == 'tokenize'
#
# p = path.py('', ns=os)
# n = p.join('getlogin')
# assert str(n) == 'getlogin'
#def test_unspecifiedpypath_lists_modules(self):
# p = path.py('')
# l = p.listdir()
# for i in l:
# assert '.' not in str(i)
#
# for j in sys.modules:
# for i in l:
# if j.startswith(str(i)):
# break
# else:
# self.fail("%s is not in sys.modules")
#def test_main_works(self):
# m = path.py('__main__')
# import __main__
# assert m.resolve() is __main__
def test_relto(self):
m1 = self.root.new(modpath='a.b.c.d')
m2 = self.root.new(modpath='a.b')
m3 = self.root.new(modpath='')
res = m1.relto(m2)
assert str(res) == 'c.d'
assert m2.relto(m3) == 'a.b'
def test_basename(self):
m1 = self.root.new(modpath='a.b.hello')
assert m1.basename == 'hello'
assert m1.check(basename='hello')
assert not m1.check(basename='nono')
assert m1.check(basestarts='he')
assert not m1.check(basestarts='42')
def test_dirpath(self):
m1 = self.root.new(modpath='a.b.hello')
m2 = self.root.new(modpath='a.b')
m3 = self.root.new(modpath='a')
m4 = self.root.new(modpath='')
assert m1.dirpath() == m2
assert m2.dirpath() == m3
assert m3.dirpath() == m4
def test_function(self):
p = self.root.join('A.func')
assert p.check(func=1)
p = self.root.join('A.x1')
assert p.check(func=0)
def test_generatorfunction(self):
p = self.root.join('A.genfunc')
assert p.check(genfunc=1)
p = self.root.join('A.func')
assert p.check(genfunc=0)
p = self.root.join('A')
assert p.check(genfunc=0)
def test_class(self):
p = self.root.join('A')
assert p.check(class_=1)
def test_hashing_equality(self):
x = self.root
y = self.root.new()
assert x == y
assert hash(x) == hash(y)
def test_parts2(self):
x = self.root.new(modpath='os.path.abspath')
l = x.parts()
assert len(l) == 4
assert self.root.join('') == l[0]
assert self.root.join('os') == l[1]
assert self.root.join('os.path') == l[2]
assert self.root.join('os.path.abspath') == l[3]
#class TestExtPyWithModule:
# def test_module(self):
# import os
# x = py.path.extpy(os, 'path.abspath')
# assert x.check()
# assert x.resolve() is os.path.abspath
# #def setup_class(cls):
# cls.root = py.path.extpy(mypath)
class TestEval:
disabled = True
def test_funccall(self):
p = path.py('os.path.join("a", "b")')
s = p.resolve()
assert s == os.path.join("a", "b")
def test_invalid1(self):
p = path.py('os.path.qwe("a", "b")')
s = test.raises(py.error.ENOENT, "p.resolve()")
def test_syntaxerror(self):
p = path.py('os.path.qwe("a", ')
s = test.raises(ValueError, "p.resolve()")
class TestErrors:
def test_ENOENT(self):
p = py.path.extpy(mypath, 'somesuch')
py.test.raises(py.error.ENOENT, p.resolve)
def test_ENOENT_really(self):
p = py.path.extpy(mypath.new(basename='notexist'), 'somesuch')
py.test.raises(py.error.ENOENT, p.resolve)
#def test_ImportError():
# p = path.py('__std.utest.test.data.failingimport.someattr')
# utest.raises(ImportError, p.resolve)
class ExampleClass:
testattr = 1
def test_no_newline():
filepath = mypath.dirpath() / 'test_data' / 'no_trailing_newline.py'
pyc = filepath.dirpath() / 'no_trailing_newline.pyc'
if pyc.check(exists=1):
pyc.remove()
data = filepath.read()
assert not data.endswith('\n') and not data.endswith('\r'), (
"The file must not end with a newline (that's the point of "
"this test")
#print repr(data)
mod_extpy = py.path.extpy(filepath)
#print mod_extpy.resolve()
assert mod_extpy.resolve().test

View File

@ -54,10 +54,6 @@ class CommonPathTests:
x = other.common(self.root) x = other.common(self.root)
assert x == self.root assert x == self.root
third = py.path.extpy('x', 'whatever')
x = other.common(third)
assert x is None
#def test_parents_nonexisting_file(self): #def test_parents_nonexisting_file(self):
# newpath = self.root / 'dirnoexist' / 'nonexisting file' # newpath = self.root / 'dirnoexist' / 'nonexisting file'

View File

@ -9,7 +9,7 @@ class TestAPI:
def repr_eval_test(self, p): def repr_eval_test(self, p):
r = repr(p) r = repr(p)
from py.path import local,svnurl, svnwc, extpy from py.path import local,svnurl, svnwc
y = eval(r) y = eval(r)
assert y == p assert y == p
@ -21,7 +21,6 @@ class TestAPI:
assert p.check() assert p.check()
assert p.check(local=1) assert p.check(local=1)
assert p.check(svnwc=0) assert p.check(svnwc=0)
assert p.check(extpy=0)
assert not p.check(svnwc=1) assert not p.check(svnwc=1)
self.repr_eval_test(p) self.repr_eval_test(p)