[Python-checkins] python/dist/src/Lib doctest.py,1.36.2.5,1.36.2.6
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Tue Aug 3 20:45:27 CEST 2004
- Previous message: [Python-checkins] python/dist/src/Lib/lib-tk FileDialog.py, 1.10,
1.11 SimpleDialog.py, 1.5, 1.6 Tkinter.py, 1.180,
1.181 tkSimpleDialog.py, 1.9, 1.10
- Next message: [Python-checkins] python/dist/src/Misc NEWS,1.1065,1.1066
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14570
Modified Files:
Tag: tim-doctest-branch
doctest.py
Log Message:
Rehabilitate the old _SpoofOut class, but this time as a subclass of
StringIO. It's necessary that doctest fight with Python's "softspace"
gimmick, and hiding that fight in methods of the output-capturing class
is the only robust way to do it (softspace is always a potential
problem, and when it bites it causes an earlier test to screw up a
later test).
test_generators passes now. Miserably enough, the way softspace
screwed it spread across two distinct __test__ entries, with a
bunch of tests raising exceptions "in the middle" of the two. Whittled
down, this was enough to fail:
>>> print 1,
1
>>> [12, 666]
[12, 666]
Ironically enough, the only test that still fails is test_doctest <heh>.
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.36.2.5
retrieving revision 1.36.2.6
diff -C2 -d -r1.36.2.5 -r1.36.2.6
*** doctest.py 3 Aug 2004 15:58:09 -0000 1.36.2.5
--- doctest.py 3 Aug 2004 18:45:24 -0000 1.36.2.6
***************
*** 430,433 ****
--- 430,453 ----
return '%s:\n%s' % (tag, msg)
+ # Override some StringIO methods.
+ class _SpoofOut(StringIO):
+ def getvalue(self):
+ result = StringIO.getvalue(self)
+ # If anything at all was written, make sure there's a trailing
+ # newline. There's no way for the expected output to indicate
+ # that a trailing newline is missing.
+ if result and not result.endswith("\n"):
+ result += "\n"
+ # Prevent softspace from screwing up the next test case, in
+ # case they used print with a trailing comma in an example.
+ if hasattr(self, "softspace"):
+ del self.softspace
+ return result
+
+ def truncate(self, size=None):
+ StringIO.truncate(self, size)
+ if hasattr(self, "softspace"):
+ del self.softspace
+
######################################################################
## 2. Example & DocTest
***************
*** 933,937 ****
# Create a fake output target for capturing doctest output.
! self._fakeout = StringIO()
#/////////////////////////////////////////////////////////////////
--- 953,957 ----
# Create a fake output target for capturing doctest output.
! self._fakeout = _SpoofOut()
#/////////////////////////////////////////////////////////////////
***************
*** 1182,1186 ****
got = self._fakeout.getvalue()
self._fakeout.truncate(0)
- if got and got[-1:] != '\n': got += '\n'
# If the example executed without raising any exceptions,
--- 1202,1205 ----
- Previous message: [Python-checkins] python/dist/src/Lib/lib-tk FileDialog.py, 1.10,
1.11 SimpleDialog.py, 1.5, 1.6 Tkinter.py, 1.180,
1.181 tkSimpleDialog.py, 1.9, 1.10
- Next message: [Python-checkins] python/dist/src/Misc NEWS,1.1065,1.1066
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Python-checkins
mailing list