From hpk at codespeak.net Sun Jul 3 13:57:59 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Sun, 3 Jul 2005 13:57:59 +0200 (CEST) Subject: [py-svn] r14131 - py/dist/py/thread Message-ID: <20050703115759.957B527B46@code1.codespeak.net> Author: hpk Date: Sun Jul 3 13:57:58 2005 New Revision: 14131 Modified: py/dist/py/thread/io.py Log: make threadout more file-like Modified: py/dist/py/thread/io.py ============================================================================== --- py/dist/py/thread/io.py (original) +++ py/dist/py/thread/io.py Sun Jul 3 13:57:58 2005 @@ -20,6 +20,10 @@ setattr(obj, attrname, self) return self + def isatty(self): + # XXX + return False + def setdefaultwriter(self, writefunc): self._defaultwriter = writefunc From arigo at codespeak.net Tue Jul 5 11:56:36 2005 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 5 Jul 2005 11:56:36 +0200 (CEST) Subject: [py-svn] r14260 - py/dist/py/path/svn Message-ID: <20050705095636.61AA227B42@code1.codespeak.net> Author: arigo Date: Tue Jul 5 11:56:36 2005 New Revision: 14260 Modified: py/dist/py/path/svn/svncommon.py Log: Setting the locale before calling 'svn' is still necessary. Revision 7780 broke this. Modified: py/dist/py/path/svn/svncommon.py ============================================================================== --- py/dist/py/path/svn/svncommon.py (original) +++ py/dist/py/path/svn/svncommon.py Tue Jul 5 11:56:36 2005 @@ -251,6 +251,6 @@ return value def fixlocale(): - #if sys.platform != 'win32': - # return 'LC_ALL=C ' + if sys.platform != 'win32': + return 'LC_ALL=C ' return '' From dstanek at codespeak.net Tue Jul 5 23:26:59 2005 From: dstanek at codespeak.net (dstanek at codespeak.net) Date: Tue, 5 Jul 2005 23:26:59 +0200 (CEST) Subject: [py-svn] r14317 - py/branch/dist-doctest Message-ID: <20050705212659.70ADB27B42@code1.codespeak.net> Author: dstanek Date: Tue Jul 5 23:26:57 2005 New Revision: 14317 Removed: py/branch/dist-doctest/ Log: Remove the dist-doctest branch; I am having trouble merging in the trunk changes so I am gonna recreate it From dstanek at codespeak.net Tue Jul 5 23:27:53 2005 From: dstanek at codespeak.net (dstanek at codespeak.net) Date: Tue, 5 Jul 2005 23:27:53 +0200 (CEST) Subject: [py-svn] r14318 - py/branch/dist-doctest Message-ID: <20050705212753.AC6E127B42@code1.codespeak.net> Author: dstanek Date: Tue Jul 5 23:27:51 2005 New Revision: 14318 Added: py/branch/dist-doctest/ - copied from r14317, py/dist/ Log: Created a new doctest branch for the development of doctest support. From hpk at codespeak.net Mon Jul 11 10:09:20 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Mon, 11 Jul 2005 10:09:20 +0200 (CEST) Subject: [py-svn] r14484 - py/dist/py Message-ID: <20050711080920.4C36627B43@code1.codespeak.net> Author: hpk Date: Mon Jul 11 10:09:18 2005 New Revision: 14484 Modified: py/dist/py/__init__.py Log: bump version number to 0.8.0-alpha2 Modified: py/dist/py/__init__.py ============================================================================== --- py/dist/py/__init__.py (original) +++ py/dist/py/__init__.py Mon Jul 11 10:09:18 2005 @@ -1,17 +1,17 @@ """\ the py lib is a development support library featuring -py.test, an interactive testing tool which supports +py.test, an interactive testing tool which supports unit-testing with practically no boilerplate. -""" -from initpkg import initpkg +""" +from initpkg import initpkg -initpkg(__name__, +initpkg(__name__, description = "py.test and the py lib", revision = int('$LastChangedRevision$'.split(':')[1][:-1]), lastchangedate = '$LastChangedDate$', - version = "0.8.0-alpha1", + version = "0.8.0-alpha2", url = "http://codespeak.net/py", - download_url = "http://codespeak.net/download/py/py-0.8.0-alpha1.tar.gz", + download_url = "http://codespeak.net/download/py/py-0.8.0-alpha1.tar.gz", license = "MIT license", platforms = ['unix', 'linux', 'cygwin'], author = "holger krekel & others", @@ -19,7 +19,7 @@ long_description = globals()['__doc__'], exportdefs = { - '_dist.setup' : ('./misc/_dist.py', 'setup'), + '_dist.setup' : ('./misc/_dist.py', 'setup'), # helpers for use from test functions or collectors 'test.raises' : ('./test/raises.py', 'raises'), @@ -32,7 +32,7 @@ # configuration/initialization related test api 'test.Config' : ('./test/config.py', 'Config'), 'test.ensuretemp' : ('./test/config.py', 'ensuretemp'), - 'test.cmdline.main' : ('./test/cmdline.py', 'main'), + 'test.cmdline.main' : ('./test/cmdline.py', 'main'), # for customization of collecting/running tests 'test.Session' : ('./test/session.py', 'Session'), @@ -100,14 +100,14 @@ 'xml.escape' : ('./xmlobj/misc.py', 'escape'), # logging API ('producers' and 'consumers' connected via keywords) - 'log.Producer' : ('./log/producer.py', 'Producer'), + 'log.Producer' : ('./log/producer.py', 'Producer'), 'log.default' : ('./log/producer.py', 'default'), - 'log._getstate' : ('./log/producer.py', '_getstate'), - 'log._setstate' : ('./log/producer.py', '_setstate'), - 'log.setconsumer' : ('./log/consumer.py', 'setconsumer'), - 'log.Path' : ('./log/consumer.py', 'Path'), - 'log.STDOUT' : ('./log/consumer.py', 'STDOUT'), - 'log.STDERR' : ('./log/consumer.py', 'STDERR'), + 'log._getstate' : ('./log/producer.py', '_getstate'), + 'log._setstate' : ('./log/producer.py', '_setstate'), + 'log.setconsumer' : ('./log/consumer.py', 'setconsumer'), + 'log.Path' : ('./log/consumer.py', 'Path'), + 'log.STDOUT' : ('./log/consumer.py', 'STDOUT'), + 'log.STDERR' : ('./log/consumer.py', 'STDERR'), 'compat.doctest' : ('./compat/doctest.py', '*'), 'compat.optparse' : ('./compat/optparse.py', '*'), From hpk at codespeak.net Mon Jul 11 10:12:29 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Mon, 11 Jul 2005 10:12:29 +0200 (CEST) Subject: [py-svn] r14485 - py/dist/py Message-ID: <20050711081229.C52D227B43@code1.codespeak.net> Author: hpk Date: Mon Jul 11 10:12:29 2005 New Revision: 14485 Modified: py/dist/py/__init__.py Log: also fixed the download url Modified: py/dist/py/__init__.py ============================================================================== --- py/dist/py/__init__.py (original) +++ py/dist/py/__init__.py Mon Jul 11 10:12:29 2005 @@ -11,7 +11,7 @@ lastchangedate = '$LastChangedDate$', version = "0.8.0-alpha2", url = "http://codespeak.net/py", - download_url = "http://codespeak.net/download/py/py-0.8.0-alpha1.tar.gz", + download_url = "http://codespeak.net/download/py/py-0.8.0-alpha2.tar.gz", license = "MIT license", platforms = ['unix', 'linux', 'cygwin'], author = "holger krekel & others", From hpk at codespeak.net Tue Jul 12 15:17:37 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Tue, 12 Jul 2005 15:17:37 +0200 (CEST) Subject: [py-svn] r14544 - py/dist/py/path/svn Message-ID: <20050712131737.BAD6427B46@code1.codespeak.net> Author: hpk Date: Tue Jul 12 15:17:35 2005 New Revision: 14544 Modified: py/dist/py/path/svn/urlcommand.py py/dist/py/path/svn/wccommand.py Log: some fixes for the (flaky, anyway) error-handling Modified: py/dist/py/path/svn/urlcommand.py ============================================================================== --- py/dist/py/path/svn/urlcommand.py (original) +++ py/dist/py/path/svn/urlcommand.py Tue Jul 12 15:17:35 2005 @@ -171,6 +171,8 @@ except process.cmdexec.Error, e: if e.err.find('non-existent in that revision') != -1: raise py.error.ENOENT(self, e.err) + elif e.err.find('File not found') != -1: + raise py.error.ENOENT(self, e.err) elif e.err.find('not part of a repository')!=-1: raise py.error.ENOENT(self, e.err) elif e.err.find('Unable to open')!=-1: Modified: py/dist/py/path/svn/wccommand.py ============================================================================== --- py/dist/py/path/svn/wccommand.py (original) +++ py/dist/py/path/svn/wccommand.py Tue Jul 12 15:17:35 2005 @@ -68,7 +68,9 @@ try: out = py.process.cmdexec(string) except py.process.cmdexec.Error, e: - if e.err.find('File Exists'): + if e.err.find('File not found') != -1: + raise py.error.ENOENT(self) + if e.err.find('File Exists') != -1: raise py.error.EEXIST(self) raise return out From dstanek at codespeak.net Thu Jul 14 00:27:22 2005 From: dstanek at codespeak.net (dstanek at codespeak.net) Date: Thu, 14 Jul 2005 00:27:22 +0200 (CEST) Subject: [py-svn] r14653 - in py/dist/py: compat documentation test tool Message-ID: <20050713222722.9417227B82@code1.codespeak.net> Author: dstanek Date: Thu Jul 14 00:27:19 2005 New Revision: 14653 Modified: py/dist/py/compat/optparse.py py/dist/py/documentation/conftest.py py/dist/py/test/config.py py/dist/py/tool/utestconvert.py Log: The imports of CPython modules that are in py.compat have all been updated to use the py.compat modules. This is part of Issue 8. Modified: py/dist/py/compat/optparse.py ============================================================================== --- py/dist/py/compat/optparse.py (original) +++ py/dist/py/compat/optparse.py Thu Jul 14 00:27:19 2005 @@ -68,9 +68,12 @@ import sys, os import types -import textwrap from gettext import gettext as _ +import py +textwrap = py.compat.textwrap + + def _repr(self): return "<%s at 0x%x: %s>" % (self.__class__.__name__, id(self), self) Modified: py/dist/py/documentation/conftest.py ============================================================================== --- py/dist/py/documentation/conftest.py (original) +++ py/dist/py/documentation/conftest.py Thu Jul 14 00:27:19 2005 @@ -56,7 +56,7 @@ def execute(self, mod, docstring): mod.__doc__ = docstring - failed, tot = py.std.doctest.testmod(mod, verbose=1) + failed, tot = py.compat.doctest.testmod(mod, verbose=1) if failed: py.test.fail("doctest %s: %s failed out of %s" %( self.fspath, failed, tot)) Modified: py/dist/py/test/config.py ============================================================================== --- py/dist/py/test/config.py (original) +++ py/dist/py/test/config.py Thu Jul 14 00:27:19 2005 @@ -1,7 +1,7 @@ from __future__ import generators import py -from py.__.test.tool import optparse +optparse = py.compat.optparse defaultconfig = py.magic.autopath().dirpath('defaultconftest.py') dummy = object() Modified: py/dist/py/tool/utestconvert.py ============================================================================== --- py/dist/py/tool/utestconvert.py (original) +++ py/dist/py/tool/utestconvert.py Thu Jul 14 00:27:19 2005 @@ -185,11 +185,11 @@ if __name__ == '__main__': - from optparse import OptionParser import sys + import py usage = "usage: %prog [-s [filename ...] | [-i | -c filename ...]]" - optparser = OptionParser(usage) + optparser = py.compat.optparse.OptionParser(usage) def select_output (option, opt, value, optparser, **kw): if hasattr(optparser, 'output'): From hpk at codespeak.net Tue Jul 19 12:20:24 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Tue, 19 Jul 2005 12:20:24 +0200 (CEST) Subject: [py-svn] r14761 - in py/dist/py/misc: . testing Message-ID: <20050719102024.8E37F27B51@code1.codespeak.net> Author: hpk Date: Tue Jul 19 12:20:23 2005 New Revision: 14761 Modified: py/dist/py/misc/error.py py/dist/py/misc/testing/test_error.py Log: don't fail on unknown Errno's but present an UnknownErrnoNUM error Modified: py/dist/py/misc/error.py ============================================================================== --- py/dist/py/misc/error.py (original) +++ py/dist/py/misc/error.py Tue Jul 19 12:20:23 2005 @@ -42,7 +42,7 @@ try: return _errno2class[eno] except KeyError: - clsname = py.std.errno.errorcode[eno] + clsname = py.std.errno.errorcode.get(eno, "UnknownErrno%d" %(eno,)) cls = py.std.new.classobj(clsname, (Error,), {'__module__':'py.error', '__doc__': py.std.os.strerror(eno)}) Modified: py/dist/py/misc/testing/test_error.py ============================================================================== --- py/dist/py/misc/testing/test_error.py (original) +++ py/dist/py/misc/testing/test_error.py Tue Jul 19 12:20:23 2005 @@ -8,3 +8,13 @@ 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 + From hpk at codespeak.net Tue Jul 19 18:22:22 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Tue, 19 Jul 2005 18:22:22 +0200 (CEST) Subject: [py-svn] r14779 - py/dist/py/documentation Message-ID: <20050719162222.B1BE327B5D@code1.codespeak.net> Author: hpk Date: Tue Jul 19 18:22:12 2005 New Revision: 14779 Modified: py/dist/py/documentation/conftest.py Log: skip URL-checks if they result in a 401/403 error (pointing to resources requiring permissions is basically not an error) Modified: py/dist/py/documentation/conftest.py ============================================================================== --- py/dist/py/documentation/conftest.py (original) +++ py/dist/py/documentation/conftest.py Tue Jul 19 18:22:12 2005 @@ -124,8 +124,11 @@ print "trying remote", tryfn py.std.urllib2.urlopen(tryfn) except (py.std.urllib2.URLError, py.std.urllib2.HTTPError), e: - py.test.fail("remote reference error %r in %s:%d\n%s" %( - tryfn, path.basename, lineno+1, e)) + if e.code in (401, 403): # authorization required, forbidden + py.test.skip("%s: %s" %(tryfn, str(e))) + else: + py.test.fail("remote reference error %r in %s:%d\n%s" %( + tryfn, path.basename, lineno+1, e)) def localrefcheck(tryfn, path, lineno): # assume it should be a file From dstanek at codespeak.net Tue Jul 19 19:17:36 2005 From: dstanek at codespeak.net (dstanek at codespeak.net) Date: Tue, 19 Jul 2005 19:17:36 +0200 (CEST) Subject: [py-svn] r14786 - py/dist/py/test/tool Message-ID: <20050719171736.321C327B5D@code1.codespeak.net> Author: dstanek Date: Tue Jul 19 19:17:29 2005 New Revision: 14786 Removed: py/dist/py/test/tool/ Log: Removed the py/test/tool tree. It has been superseded by py/compat. From hpk at codespeak.net Wed Jul 20 22:01:10 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Wed, 20 Jul 2005 22:01:10 +0200 (CEST) Subject: [py-svn] r14834 - in py/dist/py/path/local: . testing Message-ID: <20050720200110.E70B727B8B@code1.codespeak.net> Author: hpk Date: Wed Jul 20 22:01:08 2005 New Revision: 14834 Modified: py/dist/py/path/local/local.py py/dist/py/path/local/testing/test_posix.py Log: fix a probably long standing bug of the py.path.local().join method which would produce non-normalized paths. Modified: py/dist/py/path/local/local.py ============================================================================== --- py/dist/py/path/local/local.py (original) +++ py/dist/py/path/local/local.py Wed Jul 20 22:01:08 2005 @@ -154,15 +154,22 @@ """ if not args: return self - strargs = [self.strpath] - strargs.extend(map(str, args)) + strpath = self.strpath + sep = self.sep + strargs = [str(x) for x in args] if kwargs.get('abs', 0): - for i in range(len(strargs)-1, 0, -1): + for i in range(len(strargs)-1, -1, -1): if os.path.isabs(strargs[i]): - strargs = strargs[i:] + strpath = strargs[i] + strargs = strargs[i+1:] break + for arg in strargs: + arg = arg.strip(sep) + if not strpath.endswith(sep): + strpath += sep + strpath += arg obj = self.new() - obj.strpath = os.path.normpath(self.sep.join(strargs)) + obj.strpath = strpath return obj def __eq__(self, other): 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 Wed Jul 20 22:01:08 2005 @@ -115,6 +115,11 @@ p2 = py.path.local(self.root.sep+'blabla') assert p1.common(p2) == '/' + def test_join_to_root(self): + root = self.root.parts()[0] + assert len(str(root)) == 1 + assert str(root.join('a')) == '/a' + def test_chmod_simple_int(self): print "self.root is", self.root mode = self.root.mode() From hpk at codespeak.net Thu Jul 21 18:48:59 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Thu, 21 Jul 2005 18:48:59 +0200 (CEST) Subject: [py-svn] r14880 - py/dist/py/path/svn Message-ID: <20050721164859.5898527B70@code1.codespeak.net> Author: hpk Date: Thu Jul 21 18:48:58 2005 New Revision: 14880 Modified: py/dist/py/path/svn/wccommand.py Log: made the string-parsing logic for svn error discovery more robust. Modified: py/dist/py/path/svn/wccommand.py ============================================================================== --- py/dist/py/path/svn/wccommand.py (original) +++ py/dist/py/path/svn/wccommand.py Thu Jul 21 18:48:58 2005 @@ -68,9 +68,10 @@ try: out = py.process.cmdexec(string) except py.process.cmdexec.Error, e: - if e.err.find('File not found') != -1: + strerr = e.err.lower() + if strerr.find('file not found') != -1: raise py.error.ENOENT(self) - if e.err.find('File Exists') != -1: + if strerr.find('file exists') != -1: raise py.error.EEXIST(self) raise return out From hpk at codespeak.net Thu Jul 21 21:00:26 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Thu, 21 Jul 2005 21:00:26 +0200 (CEST) Subject: [py-svn] r14889 - in py/dist/py/path/local: . testing Message-ID: <20050721190026.3CCCF27BA2@code1.codespeak.net> Author: hpk Date: Thu Jul 21 21:00:25 2005 New Revision: 14889 Modified: py/dist/py/path/local/local.py py/dist/py/path/local/testing/test_posix.py Log: yet another fix to local's join() handling Modified: py/dist/py/path/local/local.py ============================================================================== --- py/dist/py/path/local/local.py (original) +++ py/dist/py/path/local/local.py Thu Jul 21 21:00:25 2005 @@ -165,9 +165,10 @@ break for arg in strargs: arg = arg.strip(sep) - if not strpath.endswith(sep): - strpath += sep - strpath += arg + if arg: + if not strpath.endswith(sep): + strpath += sep + strpath += arg obj = self.new() obj.strpath = strpath return obj 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 Thu Jul 21 21:00:25 2005 @@ -120,6 +120,11 @@ assert len(str(root)) == 1 assert str(root.join('a')) == '/a' + def test_join_root_to_root_with_no_abs(self): + nroot = self.root.join('/') + assert str(self.root) == str(nroot) + assert self.root == nroot + def test_chmod_simple_int(self): print "self.root is", self.root mode = self.root.mode() From hpk at codespeak.net Sun Jul 24 09:40:54 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Sun, 24 Jul 2005 09:40:54 +0200 (CEST) Subject: [py-svn] r14973 - py/dist/py/documentation Message-ID: <20050724074054.C192C27B70@code1.codespeak.net> Author: hpk Date: Sun Jul 24 09:40:54 2005 New Revision: 14973 Modified: py/dist/py/documentation/confrest.py py/dist/py/documentation/conftest.py Log: first steps at making the documentation/webpage generation more flexible/reusable by other projects. Modified: py/dist/py/documentation/confrest.py ============================================================================== --- py/dist/py/documentation/confrest.py (original) +++ py/dist/py/documentation/confrest.py Sun Jul 24 09:40:54 2005 @@ -5,35 +5,12 @@ mydir = py.magic.autopath().dirpath() html = py.xml.html -def process(txtpath): - encoding = 'latin1' - content = unicode(txtpath.read(), encoding) - stylesheet = 'style.css' - if not txtpath.dirpath(stylesheet).check(): - stylesheet = None - - content = convert_rest_html(content, txtpath, stylesheet=stylesheet, encoding=encoding) - content = strip_html_header(content) - - page = PyPage("[%s] " % txtpath.purebasename, stylesheeturl=stylesheet) - - svninfo = txtpath.info() - modified = " modified %s by %s" % (worded_diff_time(svninfo.mtime), - getrealname(svninfo.last_author)) - - page.contentspace.append( - html.div(html.div(modified, style="float: right; font-style: italic;"), - id = 'docinfoline')) - - page.contentspace.append(content) - htmlpath = txtpath.new(ext='.html') - htmlpath.write(page.unicode().encode(encoding)) - class Page(object): doctype = ('\n') - def __init__(self, title, stylesheeturl=None, type="text/html", encoding="ISO-8859-1"): + def __init__(self, project, title, stylesheeturl=None, type="text/html", encoding="ISO-8859-1"): + self.project = project self.title = title self.stylesheeturl = stylesheeturl self.type = type @@ -65,11 +42,7 @@ def fill(self): super(PyPage, self).fill() # base layout - self.body.append( - html.div(html.a(html.img(alt="py lib", id='pyimg', height=114, width=154, - src="http://codespeak.net/img/pylib.png"), - href="http://codespeak.net", - ))) + self.body.append(self.project.logo) #self.body.append( # html.div("py lib rev %d" % 1)) @@ -88,7 +61,6 @@ id='metaspace') self.body.append(self.metaspace) - self.contentspace = html.div(id="contentspace") self.body.append(self.contentspace) @@ -103,3 +75,38 @@ raise return user.realname or username +class Project: + stylesheet = 'style.css' + title = "py lib" + encoding = 'latin1' + logo = html.div( + html.a( + html.img(alt="py lib", id='pyimg', height=114, width=154, + src="http://codespeak.net/img/pylib.png"), + href="http://codespeak.net")) + Page = PyPage + + def process(self, txtpath): + encoding = self.encoding + content = unicode(txtpath.read(), encoding) + stylesheet = self.stylesheet + if not txtpath.dirpath(stylesheet).check(): + stylesheet = None + + content = convert_rest_html(content, txtpath, stylesheet=stylesheet, encoding=encoding) + content = strip_html_header(content) + + page = self.Page(self, "[%s] " % txtpath.purebasename, stylesheeturl=stylesheet) + + svninfo = txtpath.info() + modified = " modified %s by %s" % (worded_diff_time(svninfo.mtime), + getrealname(svninfo.last_author)) + + page.contentspace.append( + html.div(html.div(modified, style="float: right; font-style: italic;"), + id = 'docinfoline')) + + page.contentspace.append(content) + htmlpath = txtpath.new(ext='.html') + htmlpath.write(page.unicode().encode(encoding)) + Modified: py/dist/py/documentation/conftest.py ============================================================================== --- py/dist/py/documentation/conftest.py (original) +++ py/dist/py/documentation/conftest.py Sun Jul 24 09:40:54 2005 @@ -24,7 +24,7 @@ confrest = path.localpath.dirpath('confrest.py') if confrest.check(file=1): confrest = confrest.pyimport() - confrest.process(path) + confrest.Project().process(path) else: # defer to default processor rest.process(path) From hpk at codespeak.net Sun Jul 24 09:52:44 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Sun, 24 Jul 2005 09:52:44 +0200 (CEST) Subject: [py-svn] r14974 - in py/dist/py: bin c-extension/greenlet code compat/testing documentation documentation/example/pytest magic misc test/tkinter test/tkinter/testing thread Message-ID: <20050724075244.7523E27B70@code1.codespeak.net> Author: hpk Date: Sun Jul 24 09:52:43 2005 New Revision: 14974 Modified: py/dist/py/bin/_makepyrelease.py (props changed) py/dist/py/c-extension/greenlet/test_generator_nested.py (props changed) py/dist/py/code/traceback2.py (props changed) py/dist/py/compat/testing/__init__.py (props changed) py/dist/py/compat/testing/conftest.py (props changed) py/dist/py/documentation/TODO.txt (props changed) py/dist/py/documentation/__init__.py (props changed) py/dist/py/documentation/confrest.py (contents, props changed) py/dist/py/documentation/conftest.py (props changed) py/dist/py/documentation/contact.txt (props changed) py/dist/py/documentation/example/pytest/test_failures.py (props changed) py/dist/py/documentation/home.txt (props changed) py/dist/py/documentation/test_conftest.py (props changed) py/dist/py/magic/greenlet.py (props changed) py/dist/py/misc/buildcmodule.py (props changed) py/dist/py/misc/difftime.py (props changed) py/dist/py/misc/rest.py (props changed) py/dist/py/test/tkinter/backend.py (props changed) py/dist/py/test/tkinter/event.py (props changed) py/dist/py/test/tkinter/testing/test_capture_out_err.py (props changed) py/dist/py/test/tkinter/tkgui.py (props changed) py/dist/py/test/tkinter/tksession.py (props changed) py/dist/py/thread/io.py (props changed) Log: fixeol made doc-generation slightly more flexible Modified: py/dist/py/documentation/confrest.py ============================================================================== --- py/dist/py/documentation/confrest.py (original) +++ py/dist/py/documentation/confrest.py Sun Jul 24 09:52:43 2005 @@ -11,7 +11,7 @@ def __init__(self, project, title, stylesheeturl=None, type="text/html", encoding="ISO-8859-1"): self.project = project - self.title = title + self.title = project.prefix_title + title self.stylesheeturl = stylesheeturl self.type = type self.encoding = encoding @@ -30,31 +30,13 @@ html.link(href=self.stylesheeturl, media="screen", rel="stylesheet", type="text/css")) - - def unicode(self, doctype=True): - page = self._root.unicode() - if doctype: - return self.doctype + page - else: - return page - -class PyPage(Page): - def fill(self): - super(PyPage, self).fill() - # base layout - self.body.append(self.project.logo) - #self.body.append( - # html.div("py lib rev %d" % 1)) - self.menubar = html.div( html.a("home", href="home.html", class_="menu"), " ", html.a("doc", href="index.html", class_="menu"), " ", html.a("contact", href="contact.html", class_="menu"), " ", html.a("getting-started", href="getting-started.html", class_="menu"), " ", - html.a("issue", href="https://codespeak.net/issue/py-dev/", class_="menu"), id="menubar", ) - self.metaspace = html.div( html.div(self.title, class_="project_title"), self.menubar, @@ -64,6 +46,23 @@ self.contentspace = html.div(id="contentspace") self.body.append(self.contentspace) + def unicode(self, doctype=True): + page = self._root.unicode() + if doctype: + return self.doctype + page + else: + return page + +class PyPage(Page): + def fill(self): + super(PyPage, self).fill() + # base layout + self.body.append(self.project.logo) + self.menubar.append( + html.a("issue", href="https://codespeak.net/issue/py-dev/", class_="menu"), + ) + + def getrealname(username): try: import uconf @@ -78,6 +77,7 @@ class Project: stylesheet = 'style.css' title = "py lib" + prefix_title = "" # we have a logo already containing "py lib" encoding = 'latin1' logo = html.div( html.a( From hpk at codespeak.net Sun Jul 24 10:19:26 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Sun, 24 Jul 2005 10:19:26 +0200 (CEST) Subject: [py-svn] r14975 - py/dist/py/documentation Message-ID: <20050724081926.0A99E27B70@code1.codespeak.net> Author: hpk Date: Sun Jul 24 10:19:25 2005 New Revision: 14975 Modified: py/dist/py/documentation/confrest.py Log: put the logo on the default page Modified: py/dist/py/documentation/confrest.py ============================================================================== --- py/dist/py/documentation/confrest.py (original) +++ py/dist/py/documentation/confrest.py Sun Jul 24 10:19:25 2005 @@ -42,6 +42,7 @@ self.menubar, id='metaspace') + self.body.append(self.project.logo) self.body.append(self.metaspace) self.contentspace = html.div(id="contentspace") self.body.append(self.contentspace) @@ -57,7 +58,6 @@ def fill(self): super(PyPage, self).fill() # base layout - self.body.append(self.project.logo) self.menubar.append( html.a("issue", href="https://codespeak.net/issue/py-dev/", class_="menu"), ) From arigo at codespeak.net Wed Jul 27 12:30:36 2005 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 27 Jul 2005 12:30:36 +0200 (CEST) Subject: [py-svn] r15168 - in py/dist/py/c-extension: . greenlet Message-ID: <20050727103036.9C9DB27B61@code1.codespeak.net> Author: arigo Date: Wed Jul 27 12:30:29 2005 New Revision: 15168 Modified: py/dist/py/c-extension/conftest.py py/dist/py/c-extension/greenlet/greenlet.c py/dist/py/c-extension/greenlet/greenlet.h Log: - allow taking weakrefs to greenlet objects. - added a "dead" attribute. - enabled greenlet testing by default. Modified: py/dist/py/c-extension/conftest.py ============================================================================== --- py/dist/py/c-extension/conftest.py (original) +++ py/dist/py/c-extension/conftest.py Wed Jul 27 12:30:29 2005 @@ -9,5 +9,6 @@ # return False # return super(Directory, self).recfilter(path) - def run(self): - py.test.skip("c-extension testing needs platform selection") + #def run(self): + # py.test.skip("c-extension testing needs platform selection") + pass Modified: py/dist/py/c-extension/greenlet/greenlet.c ============================================================================== --- py/dist/py/c-extension/greenlet/greenlet.c (original) +++ py/dist/py/c-extension/greenlet/greenlet.c Wed Jul 27 12:30:29 2005 @@ -529,6 +529,8 @@ return; } } + if (self->weakreflist != NULL) + PyObject_ClearWeakRefs((PyObject *) self); Py_XDECREF(self->run_info); self->ob_type->tp_free((PyObject*) self); } @@ -557,6 +559,17 @@ return PyGreen_ACTIVE(self); } +static PyObject* green_getdead(PyGreenlet* self, void* c) +{ + PyObject* res; + if (PyGreen_ACTIVE(self) || !PyGreen_STARTED(self)) + res = Py_False; + else + res = Py_True; + Py_INCREF(res); + return res; +} + static PyObject* green_getrun(PyGreenlet* self, void* c) { if (PyGreen_STARTED(self) || self->run_info == NULL) { @@ -683,6 +696,8 @@ (setter)green_setparent, /*XXX*/ NULL}, {"gr_frame", (getter)green_getframe, NULL, /*XXX*/ NULL}, + {"dead", (getter)green_getdead, + NULL, /*XXX*/ NULL}, {NULL} }; @@ -700,7 +715,7 @@ (inquiry)green_nonzero, /* nb_nonzero */ }; -statichere PyTypeObject PyGreen_Type = { +PyTypeObject PyGreen_Type = { PyObject_HEAD_INIT(NULL) 0, "greenlet.greenlet", @@ -726,7 +741,7 @@ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ + offsetof(PyGreenlet, weakreflist), /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ green_methods, /* tp_methods */ Modified: py/dist/py/c-extension/greenlet/greenlet.h ============================================================================== --- py/dist/py/c-extension/greenlet/greenlet.h (original) +++ py/dist/py/c-extension/greenlet/greenlet.h Wed Jul 27 12:30:29 2005 @@ -20,6 +20,7 @@ PyObject* run_info; struct _frame* top_frame; int recursion_depth; + PyObject* weakreflist; } PyGreenlet; extern PyTypeObject PyGreen_Type; From hpk at codespeak.net Fri Jul 29 15:02:50 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 29 Jul 2005 15:02:50 +0200 (CEST) Subject: [py-svn] r15345 - py/dist/py Message-ID: <20050729130250.9FA4827B53@code1.codespeak.net> Author: hpk Date: Fri Jul 29 15:02:49 2005 New Revision: 15345 Modified: py/dist/py/initpkg.py Log: basestring is not python 2.2 Modified: py/dist/py/initpkg.py ============================================================================== --- py/dist/py/initpkg.py (original) +++ py/dist/py/initpkg.py Fri Jul 29 15:02:49 2005 @@ -67,7 +67,7 @@ assert fspath.startswith('./'), \ "%r is not an implementation path (XXX)" % (extpyish,) implmodule = self._loadimpl(fspath[:-3]) - if not isinstance(modpath, basestring): # export the entire module + if not isinstance(modpath, str): # export the entire module return implmodule current = implmodule From hpk at codespeak.net Fri Jul 29 15:03:11 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 29 Jul 2005 15:03:11 +0200 (CEST) Subject: [py-svn] r15346 - py/dist/py/documentation Message-ID: <20050729130311.28DA927B53@code1.codespeak.net> Author: hpk Date: Fri Jul 29 15:03:10 2005 New Revision: 15346 Modified: py/dist/py/documentation/confrest.py Log: fall back some more regarding obtaining author information Modified: py/dist/py/documentation/confrest.py ============================================================================== --- py/dist/py/documentation/confrest.py (original) +++ py/dist/py/documentation/confrest.py Fri Jul 29 15:03:10 2005 @@ -72,7 +72,11 @@ user = uconf.system.User(username) except KeyboardInterrupt: raise - return user.realname or username + try: + return user.realname or username + except KeyError: + return username + class Project: stylesheet = 'style.css' From hpk at codespeak.net Fri Jul 29 15:03:39 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 29 Jul 2005 15:03:39 +0200 (CEST) Subject: [py-svn] r15347 - py/dist/py/code/testing Message-ID: <20050729130339.C4BB627B53@code1.codespeak.net> Author: hpk Date: Fri Jul 29 15:03:39 2005 New Revision: 15347 Modified: py/dist/py/code/testing/test_code.py Log: python2.2 compat Modified: py/dist/py/code/testing/test_code.py ============================================================================== --- py/dist/py/code/testing/test_code.py (original) +++ py/dist/py/code/testing/test_code.py Fri Jul 29 15:03:39 2005 @@ -1,3 +1,4 @@ +from __future__ import generators import py def test_newcode(): From hpk at codespeak.net Fri Jul 29 20:23:02 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 29 Jul 2005 20:23:02 +0200 (CEST) Subject: [py-svn] r15369 - in py/dist/py/misc: . testing Message-ID: <20050729182302.9934427B5D@code1.codespeak.net> Author: hpk Date: Fri Jul 29 20:23:01 2005 New Revision: 15369 Added: py/dist/py/misc/capture.py Modified: py/dist/py/misc/testing/test_simplecapture.py Log: - add another capturing based on FDs just want to get this version in. - there definitely needs to be quite some cleanup with all the different ways of capturing stdout/stderr Added: py/dist/py/misc/capture.py ============================================================================== --- (empty file) +++ py/dist/py/misc/capture.py Fri Jul 29 20:23:01 2005 @@ -0,0 +1,44 @@ + +import os, sys + +class FDCapture: + def __init__(self, targetfd, sysattr=None): + self.targetfd = targetfd + self.tmpfile = self.maketmpfile() + self._savefd = os.dup(targetfd) + os.dup2(self.tmpfile.fileno(), targetfd) + if sysattr is not None: + self._reset = (lambda oldval=getattr(sys, sysattr): + setattr(sys, sysattr, oldval)) + setattr(sys, sysattr, self.tmpfile) + + def done(self): + os.dup2(self._savefd, self.targetfd) + if hasattr(self, '_reset'): + self._reset() + del self._reset + os.close(self._savefd) + f = self.tmpfile + f.seek(0) + del self._savefd + del self.tmpfile + return f + + def maketmpfile(self): + return os.tmpfile() + +class Capture: + def __init__(self): + self._out = FDCapture(1, 'stdout') + self._oldsysout = sys.stdout + sys.stdout = self._out.tmpfile + + self._err = FDCapture(2, 'stderr') + self._olderrout = sys.stderr + sys.stderr = self._err.tmpfile + + def reset(self): + outfile = self._out.done() + errfile = self._err.done() + return outfile.read(), errfile.read() + Modified: py/dist/py/misc/testing/test_simplecapture.py ============================================================================== --- py/dist/py/misc/testing/test_simplecapture.py (original) +++ py/dist/py/misc/testing/test_simplecapture.py Fri Jul 29 20:23:01 2005 @@ -1,43 +1,67 @@ -import sys +import os, sys import py from py.__.misc.simplecapture import SimpleOutErrCapture, callcapture +from py.__.misc.capture import Capture, FDCapture -def test_capturing_simple(): - cap = SimpleOutErrCapture() - 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(): - cap = SimpleOutErrCapture() - print "hello" - cap.reset() - py.test.raises(AttributeError, "cap.reset()") - -def test_capturing_modify_sysouterr_in_between(): - oldout = sys.stdout - olderr = sys.stderr - cap = SimpleOutErrCapture() - 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(): - cap = SimpleOutErrCapture() - cap2 = SimpleOutErrCapture() - print "hello" - cap2.reset() - py.test.raises(AttributeError, "cap2.reset()") +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): + cap = self.getcapture() + cap2 = self.getcapture() + print "hello" + cap2.reset() + py.test.raises(AttributeError, "cap2.reset()") + cap.reset() def test_callcapture(): def func(x, y): @@ -49,4 +73,7 @@ assert res == 42 assert out.startswith("3") assert err.startswith("4") - + +class TestCapturingOnFDs(TestCapturingOnSys): + def getcapture(self): + return Capture() From hpk at codespeak.net Fri Jul 29 21:48:33 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 29 Jul 2005 21:48:33 +0200 (CEST) Subject: [py-svn] r15378 - in py/dist/py/misc: . testing Message-ID: <20050729194833.47FE227B5D@code1.codespeak.net> Author: hpk Date: Fri Jul 29 21:48:32 2005 New Revision: 15378 Modified: py/dist/py/misc/capture.py py/dist/py/misc/testing/test_simplecapture.py Log: some more capturing refinements Modified: py/dist/py/misc/capture.py ============================================================================== --- py/dist/py/misc/capture.py (original) +++ py/dist/py/misc/capture.py Fri Jul 29 21:48:32 2005 @@ -25,7 +25,12 @@ return f def maketmpfile(self): - return os.tmpfile() + f = os.tmpfile() + fd = f.fileno() + newfd = os.dup(fd) + newf = os.fdopen(newfd, 'w+b', 0) + f.close() + return newf class Capture: def __init__(self): Modified: py/dist/py/misc/testing/test_simplecapture.py ============================================================================== --- py/dist/py/misc/testing/test_simplecapture.py (original) +++ py/dist/py/misc/testing/test_simplecapture.py Fri Jul 29 21:48:32 2005 @@ -56,12 +56,15 @@ assert sys.stderr == olderr def test_capturing_error_recursive(self): - cap = self.getcapture() + cap1 = self.getcapture() + print "cap1" cap2 = self.getcapture() - print "hello" - cap2.reset() + print "cap2" + out2, err2 = cap2.reset() py.test.raises(AttributeError, "cap2.reset()") - cap.reset() + out1, err1 = cap1.reset() + assert out1 == "cap1\n" + assert out2 == "cap2\n" def test_callcapture(): def func(x, y): From hpk at codespeak.net Fri Jul 29 23:11:01 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 29 Jul 2005 23:11:01 +0200 (CEST) Subject: [py-svn] r15385 - in py/dist/py: . io io/test test test/terminal test/testing thread/testing Message-ID: <20050729211101.69BCB27B5D@code1.codespeak.net> Author: hpk Date: Fri Jul 29 23:10:58 2005 New Revision: 15385 Added: py/dist/py/io/ (props changed) py/dist/py/io/__init__.py (contents, props changed) py/dist/py/io/capture.py (contents, props changed) - copied, changed from r15369, py/dist/py/misc/capture.py py/dist/py/io/dupfile.py (contents, props changed) py/dist/py/io/test/ (props changed) py/dist/py/io/test/__init__.py (contents, props changed) py/dist/py/io/test/test_capture.py - copied, changed from r15369, py/dist/py/misc/testing/test_simplecapture.py py/dist/py/io/test/test_dupfile.py (contents, props changed) Modified: py/dist/py/__init__.py py/dist/py/test/collect.py py/dist/py/test/item.py py/dist/py/test/terminal/out.py py/dist/py/test/testing/test_session.py py/dist/py/thread/testing/test_pool.py Log: a new namespace which offers in a more thought out way some IO related funcionality namely stdout/stderr capturing down to the filedescriptor os-level. According to the python documentation the used os-module functionality should be available on the major platforms but we'll see if we hit problems. py.test now uses py.io.OutErrCapture to capture stdout/stderr and should be a bit more robust. We can easily switch back to the old more shallow way of stdout/stderr capturing (which just patched sys.stdout and sys.stderr) should there be a need. the py.io-interface is likely to get refined a bit over time so use with some care. i am interested to hear especially if there are problems on win32 regarding running py.test. Modified: py/dist/py/__init__.py ============================================================================== --- py/dist/py/__init__.py (original) +++ py/dist/py/__init__.py Fri Jul 29 23:10:58 2005 @@ -90,6 +90,12 @@ 'execnet.PopenGateway' : ('./execnet/register.py', 'PopenGateway'), 'execnet.SshGateway' : ('./execnet/register.py', 'SshGateway'), + # input-output helping + 'io.dupfile' : ('./io/dupfile.py', 'dupfile'), + 'io.FDCapture' : ('./io/capture.py', 'FDCapture'), + 'io.OutErrCapture' : ('./io/capture.py', 'OutErrCapture'), + 'io.callcapture' : ('./io/capture.py', 'callcapture'), + # error module, defining all errno's as Classes 'error' : ('./misc/error.py', 'error'), Added: py/dist/py/io/__init__.py ============================================================================== --- (empty file) +++ py/dist/py/io/__init__.py Fri Jul 29 23:10:58 2005 @@ -0,0 +1 @@ +# Copied: py/dist/py/io/capture.py (from r15369, py/dist/py/misc/capture.py) ============================================================================== --- py/dist/py/misc/capture.py (original) +++ py/dist/py/io/capture.py Fri Jul 29 23:10:58 2005 @@ -1,44 +1,66 @@ import os, sys +import py class FDCapture: - def __init__(self, targetfd, sysattr=None): + """ Capture IO to/from a given os-level filedescriptor. """ + def __init__(self, targetfd, tmpfile=None): self.targetfd = targetfd - self.tmpfile = self.maketmpfile() + if tmpfile is None: + tmpfile = self.maketmpfile() + self.tmpfile = tmpfile self._savefd = os.dup(targetfd) os.dup2(self.tmpfile.fileno(), targetfd) - if sysattr is not None: - self._reset = (lambda oldval=getattr(sys, sysattr): - setattr(sys, sysattr, oldval)) - setattr(sys, sysattr, self.tmpfile) + self._patched = [] + + def setasfile(self, name, module=sys): + key = (module, name) + self._patched.append((key, getattr(module, name))) + setattr(module, name, self.tmpfile) + + def unsetfiles(self): + while self._patched: + (module, name), value = self._patched.pop() + setattr(module, name, value) def done(self): os.dup2(self._savefd, self.targetfd) - if hasattr(self, '_reset'): - self._reset() - del self._reset + self.unsetfiles() os.close(self._savefd) - f = self.tmpfile - f.seek(0) - del self._savefd - del self.tmpfile - return f + self.tmpfile.seek(0) + return self.tmpfile def maketmpfile(self): - return os.tmpfile() - -class Capture: + f = os.tmpfile() + newf = py.io.dupfile(f) + f.close() + return newf + +class OutErrCapture: + """ capture Stdout and Stderr both on filedescriptor + and sys.stdout/stderr level. + """ def __init__(self): - self._out = FDCapture(1, 'stdout') - self._oldsysout = sys.stdout - sys.stdout = self._out.tmpfile - - self._err = FDCapture(2, 'stderr') - self._olderrout = sys.stderr - sys.stderr = self._err.tmpfile + self.out = FDCapture(1) + self.out.setasfile('stdout') + self.err = FDCapture(2) + self.err.setasfile('stderr') def reset(self): - outfile = self._out.done() - errfile = self._err.done() + outfile = self.out.done() + errfile = self.err.done() return outfile.read(), errfile.read() + +def callcapture(func, *args, **kwargs): + """ call the given function with args/kwargs + and return a (res, out, err) tuple where + out and err represent the output/error output + during function execution. + """ + so = OutErrCapture() + try: + res = func(*args, **kwargs) + finally: + out, err = so.reset() + return res, out, err Added: py/dist/py/io/dupfile.py ============================================================================== --- (empty file) +++ py/dist/py/io/dupfile.py Fri Jul 29 23:10:58 2005 @@ -0,0 +1,13 @@ + +import os + +def dupfile(f, mode=None, buffering=0, raising=False): + try: + fd = f.fileno() + except AttributeError: + if raising: + raise + return f + newfd = os.dup(fd) + mode = mode and mode or f.mode + return os.fdopen(newfd, mode, buffering) Added: py/dist/py/io/test/__init__.py ============================================================================== --- (empty file) +++ py/dist/py/io/test/__init__.py Fri Jul 29 23:10:58 2005 @@ -0,0 +1 @@ +# Copied: py/dist/py/io/test/test_capture.py (from r15369, py/dist/py/misc/testing/test_simplecapture.py) ============================================================================== --- py/dist/py/misc/testing/test_simplecapture.py (original) +++ py/dist/py/io/test/test_capture.py Fri Jul 29 23:10:58 2005 @@ -1,29 +1,36 @@ 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) + cap = py.io.FDCapture(fd) os.write(fd, "hello") f = cap.done() s = f.read() assert s == "hello" def test_stderr(self): - cap = FDCapture(2, 'stderr') + cap = py.io.FDCapture(2) + cap.setasfile('stderr') print >>sys.stderr, "hello" f = cap.done() s = f.read() assert s == "hello\n" -class TestCapturingOnSys: + def test_stdin(self): + f = os.tmpfile() + print >>f, "3" + f.seek(0) + cap = py.io.FDCapture(0, tmpfile=f) + x = raw_input() + f = cap.done() + assert x == "3" +class TestCapturing: def getcapture(self): - return SimpleOutErrCapture() + return py.io.OutErrCapture() def test_capturing_simple(self): cap = self.getcapture() @@ -37,7 +44,7 @@ cap = self.getcapture() print "hello" cap.reset() - py.test.raises(AttributeError, "cap.reset()") + py.test.raises(EnvironmentError, "cap.reset()") def test_capturing_modify_sysouterr_in_between(self): oldout = sys.stdout @@ -56,12 +63,15 @@ assert sys.stderr == olderr def test_capturing_error_recursive(self): - cap = self.getcapture() + cap1 = self.getcapture() + print "cap1" cap2 = self.getcapture() - print "hello" - cap2.reset() - py.test.raises(AttributeError, "cap2.reset()") - cap.reset() + print "cap2" + out2, err2 = cap2.reset() + py.test.raises(EnvironmentError, "cap2.reset()") + out1, err1 = cap1.reset() + assert out1 == "cap1\n" + assert out2 == "cap2\n" def test_callcapture(): def func(x, y): @@ -69,11 +79,11 @@ print >>py.std.sys.stderr, y return 42 - res, out, err = callcapture(func, 3, y=4) + res, out, err = py.io.callcapture(func, 3, y=4) assert res == 42 assert out.startswith("3") assert err.startswith("4") -class TestCapturingOnFDs(TestCapturingOnSys): - def getcapture(self): - return Capture() +#class TestCapturingOnFDs(TestCapturingOnSys): +# def getcapture(self): +# return Capture() Added: py/dist/py/io/test/test_dupfile.py ============================================================================== --- (empty file) +++ py/dist/py/io/test/test_dupfile.py Fri Jul 29 23:10:58 2005 @@ -0,0 +1,20 @@ + +import py + +def test_dupfile(): + somefile = py.std.os.tmpfile() + flist = [] + for i in range(5): + nf = py.io.dupfile(somefile) + assert nf != somefile + assert nf.fileno() != somefile.fileno() + assert nf not in flist + print >>nf, i, + flist.append(nf) + for i in range(5): + f = flist[i] + f.close() + somefile.seek(0) + s = somefile.read() + assert s.startswith("01234") + somefile.close() Modified: py/dist/py/test/collect.py ============================================================================== --- py/dist/py/test/collect.py (original) +++ py/dist/py/test/collect.py Fri Jul 29 23:10:58 2005 @@ -25,7 +25,6 @@ """ from __future__ import generators import py -from py.__.misc.simplecapture import SimpleOutErrCapture isclass = py.std.inspect.isclass def configproperty(name): @@ -278,7 +277,9 @@ class Module(PyCollectorMixin, FSCollector): def startcapture(self): if not self.option.nocapture and not self.option.usepdb: - self._capture = SimpleOutErrCapture() + assert not hasattr(self, '_capture') + self._capture = py.io.OutErrCapture() + def finishcapture(self): if hasattr(self, '_capture'): capture = self._capture Modified: py/dist/py/test/item.py ============================================================================== --- py/dist/py/test/item.py (original) +++ py/dist/py/test/item.py Fri Jul 29 23:10:58 2005 @@ -1,7 +1,6 @@ import py from inspect import isclass, ismodule -from py.__.misc.simplecapture import SimpleOutErrCapture _dummy = object() @@ -33,7 +32,7 @@ class Item(py.test.collect.Collector): def startcapture(self): if not self.option.nocapture and not self.option.usepdb: - self._capture = SimpleOutErrCapture() + self._capture = py.io.OutErrCapture() def finishcapture(self): if hasattr(self, '_capture'): capture = self._capture Modified: py/dist/py/test/terminal/out.py ============================================================================== --- py/dist/py/test/terminal/out.py (original) +++ py/dist/py/test/terminal/out.py Fri Jul 29 23:10:58 2005 @@ -9,7 +9,7 @@ tty = False fullwidth = int(os.environ.get('COLUMNS', 80))-1 def __init__(self, file): - self.file = file + self.file = py.io.dupfile(file) def sep(self, sepchar, title=None): fullwidth = self.fullwidth Modified: py/dist/py/test/testing/test_session.py ============================================================================== --- py/dist/py/test/testing/test_session.py (original) +++ py/dist/py/test/testing/test_session.py Fri Jul 29 23:10:58 2005 @@ -1,7 +1,6 @@ import py datadir = py.magic.autopath().dirpath('data') from cStringIO import StringIO -from py.__.misc.simplecapture import callcapture tmpdir = py.test.ensuretemp('test_drive') @@ -193,10 +192,9 @@ """)) conftest = o.join('conftest.py').write(py.code.Source(""" import py - from py.__.misc.simplecapture import SimpleOutErrCapture class Function(py.test.Function): def startcapture(self): - self._mycapture = SimpleOutErrCapture() + self._mycapture = py.io.OutErrCapture() def finishcapture(self): self._testmycapture = self._mycapture.reset() Modified: py/dist/py/thread/testing/test_pool.py ============================================================================== --- py/dist/py/thread/testing/test_pool.py (original) +++ py/dist/py/thread/testing/test_pool.py Fri Jul 29 23:10:58 2005 @@ -70,8 +70,7 @@ pool.join(timeout=0.1) def test_pool_clean_shutdown(): - from py.__.misc.simplecapture import SimpleOutErrCapture - capture = SimpleOutErrCapture() + capture = py.io.OutErrCapture() pool = WorkerPool() def f(): pass From hpk at codespeak.net Sat Jul 30 08:44:33 2005 From: hpk at codespeak.net (hpk at codespeak.net) Date: Sat, 30 Jul 2005 08:44:33 +0200 (CEST) Subject: [py-svn] r15395 - in py/dist/py/io: . test Message-ID: <20050730064433.62FF727B61@code1.codespeak.net> Author: hpk Date: Sat Jul 30 08:44:29 2005 New Revision: 15395 Modified: py/dist/py/io/capture.py py/dist/py/io/test/test_capture.py Log: capturing API refinements Modified: py/dist/py/io/capture.py ============================================================================== --- py/dist/py/io/capture.py (original) +++ py/dist/py/io/capture.py Sat Jul 30 08:44:29 2005 @@ -40,17 +40,25 @@ """ capture Stdout and Stderr both on filedescriptor and sys.stdout/stderr level. """ - def __init__(self): - self.out = FDCapture(1) - self.out.setasfile('stdout') - self.err = FDCapture(2) - self.err.setasfile('stderr') + def __init__(self, out=True, err=True, patchsys=True): + if out: + self.out = FDCapture(1) + if patchsys: + self.out.setasfile('stdout') + if err: + self.err = FDCapture(2) + if patchsys: + self.err.setasfile('stderr') def reset(self): - outfile = self.out.done() - errfile = self.err.done() - return outfile.read(), errfile.read() - + out = err = "" + if hasattr(self, 'out'): + outfile = self.out.done() + out = outfile.read() + if hasattr(self, 'err'): + errfile = self.err.done() + err = errfile.read() + return out, err def callcapture(func, *args, **kwargs): """ call the given function with args/kwargs Modified: py/dist/py/io/test/test_capture.py ============================================================================== --- py/dist/py/io/test/test_capture.py (original) +++ py/dist/py/io/test/test_capture.py Sat Jul 30 08:44:29 2005 @@ -73,17 +73,55 @@ assert out1 == "cap1\n" assert out2 == "cap2\n" + def test_intermingling(self): + cap = self.getcapture() + os.write(1, "1") + print >>sys.stdout, 2, + os.write(1, "3") + os.write(2, "a") + print >>sys.stderr, "b", + os.write(2, "c") + out, err = cap.reset() + assert out == "123" + assert err == "abc" + def test_callcapture(): def func(x, y): print x print >>py.std.sys.stderr, y return 42 - + res, out, err = py.io.callcapture(func, 3, y=4) assert res == 42 assert out.startswith("3") assert err.startswith("4") - + +def test_just_out_capture(): + cap = py.io.OutErrCapture(out=True, err=False) + print >>sys.stdout, "hello" + print >>sys.stderr, "world" + out, err = cap.reset() + assert out == "hello\n" + assert not err + +def test_just_err_capture(): + cap = py.io.OutErrCapture(out=False, err=True) + print >>sys.stdout, "hello" + print >>sys.stderr, "world" + out, err = cap.reset() + assert err == "world\n" + assert not out + +def test_capture_no_sys(): + cap = py.io.OutErrCapture(patchsys=False) + print >>sys.stdout, "hello" + print >>sys.stderr, "world" + os.write(1, "1") + os.write(2, "2") + out, err = cap.reset() + assert out == "1" + assert err == "2" + #class TestCapturingOnFDs(TestCapturingOnSys): # def getcapture(self): # return Capture()