Hi Guys, Line 396 of doctest.py contains code which is, at best, platform-specific (and so a bug) or, more likely, irrelevent. I have the following code that runs the tests in all my package's docs: def test_suite(): suite = unittest.TestSuite() for path in \ glob(os.path.join(os.path.dirname(__file__),'..','docs','*.txt')): suite.addTest( DocFileSuite(path, optionflags=REPORT_NDIFF|ELLIPSIS) ) return suite ...which runs fine on Windows (which makes me think that whole ValueError raise is bogus) and yet fails on Linux. Does anyone know why that raise is there? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
On Fri, Dec 19, 2008 at 1:03 PM, Chris Withers <chris@simplistix.co.uk> wrote:
Hi Guys,
Line 396 of doctest.py contains code which is, at best, platform-specific (and so a bug) or, more likely, irrelevent.
Line 396 of doctest.py from zope.testing 3.7.1 doesn't include a raise. I'm assuming you mean line 401 instead.
I have the following code that runs the tests in all my package's docs:
def test_suite(): suite = unittest.TestSuite() for path in \ glob(os.path.join(os.path.dirname(__file__),'..','docs','*.txt')): suite.addTest( DocFileSuite(path, optionflags=REPORT_NDIFF|ELLIPSIS) ) return suite
Paths to doctest files are relative to the calling module (by default). Also, DocFileSuite can take multiple paths, so your function can be simplified to this: def test_suite(): paths = glob(os.path.join('..', 'docs', '*.txt')) return DocFileSuite(*paths, optionflags=REPORT_NDIFF|ELLIPSIS) (You might want to use os.path.pardir instead of '..') -- Benji York Senior Software Engineer Zope Corporation
On Fri, Dec 19, 2008 at 01:37:52PM -0500, Benji York wrote:
On Fri, Dec 19, 2008 at 1:03 PM, Chris Withers <chris@simplistix.co.uk> wrote:
I have the following code that runs the tests in all my package's docs:
def test_suite(): suite = unittest.TestSuite() for path in \ glob(os.path.join(os.path.dirname(__file__),'..','docs','*.txt')): suite.addTest( DocFileSuite(path, optionflags=REPORT_NDIFF|ELLIPSIS) ) return suite
Paths to doctest files are relative to the calling module (by default).
To get them to accept paths relative to os.getcwd() (or absolute paths for that matter), pass module_relative=False to DocFileSuite.
Also, DocFileSuite can take multiple paths,
(I also always forget that.)
so your function can be simplified to this:
def test_suite(): paths = glob(os.path.join('..', 'docs', '*.txt')) return DocFileSuite(*paths, optionflags=REPORT_NDIFF|ELLIPSIS)
(You might want to use os.path.pardir instead of '..')
glob() will search relative to os.getcwd(), while DocFileSuite will search relative to os.path.dirname(__file__). The two may be different. Marius Gedminas -- http://pov.lt/ -- Zope 3 consulting and development
Benji York wrote:
On Fri, Dec 19, 2008 at 1:03 PM, Chris Withers <chris@simplistix.co.uk> wrote:
Hi Guys,
Line 396 of doctest.py contains code which is, at best, platform-specific (and so a bug) or, more likely, irrelevent.
Line 396 of doctest.py from zope.testing 3.7.1 doesn't include a raise. I'm assuming you mean line 401 instead.
Nope, typo on my part, I meant like 386/387: if path.startswith('/'): raise ValueError('Module-relative files may not have absolute ...which, as I said, runs fine on Windows (which makes me think that whole ValueError raise is bogus) and yet fails on Linux.
Also, DocFileSuite can take multiple paths, so your function can be simplified to this:
def test_suite(): paths = glob(os.path.join('..', 'docs', '*.txt')) return DocFileSuite(*paths, optionflags=REPORT_NDIFF|ELLIPSIS)
Not quite, that'll actually give you a syntax error ;-) Here's what I ended up with: def test_suite(): return DocFileSuite( optionflags=REPORT_NDIFF|ELLIPSIS, *glob(join(dirname(__file__),pardir,'docs','*.txt')) ) FWIW, I still think the check and raise that I meant to refer to are pointless and buggy. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Benji York -
Chris Withers -
Marius Gedminas