2017-02-20 07:10:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
from os.path import abspath, dirname, join
|
|
|
|
|
|
|
|
SKIP_EXAMPLES = ['Example 4']
|
|
|
|
|
|
|
|
|
2017-04-29 06:36:37 +00:00
|
|
|
@pytest.mark.xfail
|
2017-02-20 07:10:45 +00:00
|
|
|
@pytest.mark.skipif(os.name == 'nt', reason='No make.bat specified for Windows')
|
2017-04-30 01:19:59 +00:00
|
|
|
def _test_build_documentation():
|
2017-02-20 07:10:45 +00:00
|
|
|
docroot = join(dirname(dirname(abspath(__file__))), 'docs')
|
2017-04-23 05:18:53 +00:00
|
|
|
cmd = shlex.split('sphinx-build -aE . _build')
|
2017-02-28 04:43:31 +00:00
|
|
|
proc = subprocess.Popen(cmd, cwd=docroot, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2017-02-20 07:10:45 +00:00
|
|
|
status = proc.wait()
|
|
|
|
assert status == 0
|
2017-04-23 05:18:53 +00:00
|
|
|
issues = []
|
2017-02-28 04:43:31 +00:00
|
|
|
for output in proc.communicate():
|
|
|
|
for line in str(output).split('\\n'):
|
|
|
|
line = line.lower().strip()
|
2017-04-23 05:18:53 +00:00
|
|
|
if 'warning' in line or 'error' in line or 'traceback' in line:
|
|
|
|
issues.append(line)
|
|
|
|
for line in issues:
|
|
|
|
print(line)
|
|
|
|
assert not issues
|
2017-02-20 07:10:45 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_readme_examples(plex):
|
2017-02-20 07:10:45 +00:00
|
|
|
failed = 0
|
2017-04-15 00:47:59 +00:00
|
|
|
examples = _fetch_examples()
|
2017-02-20 19:50:02 +00:00
|
|
|
assert len(examples), 'No examples found in README'
|
2017-02-20 07:10:45 +00:00
|
|
|
for title, example in examples:
|
|
|
|
if _check_run_example(title):
|
|
|
|
try:
|
|
|
|
print('\n%s\n%s' % (title, '-' * len(title)))
|
|
|
|
exec('\n'.join(example))
|
|
|
|
except Exception as err:
|
|
|
|
failed += 1
|
|
|
|
print('Error running test: %s\nError: %s' % (title, err))
|
|
|
|
assert not failed, '%s examples raised an exception.' % failed
|
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def _fetch_examples():
|
2017-02-20 07:10:45 +00:00
|
|
|
parsing = False
|
|
|
|
examples = []
|
2017-02-20 19:50:02 +00:00
|
|
|
filepath = join(dirname(dirname(abspath(__file__))), 'README.rst')
|
2017-02-20 07:10:45 +00:00
|
|
|
with open(filepath, 'r') as handle:
|
|
|
|
for line in handle.read().split('\n'):
|
2017-02-20 19:50:02 +00:00
|
|
|
line = line[4:]
|
2017-02-20 07:10:45 +00:00
|
|
|
if line.startswith('# Example '):
|
|
|
|
parsing = True
|
|
|
|
title = line.lstrip('# ')
|
2017-04-15 00:47:59 +00:00
|
|
|
examples.append([title, []])
|
2017-02-20 19:50:02 +00:00
|
|
|
elif parsing and line == '':
|
2017-02-20 07:10:45 +00:00
|
|
|
parsing = False
|
|
|
|
elif parsing:
|
|
|
|
examples[-1][1].append(line)
|
|
|
|
return examples
|
|
|
|
|
|
|
|
|
|
|
|
def _check_run_example(title):
|
|
|
|
for skip_example in SKIP_EXAMPLES:
|
|
|
|
if skip_example in title:
|
|
|
|
return False
|
|
|
|
return True
|