Skip to content

Commit

Permalink
tests: move/rename/cleanup vspec based tests
Browse files Browse the repository at this point in the history
The main motivation is to being able to use normal/other pytest based
tests.

Therefore this moves everything from conftest into test_integration
itself.
  • Loading branch information
blueyed committed Jul 30, 2018
1 parent b33392c commit f36e5ef
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 82 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test:
pytest test_*.py
pytest

test_nvim:
VSPEC_VIM=nvim pytest test_*.py
VSPEC_VIM=nvim pytest

build:
mkdir $@
Expand Down
75 changes: 0 additions & 75 deletions conftest.py

This file was deleted.

3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[tool:pytest]
testpaths = test

[flake8]
max-line-length = 100
62 changes: 62 additions & 0 deletions test/test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Runs tests from ./vspec in vim-vspec."""
import os
import subprocess
import urllib.request
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 = urllib.request.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)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions test_integration.py

This file was deleted.

0 comments on commit f36e5ef

Please sign in to comment.