mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-06 10:54:22 +08:00
tests: move/rename/cleanup vspec based tests (#860)
The main motivation is to being able to use normal/other pytest based tests. Therefore this moves everything from conftest into test_integration itself.
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,8 +1,8 @@
|
|||||||
test:
|
test:
|
||||||
pytest test_*.py
|
pytest
|
||||||
|
|
||||||
test_nvim:
|
test_nvim:
|
||||||
VSPEC_VIM=nvim pytest test_*.py
|
VSPEC_VIM=nvim pytest
|
||||||
|
|
||||||
test_coverage: export PYTEST_ADDOPTS:=--cov pythonx --cov test --cov-report=term-missing:skip-covered
|
test_coverage: export PYTEST_ADDOPTS:=--cov pythonx --cov test --cov-report=term-missing:skip-covered
|
||||||
test_coverage: test_nvim
|
test_coverage: test_nvim
|
||||||
|
|||||||
78
conftest.py
78
conftest.py
@@ -1,78 +0,0 @@
|
|||||||
import os
|
|
||||||
import subprocess
|
|
||||||
try:
|
|
||||||
from urllib.request import urlretrieve
|
|
||||||
except ImportError:
|
|
||||||
from urllib import urlretrieve
|
|
||||||
import zipfile
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
VSPEC_URL = 'https://github.com/kana/vim-vspec/archive/1.8.1.zip'
|
|
||||||
CACHE_FOLDER = 'build'
|
|
||||||
VSPEC_FOLDER = os.path.join(CACHE_FOLDER, 'vim-vspec-1.8.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])
|
|
||||||
had_ok = False
|
|
||||||
for line in output.splitlines():
|
|
||||||
if (line.startswith(b'not ok') or
|
|
||||||
line.startswith(b'Error') or
|
|
||||||
line.startswith(b'Bail out!')):
|
|
||||||
pytest.fail("{0} failed:\n{1}".format(
|
|
||||||
self.path, output.decode('utf-8')), pytrace=False)
|
|
||||||
if not had_ok and line.startswith(b'ok'):
|
|
||||||
had_ok = True
|
|
||||||
if not had_ok:
|
|
||||||
pytest.fail("{0} failed: no 'ok' found:\n{1}".format(
|
|
||||||
self.path, output.decode('utf-8')), pytrace=False)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
name = os.path.basename(self.path)
|
|
||||||
name, _, _ = name.rpartition('.')
|
|
||||||
return name
|
|
||||||
|
|
||||||
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 = 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, 'wb') 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') and f != '_utils.vim':
|
|
||||||
yield IntegrationTestFile(os.path.join(TEST_DIR, f))
|
|
||||||
|
|
||||||
tests = list(collect_tests())
|
|
||||||
metafunc.parametrize('case', tests, ids=[test.name for test in tests])
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[pytest]
|
|
||||||
# Ignore all files
|
|
||||||
norecursedirs = *
|
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
|
[tool:pytest]
|
||||||
|
testpaths = test
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
max-line-length = 100
|
max-line-length = 100
|
||||||
|
|||||||
65
test/test_integration.py
Normal file
65
test/test_integration.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
"""Runs tests from ./vspec in vim-vspec."""
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
try:
|
||||||
|
from urllib.request import urlretrieve
|
||||||
|
except ImportError:
|
||||||
|
from urllib import urlretrieve
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
vspec_version = '1.8.1'
|
||||||
|
|
||||||
|
VSPEC_URL = 'https://github.com/kana/vim-vspec/archive/%s.zip' % vspec_version
|
||||||
|
root = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
CACHE_FOLDER = os.path.join(root, 'build')
|
||||||
|
VSPEC_FOLDER = os.path.join(CACHE_FOLDER, 'vim-vspec-%s' % vspec_version)
|
||||||
|
VSPEC_RUNNER = os.path.join(VSPEC_FOLDER, 'bin/vspec')
|
||||||
|
TEST_DIR = os.path.join(root, 'test', 'vspec')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def install_vspec(request):
|
||||||
|
if not os.path.isdir(CACHE_FOLDER):
|
||||||
|
os.mkdir(CACHE_FOLDER)
|
||||||
|
|
||||||
|
if not os.path.exists(VSPEC_FOLDER):
|
||||||
|
name, hdrs = 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, 'wb') as f:
|
||||||
|
f.write(data)
|
||||||
|
z.close()
|
||||||
|
os.chmod(VSPEC_RUNNER, 0o777)
|
||||||
|
|
||||||
|
|
||||||
|
def get_vspec_tests():
|
||||||
|
for f in os.listdir(TEST_DIR):
|
||||||
|
yield os.path.relpath(os.path.join(TEST_DIR, f))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('path', get_vspec_tests())
|
||||||
|
def test_integration(install_vspec, path):
|
||||||
|
output = subprocess.check_output(
|
||||||
|
[VSPEC_RUNNER, '.', VSPEC_FOLDER, os.path.relpath(path, root)],
|
||||||
|
cwd=root,
|
||||||
|
)
|
||||||
|
had_ok = False
|
||||||
|
for line in output.splitlines():
|
||||||
|
if (line.startswith(b'not ok') or
|
||||||
|
line.startswith(b'Error') or
|
||||||
|
line.startswith(b'Bail out!')):
|
||||||
|
pytest.fail("{0} failed:\n{1}".format(
|
||||||
|
path, output.decode('utf-8')), pytrace=False)
|
||||||
|
if not had_ok and line.startswith(b'ok'):
|
||||||
|
had_ok = True
|
||||||
|
if not had_ok:
|
||||||
|
pytest.fail("{0} failed: no 'ok' found:\n{1}".format(
|
||||||
|
path, output.decode('utf-8')), pytrace=False)
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
def test_integration(case, monkeypatch, pytestconfig):
|
|
||||||
case.run()
|
|
||||||
Reference in New Issue
Block a user