From 6a782e3cb90d8871d4b8474a8604dc3847645f02 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 29 Jul 2018 16:14:35 +0200 Subject: [PATCH] tests: move/rename/cleanup vspec based tests The main motivation is to being able to use normal/other pytest based tests. Therefore this moves everything from conftest into test_integration itself. --- Makefile | 4 +- pytest.ini | 3 -- setup.cfg | 3 ++ test/test_integration.py | 65 +++++++++++++++++++++++ test/{ => vspec}/completions.vim | 0 test/{ => vspec}/completions_disabled.vim | 0 test/{ => vspec}/documentation.vim | 0 test/{ => vspec}/goto.vim | 0 test/{ => vspec}/pyimport.vim | 0 test/{ => vspec}/signatures.vim | 0 test_integration.py | 2 - 11 files changed, 70 insertions(+), 7 deletions(-) delete mode 100644 pytest.ini create mode 100644 test/test_integration.py rename test/{ => vspec}/completions.vim (100%) rename test/{ => vspec}/completions_disabled.vim (100%) rename test/{ => vspec}/documentation.vim (100%) rename test/{ => vspec}/goto.vim (100%) rename test/{ => vspec}/pyimport.vim (100%) rename test/{ => vspec}/signatures.vim (100%) delete mode 100644 test_integration.py diff --git a/Makefile b/Makefile index 8c8fa4fb..4cdcbe7f 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ test: - pytest test_*.py + pytest 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: test_nvim diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 16700c3c..00000000 --- a/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -# Ignore all files -norecursedirs = * diff --git a/setup.cfg b/setup.cfg index 7da1f960..93e190e5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,5 @@ +[tool:pytest] +testpaths = test + [flake8] max-line-length = 100 diff --git a/test/test_integration.py b/test/test_integration.py new file mode 100644 index 00000000..ae39307d --- /dev/null +++ b/test/test_integration.py @@ -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) diff --git a/test/completions.vim b/test/vspec/completions.vim similarity index 100% rename from test/completions.vim rename to test/vspec/completions.vim diff --git a/test/completions_disabled.vim b/test/vspec/completions_disabled.vim similarity index 100% rename from test/completions_disabled.vim rename to test/vspec/completions_disabled.vim diff --git a/test/documentation.vim b/test/vspec/documentation.vim similarity index 100% rename from test/documentation.vim rename to test/vspec/documentation.vim diff --git a/test/goto.vim b/test/vspec/goto.vim similarity index 100% rename from test/goto.vim rename to test/vspec/goto.vim diff --git a/test/pyimport.vim b/test/vspec/pyimport.vim similarity index 100% rename from test/pyimport.vim rename to test/vspec/pyimport.vim diff --git a/test/signatures.vim b/test/vspec/signatures.vim similarity index 100% rename from test/signatures.vim rename to test/vspec/signatures.vim diff --git a/test_integration.py b/test_integration.py deleted file mode 100644 index d47e06be..00000000 --- a/test_integration.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_integration(case, monkeypatch, pytestconfig): - case.run()