File: test_genscript.py

package info (click to toggle)
firefox-esr 52.8.1esr-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,983,244 kB
  • sloc: cpp: 4,810,275; ansic: 2,004,548; python: 451,282; java: 241,615; asm: 178,649; xml: 136,302; sh: 82,207; makefile: 22,575; perl: 15,783; objc: 4,389; yacc: 1,816; ada: 1,697; pascal: 1,519; lex: 1,257; cs: 879; exp: 499; php: 436; lisp: 258; awk: 152; sed: 51; ruby: 47; csh: 27
file content (51 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pytest
import sys


@pytest.fixture(scope="module")
def standalone(request):
    return Standalone(request)

class Standalone:
    def __init__(self, request):
        self.testdir = request.getfuncargvalue("testdir")
        script = "mypytest"
        result = self.testdir.runpytest("--genscript=%s" % script)
        assert result.ret == 0
        self.script = self.testdir.tmpdir.join(script)
        assert self.script.check()

    def run(self, anypython, testdir, *args):
        return testdir._run(anypython, self.script, *args)

def test_gen(testdir, anypython, standalone):
    if sys.version_info >= (2,7):
        result = testdir._run(anypython, "-c",
                                "import sys;print (sys.version_info >=(2,7))")
        assert result.ret == 0
        if result.stdout.str() == "False":
            pytest.skip("genscript called from python2.7 cannot work "
                        "earlier python versions")
    result = standalone.run(anypython, testdir, '--version')
    if result.ret == 2:
        result.stderr.fnmatch_lines(["*ERROR: setuptools not installed*"])
    elif result.ret == 0:
        result.stderr.fnmatch_lines([
            "*imported from*mypytest*"
        ])
        p = testdir.makepyfile("def test_func(): assert 0")
        result = standalone.run(anypython, testdir, p)
        assert result.ret != 0
    else:
        pytest.fail("Unexpected return code")


def test_freeze_includes():
    """
    Smoke test for freeze_includes(), to ensure that it works across all
    supported python versions.
    """
    includes = pytest.freeze_includes()
    assert len(includes) > 1
    assert '_pytest.genscript' in includes