parent
							
								
									6d46efa87a
								
							
						
					
					
						commit
						88e61467f1
					
				| 
						 | 
					@ -13,9 +13,10 @@ def bincall(*args):
 | 
				
			||||||
    args[0] = os.path.join(BIN, args[0])
 | 
					    args[0] = os.path.join(BIN, args[0])
 | 
				
			||||||
    call(*args)
 | 
					    call(*args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
call("virtualenv", BUILDNAME, '--no-site-packages')
 | 
					call("virtualenv", os.path.abspath(BUILDNAME), '--no-site-packages')
 | 
				
			||||||
bincall("python", "setup.py", "develop", "-q")
 | 
					bincall("python", "setup.py", "develop", "-q")
 | 
				
			||||||
bincall("pip", "install", "-r", "testing/pip-reqs1.txt", 
 | 
					bincall("pip", "install", "-r", "testing/pip-reqs1.txt", 
 | 
				
			||||||
               "-q", "--download-cache=download")
 | 
					               "-q", "--download-cache=download")
 | 
				
			||||||
bincall("py.test", "-p", "xmlresult", "--xmlresult=junit.xml", 
 | 
					bincall("py.test", "--ignore", BUILDNAME, 
 | 
				
			||||||
        "--report=skipped", "--runslowtest")
 | 
					        "-p", "xmlresult", "--xmlresult=junit.xml", 
 | 
				
			||||||
 | 
					        "--report=skipped", "--runslowtest", *sys.argv[1:])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,4 @@
 | 
				
			||||||
import py
 | 
					import py
 | 
				
			||||||
#py.test.importorskip("pygments")
 | 
					#py.test.importorskip("pygments")
 | 
				
			||||||
pytest_plugins = ['pytest_restdoc']
 | 
					pytest_plugins = ['pytest_restdoc']
 | 
				
			||||||
rsyncdirs = ['.']
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
collect_ignore = ['test/attic.txt']
 | 
					collect_ignore = ['test/attic.txt']
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ funcargs and support code for testing py.test's own functionality.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import py
 | 
					import py
 | 
				
			||||||
import sys, os
 | 
					import sys, os
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
import inspect
 | 
					import inspect
 | 
				
			||||||
from py.impl.test.config import Config as pytestConfig
 | 
					from py.impl.test.config import Config as pytestConfig
 | 
				
			||||||
from py.plugin import hookspec
 | 
					from py.plugin import hookspec
 | 
				
			||||||
| 
						 | 
					@ -26,6 +27,7 @@ def pytest_funcarg__reportrecorder(request):
 | 
				
			||||||
    request.addfinalizer(lambda: reprec.comregistry.unregister(reprec))
 | 
					    request.addfinalizer(lambda: reprec.comregistry.unregister(reprec))
 | 
				
			||||||
    return reprec
 | 
					    return reprec
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rex_outcome = re.compile("(\d+) (\w+)")
 | 
				
			||||||
class RunResult:
 | 
					class RunResult:
 | 
				
			||||||
    def __init__(self, ret, outlines, errlines):
 | 
					    def __init__(self, ret, outlines, errlines):
 | 
				
			||||||
        self.ret = ret
 | 
					        self.ret = ret
 | 
				
			||||||
| 
						 | 
					@ -33,6 +35,15 @@ class RunResult:
 | 
				
			||||||
        self.errlines = errlines
 | 
					        self.errlines = errlines
 | 
				
			||||||
        self.stdout = LineMatcher(outlines)
 | 
					        self.stdout = LineMatcher(outlines)
 | 
				
			||||||
        self.stderr = LineMatcher(errlines)
 | 
					        self.stderr = LineMatcher(errlines)
 | 
				
			||||||
 | 
					    def parseoutcomes(self):
 | 
				
			||||||
 | 
					        for line in reversed(self.outlines):
 | 
				
			||||||
 | 
					            if 'seconds' in line:
 | 
				
			||||||
 | 
					                outcomes = rex_outcome.findall(line)
 | 
				
			||||||
 | 
					                if outcomes:
 | 
				
			||||||
 | 
					                    d = {}
 | 
				
			||||||
 | 
					                    for num, cat in outcomes:
 | 
				
			||||||
 | 
					                        d[cat] = int(num)
 | 
				
			||||||
 | 
					                    return d
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TmpTestdir:
 | 
					class TmpTestdir:
 | 
				
			||||||
    def __init__(self, request):
 | 
					    def __init__(self, request):
 | 
				
			||||||
| 
						 | 
					@ -245,17 +256,6 @@ class TmpTestdir:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return self.config.getfsnode(path)
 | 
					        return self.config.getfsnode(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def prepare(self):
 | 
					 | 
				
			||||||
        p = self.tmpdir.join("conftest.py") 
 | 
					 | 
				
			||||||
        if not p.check():
 | 
					 | 
				
			||||||
            plugins = [x for x in self.plugins if isinstance(x, str)]
 | 
					 | 
				
			||||||
            if not plugins:
 | 
					 | 
				
			||||||
                return
 | 
					 | 
				
			||||||
            p.write("import py ; pytest_plugins = %r" % plugins)
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            if self.plugins:
 | 
					 | 
				
			||||||
                print ("warning, ignoring reusing existing %s" % p)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def popen(self, cmdargs, stdout, stderr, **kw):
 | 
					    def popen(self, cmdargs, stdout, stderr, **kw):
 | 
				
			||||||
        if not hasattr(py.std, 'subprocess'):
 | 
					        if not hasattr(py.std, 'subprocess'):
 | 
				
			||||||
            py.test.skip("no subprocess module")
 | 
					            py.test.skip("no subprocess module")
 | 
				
			||||||
| 
						 | 
					@ -267,7 +267,6 @@ class TmpTestdir:
 | 
				
			||||||
        return py.std.subprocess.Popen(cmdargs, stdout=stdout, stderr=stderr, **kw)
 | 
					        return py.std.subprocess.Popen(cmdargs, stdout=stdout, stderr=stderr, **kw)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def run(self, *cmdargs):
 | 
					    def run(self, *cmdargs):
 | 
				
			||||||
        self.prepare()
 | 
					 | 
				
			||||||
        old = self.tmpdir.chdir()
 | 
					        old = self.tmpdir.chdir()
 | 
				
			||||||
        #print "chdir", self.tmpdir
 | 
					        #print "chdir", self.tmpdir
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
| 
						 | 
					@ -316,6 +315,9 @@ class TmpTestdir:
 | 
				
			||||||
        p = py.path.local.make_numbered_dir(prefix="runpytest-", 
 | 
					        p = py.path.local.make_numbered_dir(prefix="runpytest-", 
 | 
				
			||||||
            keep=None, rootdir=self.tmpdir)
 | 
					            keep=None, rootdir=self.tmpdir)
 | 
				
			||||||
        args = ('--basetemp=%s' % p, ) + args 
 | 
					        args = ('--basetemp=%s' % p, ) + args 
 | 
				
			||||||
 | 
					        plugins = [x for x in self.plugins if isinstance(x, str)]
 | 
				
			||||||
 | 
					        if plugins:
 | 
				
			||||||
 | 
					            args = ('-p', plugins[0]) + args
 | 
				
			||||||
        return self.runpybin("py.test", *args)
 | 
					        return self.runpybin("py.test", *args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def spawn_pytest(self, string, expect_timeout=10.0):
 | 
					    def spawn_pytest(self, string, expect_timeout=10.0):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
docutils
 | 
					docutils
 | 
				
			||||||
pexpect
 | 
					pexpect
 | 
				
			||||||
 | 
					figleaf
 | 
				
			||||||
hg+http://bitbucket.org/hpk42/execnet#egg=execnet
 | 
					hg+http://bitbucket.org/hpk42/execnet#egg=execnet
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,53 +8,16 @@ def test_deindent():
 | 
				
			||||||
    assert deindent(' foo\n  bar\n') == 'foo\n bar\n'
 | 
					    assert deindent(' foo\n  bar\n') == 'foo\n bar\n'
 | 
				
			||||||
    assert deindent('  foo\n bar\n') == ' foo\nbar\n'
 | 
					    assert deindent('  foo\n bar\n') == ' foo\nbar\n'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestApigenLinkRole:
 | 
					 | 
				
			||||||
    disabled = True
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # these tests are moved here from the former py/doc/conftest.py
 | 
					 | 
				
			||||||
    def test_resolve_linkrole(self):
 | 
					 | 
				
			||||||
        from py.impl.doc.conftest import get_apigen_relpath
 | 
					 | 
				
			||||||
        apigen_relpath = get_apigen_relpath()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        assert resolve_linkrole('api', 'py.foo.bar', False) == (
 | 
					 | 
				
			||||||
            'py.foo.bar', apigen_relpath + 'api/foo.bar.html')
 | 
					 | 
				
			||||||
        assert resolve_linkrole('api', 'py.foo.bar()', False) == (
 | 
					 | 
				
			||||||
            'py.foo.bar()', apigen_relpath + 'api/foo.bar.html')
 | 
					 | 
				
			||||||
        assert resolve_linkrole('api', 'py', False) == (
 | 
					 | 
				
			||||||
            'py', apigen_relpath + 'api/index.html')
 | 
					 | 
				
			||||||
        py.test.raises(AssertionError, 'resolve_linkrole("api", "foo.bar")')
 | 
					 | 
				
			||||||
        assert resolve_linkrole('source', 'py/foo/bar.py', False) == (
 | 
					 | 
				
			||||||
            'py/foo/bar.py', apigen_relpath + 'source/foo/bar.py.html')
 | 
					 | 
				
			||||||
        assert resolve_linkrole('source', 'py/foo/', False) == (
 | 
					 | 
				
			||||||
            'py/foo/', apigen_relpath + 'source/foo/index.html')
 | 
					 | 
				
			||||||
        assert resolve_linkrole('source', 'py/', False) == (
 | 
					 | 
				
			||||||
            'py/', apigen_relpath + 'source/index.html')
 | 
					 | 
				
			||||||
        py.test.raises(AssertionError, 'resolve_linkrole("source", "/foo/bar/")')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_resolve_linkrole_check_api(self):
 | 
					 | 
				
			||||||
        assert resolve_linkrole('api', 'py.test.ensuretemp')
 | 
					 | 
				
			||||||
        py.test.raises(AssertionError, "resolve_linkrole('api', 'py.foo.baz')")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_resolve_linkrole_check_source(self):
 | 
					 | 
				
			||||||
        assert resolve_linkrole('source', 'py/path/common.py')
 | 
					 | 
				
			||||||
        py.test.raises(AssertionError,
 | 
					 | 
				
			||||||
                       "resolve_linkrole('source', 'py/foo/bar.py')")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class TestDoctest:
 | 
					class TestDoctest:
 | 
				
			||||||
    def pytest_funcarg__testdir(self, request):
 | 
					    def pytest_funcarg__testdir(self, request):
 | 
				
			||||||
        testdir = request.getfuncargvalue("testdir")
 | 
					        testdir = request.getfuncargvalue("testdir")
 | 
				
			||||||
 | 
					        testdir.plugins.append("restdoc")
 | 
				
			||||||
        assert request.module.__name__ == __name__
 | 
					        assert request.module.__name__ == __name__
 | 
				
			||||||
        testdir.makepyfile(confrest=
 | 
					        testdir.makepyfile(confrest=
 | 
				
			||||||
            "from py.plugin.pytest_restdoc import Project")
 | 
					            "from py.plugin.pytest_restdoc import Project")
 | 
				
			||||||
        # we scope our confrest file so that it doesn't
 | 
					        # we scope our confrest file so that it doesn't
 | 
				
			||||||
        # conflict with another global confrest.py 
 | 
					        # conflict with another global confrest.py 
 | 
				
			||||||
        testdir.makepyfile(__init__="")
 | 
					        testdir.makepyfile(__init__="")
 | 
				
			||||||
        for p in testdir.plugins:
 | 
					 | 
				
			||||||
            if p == globals():
 | 
					 | 
				
			||||||
                break
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            testdir.plugins.append(globals())
 | 
					 | 
				
			||||||
        return testdir
 | 
					        return testdir
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def test_doctest_extra_exec(self, testdir):
 | 
					    def test_doctest_extra_exec(self, testdir):
 | 
				
			||||||
| 
						 | 
					@ -63,9 +26,8 @@ class TestDoctest:
 | 
				
			||||||
                .. >>> raise ValueError 
 | 
					                .. >>> raise ValueError 
 | 
				
			||||||
                   >>> None
 | 
					                   >>> None
 | 
				
			||||||
        """)
 | 
					        """)
 | 
				
			||||||
        reprec = testdir.inline_run(xtxt)
 | 
					        result = testdir.runpytest(xtxt)
 | 
				
			||||||
        passed, skipped, failed = reprec.countoutcomes()
 | 
					        result.stdout.fnmatch_lines(['*1 fail*'])
 | 
				
			||||||
        assert failed == 1
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_doctest_basic(self, testdir): 
 | 
					    def test_doctest_basic(self, testdir): 
 | 
				
			||||||
        xtxt = testdir.maketxtfile(x="""
 | 
					        xtxt = testdir.maketxtfile(x="""
 | 
				
			||||||
| 
						 | 
					@ -86,25 +48,21 @@ class TestDoctest:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            end
 | 
					            end
 | 
				
			||||||
        """)
 | 
					        """)
 | 
				
			||||||
        reprec = testdir.inline_run(xtxt)
 | 
					        result = testdir.runpytest(xtxt)
 | 
				
			||||||
        passed, skipped, failed = reprec.countoutcomes()
 | 
					        result.stdout.fnmatch_lines([
 | 
				
			||||||
        assert failed == 0 
 | 
					            "*2 passed*"
 | 
				
			||||||
        assert passed + skipped == 2
 | 
					        ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_doctest_eol(self, testdir): 
 | 
					    def test_doctest_eol(self, testdir): 
 | 
				
			||||||
        ytxt = testdir.maketxtfile(y=".. >>> 1 + 1\r\n   2\r\n\r\n")
 | 
					        ytxt = testdir.maketxtfile(y=".. >>> 1 + 1\r\n   2\r\n\r\n")
 | 
				
			||||||
        reprec = testdir.inline_run(ytxt)
 | 
					        result = testdir.runpytest(ytxt)
 | 
				
			||||||
        passed, skipped, failed = reprec.countoutcomes()
 | 
					        result.stdout.fnmatch_lines(["*2 passed*"])
 | 
				
			||||||
        assert failed == 0 
 | 
					 | 
				
			||||||
        assert passed + skipped == 2
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_doctest_indentation(self, testdir):
 | 
					    def test_doctest_indentation(self, testdir):
 | 
				
			||||||
        footxt = testdir.maketxtfile(foo=
 | 
					        footxt = testdir.maketxtfile(foo=
 | 
				
			||||||
            '..\n  >>> print ("foo\\n  bar")\n  foo\n    bar\n')
 | 
					            '..\n  >>> print ("foo\\n  bar")\n  foo\n    bar\n')
 | 
				
			||||||
        reprec = testdir.inline_run(footxt)
 | 
					        result = testdir.runpytest(footxt)
 | 
				
			||||||
        passed, skipped, failed = reprec.countoutcomes()
 | 
					        result.stdout.fnmatch_lines(["*2 passed*"])
 | 
				
			||||||
        assert failed == 0
 | 
					 | 
				
			||||||
        assert skipped + passed == 2 
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_js_ignore(self, testdir):
 | 
					    def test_js_ignore(self, testdir):
 | 
				
			||||||
        xtxt = testdir.maketxtfile(xtxt="""
 | 
					        xtxt = testdir.maketxtfile(xtxt="""
 | 
				
			||||||
| 
						 | 
					@ -112,20 +70,14 @@ class TestDoctest:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            .. _`blah`: javascript:some_function()
 | 
					            .. _`blah`: javascript:some_function()
 | 
				
			||||||
        """)
 | 
					        """)
 | 
				
			||||||
        reprec = testdir.inline_run(xtxt)
 | 
					        result = testdir.runpytest(xtxt)
 | 
				
			||||||
        passed, skipped, failed = reprec.countoutcomes()
 | 
					        result.stdout.fnmatch_lines(["*3 passed*"])
 | 
				
			||||||
        assert failed == 0
 | 
					 | 
				
			||||||
        assert skipped + passed == 3 
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_pytest_doctest_prepare_content(self, testdir):
 | 
					    def test_pytest_doctest_prepare_content(self, testdir):
 | 
				
			||||||
        l = []
 | 
					        testdir.makeconftest("""
 | 
				
			||||||
        class MyPlugin:
 | 
					            def pytest_doctest_prepare_content(content):
 | 
				
			||||||
            def pytest_doctest_prepare_content(self, content):
 | 
					 | 
				
			||||||
                l.append(content)
 | 
					 | 
				
			||||||
                return content.replace("False", "True")
 | 
					                return content.replace("False", "True")
 | 
				
			||||||
 | 
					        """)
 | 
				
			||||||
        testdir.plugins.append(MyPlugin())
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        xtxt = testdir.maketxtfile(x="""
 | 
					        xtxt = testdir.maketxtfile(x="""
 | 
				
			||||||
            hello:
 | 
					            hello:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,9 +85,8 @@ class TestDoctest:
 | 
				
			||||||
                False
 | 
					                False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        """)
 | 
					        """)
 | 
				
			||||||
        reprec = testdir.inline_run(xtxt)
 | 
					        result = testdir.runpytest(xtxt)
 | 
				
			||||||
        assert len(l) == 1
 | 
					        outcomes = result.parseoutcomes()
 | 
				
			||||||
        passed, skipped, failed = reprec.countoutcomes()
 | 
					        assert outcomes['passed'] >= 1
 | 
				
			||||||
        assert passed >= 1
 | 
					        assert 'failed' not in outcomes
 | 
				
			||||||
        assert not failed 
 | 
					        assert 'skipped' not in outcomes 
 | 
				
			||||||
        assert skipped <= 1
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue