File: conftest.py

package info (click to toggle)
python-jedi 0.10.0~git1%2Bf05c071-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,064 kB
  • ctags: 3,014
  • sloc: python: 16,997; makefile: 149; ansic: 13
file content (60 lines) | stat: -rw-r--r-- 1,785 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
import os
import subprocess
import urllib
import zipfile

import pytest

VSPEC_URL = 'https://github.com/kana/vim-vspec/archive/1.4.1.zip'
CACHE_FOLDER = '.cache'
VSPEC_FOLDER = os.path.join(CACHE_FOLDER, 'vim-vspec-1.4.1')
VSPEC_RUNNER = os.path.join(VSPEC_FOLDER, 'bin/vspec')
TEST_DIR = 'test'


class IntegrationTestFile(object):
    def __init__(self, path):
        self.path = path

    def run(self):
        output = subprocess.check_output(
            [VSPEC_RUNNER, '.', VSPEC_FOLDER, self.path])
        for line in output.splitlines():
            if line.startswith(b'not ok') or line.startswith(b'Error'):
                pytest.fail("{0} failed:\n{1}".format(
                    self.path, output.decode('utf-8')), pytrace=False)

    def __repr__(self):
        return "<%s: %s>" % (type(self), self.path)


def pytest_configure(config):
    if not os.path.isdir(CACHE_FOLDER):
        os.mkdir(CACHE_FOLDER)

    if not os.path.exists(VSPEC_FOLDER):
        name, hdrs = urllib.urlretrieve(VSPEC_URL)
        z = zipfile.ZipFile(name)
        for n in z.namelist():
            dest = os.path.join(CACHE_FOLDER, n)
            destdir = os.path.dirname(dest)
            if not os.path.isdir(destdir):
                os.makedirs(destdir)
            data = z.read(n)
            if not os.path.isdir(dest):
                with open(dest, 'w') as f:
                    f.write(data)
        z.close()
        os.chmod(VSPEC_RUNNER, 0o777)


def pytest_generate_tests(metafunc):
    """
    :type metafunc: _pytest.python.Metafunc
    """
    def collect_tests():
        for f in os.listdir(TEST_DIR):
            if f.endswith('.vim'):
                yield IntegrationTestFile(os.path.join(TEST_DIR, f))

    metafunc.parametrize('case', list(collect_tests()))