2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
import py
|
2007-02-03 20:14:46 +08:00
|
|
|
from py.__.test.outcome import Skipped, Failed, Passed
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
def setup_module(mod):
|
|
|
|
mod.tmpdir = py.test.ensuretemp('docdoctest')
|
|
|
|
|
2007-02-08 05:31:13 +08:00
|
|
|
def test_doctest_extra_exec():
|
|
|
|
# XXX get rid of the next line:
|
|
|
|
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
|
|
|
xtxt = tmpdir.join('y.txt')
|
|
|
|
xtxt.write(py.code.Source("""
|
|
|
|
hello::
|
|
|
|
.. >>> raise ValueError
|
|
|
|
>>> None
|
|
|
|
"""))
|
|
|
|
config = py.test.config._reparse([xtxt])
|
|
|
|
session = config.initsession()
|
|
|
|
session.main()
|
|
|
|
l = session.getitemoutcomepairs(Failed)
|
|
|
|
assert len(l) == 1
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
def test_doctest_basic():
|
|
|
|
# XXX get rid of the next line:
|
|
|
|
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
|
|
|
|
|
|
|
xtxt = tmpdir.join('x.txt')
|
|
|
|
xtxt.write(py.code.Source("""
|
|
|
|
..
|
|
|
|
>>> from os.path import abspath
|
|
|
|
|
|
|
|
hello world
|
|
|
|
|
|
|
|
>>> assert abspath
|
|
|
|
>>> i=3
|
|
|
|
>>> print i
|
|
|
|
3
|
|
|
|
|
|
|
|
yes yes
|
|
|
|
|
|
|
|
>>> i
|
|
|
|
3
|
|
|
|
|
|
|
|
end
|
|
|
|
"""))
|
|
|
|
config = py.test.config._reparse([xtxt])
|
2007-01-25 00:46:46 +08:00
|
|
|
session = config.initsession()
|
2007-01-24 22:24:01 +08:00
|
|
|
session.main()
|
2007-02-03 20:14:46 +08:00
|
|
|
l = session.getitemoutcomepairs(Failed)
|
2007-01-24 22:24:01 +08:00
|
|
|
assert len(l) == 0
|
2007-02-03 20:14:46 +08:00
|
|
|
l = session.getitemoutcomepairs(Passed)
|
|
|
|
l2 = session.getitemoutcomepairs(Skipped)
|
2007-01-24 22:24:01 +08:00
|
|
|
assert len(l+l2) == 2
|
|
|
|
|
2007-02-08 21:47:23 +08:00
|
|
|
def test_deindent():
|
|
|
|
from py.__.doc.conftest import deindent
|
|
|
|
assert deindent('foo') == 'foo'
|
|
|
|
assert deindent('foo\n bar') == 'foo\n bar'
|
|
|
|
assert deindent(' foo\n bar\n') == 'foo\nbar\n'
|
|
|
|
assert deindent(' foo\n\n bar\n') == 'foo\n\nbar\n'
|
|
|
|
assert deindent(' foo\n bar\n') == 'foo\n bar\n'
|
|
|
|
assert deindent(' foo\n bar\n') == ' foo\nbar\n'
|
|
|
|
|
2007-01-25 22:08:48 +08:00
|
|
|
def test_doctest_eol():
|
|
|
|
# XXX get rid of the next line:
|
|
|
|
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
|
|
|
|
|
|
|
ytxt = tmpdir.join('y.txt')
|
|
|
|
ytxt.write(py.code.Source(".. >>> 1 + 1\r\n 2\r\n\r\n"))
|
|
|
|
config = py.test.config._reparse([ytxt])
|
|
|
|
session = config.initsession()
|
|
|
|
session.main()
|
2007-02-03 20:14:46 +08:00
|
|
|
l = session.getitemoutcomepairs(Failed)
|
2007-01-25 22:08:48 +08:00
|
|
|
assert len(l) == 0
|
2007-02-03 20:14:46 +08:00
|
|
|
l = session.getitemoutcomepairs(Passed)
|
2007-02-08 21:47:23 +08:00
|
|
|
l2 = session.getitemoutcomepairs(Skipped)
|
|
|
|
assert len(l+l2) == 2
|
|
|
|
|
|
|
|
def test_doctest_indentation():
|
|
|
|
# XXX get rid of the next line:
|
|
|
|
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
|
|
|
|
|
|
|
txt = tmpdir.join('foo.txt')
|
|
|
|
txt.write('..\n >>> print "foo\\n bar"\n foo\n bar\n')
|
|
|
|
config = py.test.config._reparse([txt])
|
|
|
|
session = config.initsession()
|
|
|
|
session.main()
|
|
|
|
l = session.getitemoutcomepairs(Failed)
|
|
|
|
assert len(l) == 0
|
|
|
|
l = session.getitemoutcomepairs(Passed)
|
2007-02-03 20:14:46 +08:00
|
|
|
l2 = session.getitemoutcomepairs(Skipped)
|
2007-01-25 22:08:48 +08:00
|
|
|
assert len(l+l2) == 2
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
def test_js_ignore():
|
|
|
|
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
|
|
|
tmpdir.ensure('__init__.py')
|
|
|
|
xtxt = tmpdir.join('x.txt')
|
|
|
|
xtxt.write(py.code.Source("""
|
|
|
|
`blah`_
|
|
|
|
|
|
|
|
.. _`blah`: javascript:some_function()
|
|
|
|
"""))
|
|
|
|
config = py.test.config._reparse([xtxt])
|
2007-01-25 00:46:46 +08:00
|
|
|
session = config.initsession()
|
2007-01-24 22:24:01 +08:00
|
|
|
session.main()
|
2007-02-03 20:14:46 +08:00
|
|
|
l = session.getitemoutcomepairs(Failed)
|
2007-01-24 22:24:01 +08:00
|
|
|
assert len(l) == 0
|
2007-02-03 20:14:46 +08:00
|
|
|
l = session.getitemoutcomepairs(Passed)
|
|
|
|
l2 = session.getitemoutcomepairs(Skipped)
|
2007-01-24 22:24:01 +08:00
|
|
|
assert len(l+l2) == 3
|
|
|
|
|
|
|
|
def test_resolve_linkrole():
|
2007-02-02 08:00:50 +08:00
|
|
|
from py.__.doc.conftest import resolve_linkrole
|
|
|
|
assert resolve_linkrole('api', 'py.foo.bar', False) == (
|
2007-01-24 22:24:01 +08:00
|
|
|
'py.foo.bar', '../../apigen/api/foo.bar.html')
|
2007-02-02 08:00:50 +08:00
|
|
|
assert resolve_linkrole('api', 'py.foo.bar()', False) == (
|
2007-01-24 22:24:01 +08:00
|
|
|
'py.foo.bar()', '../../apigen/api/foo.bar.html')
|
2007-02-02 08:00:50 +08:00
|
|
|
assert resolve_linkrole('api', 'py', False) == (
|
2007-01-24 22:24:01 +08:00
|
|
|
'py', '../../apigen/api/index.html')
|
|
|
|
py.test.raises(AssertionError, 'resolve_linkrole("api", "foo.bar")')
|
2007-02-02 08:00:50 +08:00
|
|
|
assert resolve_linkrole('source', 'py/foo/bar.py', False) == (
|
2007-01-24 22:24:01 +08:00
|
|
|
'py/foo/bar.py', '../../apigen/source/foo/bar.py.html')
|
2007-02-02 08:00:50 +08:00
|
|
|
assert resolve_linkrole('source', 'py/foo/', False) == (
|
2007-01-24 22:24:01 +08:00
|
|
|
'py/foo/', '../../apigen/source/foo/index.html')
|
2007-02-02 08:00:50 +08:00
|
|
|
assert resolve_linkrole('source', 'py/', False) == (
|
2007-01-24 22:24:01 +08:00
|
|
|
'py/', '../../apigen/source/index.html')
|
|
|
|
py.test.raises(AssertionError, 'resolve_linkrole("source", "/foo/bar/")')
|
|
|
|
|
2007-02-02 08:00:50 +08:00
|
|
|
def test_resolve_linkrole_check_api():
|
|
|
|
from py.__.doc.conftest import resolve_linkrole
|
|
|
|
assert resolve_linkrole('api', 'py.test.ensuretemp')
|
2007-02-02 06:30:51 +08:00
|
|
|
py.test.raises(AssertionError, "resolve_linkrole('api', 'py.foo.baz')")
|
|
|
|
|
2007-02-02 08:00:50 +08:00
|
|
|
def test_resolve_linkrole_check_source():
|
|
|
|
from py.__.doc.conftest import resolve_linkrole
|
|
|
|
assert resolve_linkrole('source', 'py/path/common.py')
|
|
|
|
py.test.raises(AssertionError,
|
|
|
|
"resolve_linkrole('source', 'py/foo/bar.py')")
|
|
|
|
|