2009-11-05 04:34:07 +08:00
|
|
|
from py.plugin.pytest_restdoc import deindent
|
2009-09-06 22:59:39 +08:00
|
|
|
|
|
|
|
def test_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'
|
|
|
|
|
|
|
|
class TestDoctest:
|
|
|
|
def pytest_funcarg__testdir(self, request):
|
|
|
|
testdir = request.getfuncargvalue("testdir")
|
2009-12-25 07:24:58 +08:00
|
|
|
testdir.plugins.append("restdoc")
|
2009-09-06 22:59:39 +08:00
|
|
|
assert request.module.__name__ == __name__
|
2009-10-29 19:25:47 +08:00
|
|
|
testdir.makepyfile(confrest=
|
2009-11-05 04:34:07 +08:00
|
|
|
"from py.plugin.pytest_restdoc import Project")
|
2009-11-24 22:16:58 +08:00
|
|
|
# we scope our confrest file so that it doesn't
|
|
|
|
# conflict with another global confrest.py
|
|
|
|
testdir.makepyfile(__init__="")
|
2009-09-06 22:59:39 +08:00
|
|
|
return testdir
|
|
|
|
|
|
|
|
def test_doctest_extra_exec(self, testdir):
|
|
|
|
xtxt = testdir.maketxtfile(x="""
|
|
|
|
hello::
|
|
|
|
.. >>> raise ValueError
|
|
|
|
>>> None
|
|
|
|
""")
|
2009-12-25 07:24:58 +08:00
|
|
|
result = testdir.runpytest(xtxt)
|
|
|
|
result.stdout.fnmatch_lines(['*1 fail*'])
|
2009-09-06 22:59:39 +08:00
|
|
|
|
|
|
|
def test_doctest_basic(self, testdir):
|
|
|
|
xtxt = testdir.maketxtfile(x="""
|
|
|
|
..
|
|
|
|
>>> from os.path import abspath
|
|
|
|
|
|
|
|
hello world
|
|
|
|
|
|
|
|
>>> assert abspath
|
|
|
|
>>> i=3
|
|
|
|
>>> print (i)
|
|
|
|
3
|
|
|
|
|
|
|
|
yes yes
|
|
|
|
|
|
|
|
>>> i
|
|
|
|
3
|
|
|
|
|
|
|
|
end
|
|
|
|
""")
|
2009-12-25 07:24:58 +08:00
|
|
|
result = testdir.runpytest(xtxt)
|
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"*2 passed*"
|
|
|
|
])
|
2009-09-06 22:59:39 +08:00
|
|
|
|
|
|
|
def test_doctest_eol(self, testdir):
|
|
|
|
ytxt = testdir.maketxtfile(y=".. >>> 1 + 1\r\n 2\r\n\r\n")
|
2009-12-25 07:24:58 +08:00
|
|
|
result = testdir.runpytest(ytxt)
|
|
|
|
result.stdout.fnmatch_lines(["*2 passed*"])
|
2009-09-06 22:59:39 +08:00
|
|
|
|
|
|
|
def test_doctest_indentation(self, testdir):
|
|
|
|
footxt = testdir.maketxtfile(foo=
|
|
|
|
'..\n >>> print ("foo\\n bar")\n foo\n bar\n')
|
2009-12-25 07:24:58 +08:00
|
|
|
result = testdir.runpytest(footxt)
|
|
|
|
result.stdout.fnmatch_lines(["*2 passed*"])
|
2009-09-06 22:59:39 +08:00
|
|
|
|
|
|
|
def test_js_ignore(self, testdir):
|
|
|
|
xtxt = testdir.maketxtfile(xtxt="""
|
|
|
|
`blah`_
|
|
|
|
|
|
|
|
.. _`blah`: javascript:some_function()
|
|
|
|
""")
|
2009-12-25 07:24:58 +08:00
|
|
|
result = testdir.runpytest(xtxt)
|
|
|
|
result.stdout.fnmatch_lines(["*3 passed*"])
|
2009-09-06 22:59:39 +08:00
|
|
|
|
|
|
|
def test_pytest_doctest_prepare_content(self, testdir):
|
2009-12-25 07:24:58 +08:00
|
|
|
testdir.makeconftest("""
|
|
|
|
def pytest_doctest_prepare_content(content):
|
2009-09-06 22:59:39 +08:00
|
|
|
return content.replace("False", "True")
|
2009-12-25 07:24:58 +08:00
|
|
|
""")
|
2009-09-06 22:59:39 +08:00
|
|
|
xtxt = testdir.maketxtfile(x="""
|
|
|
|
hello:
|
|
|
|
|
|
|
|
>>> 2 == 2
|
|
|
|
False
|
|
|
|
|
|
|
|
""")
|
2009-12-25 07:24:58 +08:00
|
|
|
result = testdir.runpytest(xtxt)
|
|
|
|
outcomes = result.parseoutcomes()
|
|
|
|
assert outcomes['passed'] >= 1
|
|
|
|
assert 'failed' not in outcomes
|
|
|
|
assert 'skipped' not in outcomes
|