2014-04-24 14:07:31 +02:00
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
2019-12-04 13:51:45 +01:00
|
|
|
|
from glob import glob
|
2019-12-04 18:09:51 +01:00
|
|
|
|
from pathlib import Path
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
2014-04-24 15:17:23 +02:00
|
|
|
|
import pytest
|
|
|
|
|
|
2014-04-28 11:29:41 +02:00
|
|
|
|
from utils import TESTS_ROOT
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
|
|
|
|
|
2019-12-04 13:51:45 +01:00
|
|
|
|
SOURCE_DIRECTORIES = [
|
|
|
|
|
'extras',
|
|
|
|
|
'httpie',
|
|
|
|
|
'tests',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2014-04-24 14:07:31 +02:00
|
|
|
|
def has_docutils():
|
|
|
|
|
try:
|
2019-08-30 11:32:14 +02:00
|
|
|
|
# noinspection PyUnresolvedReferences,PyPackageRequirements
|
2014-04-24 14:07:31 +02:00
|
|
|
|
import docutils
|
|
|
|
|
return True
|
|
|
|
|
except ImportError:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
2014-04-25 10:41:04 +02:00
|
|
|
|
def rst_filenames():
|
2019-12-04 13:51:45 +01:00
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
os.chdir(TESTS_ROOT.parent)
|
|
|
|
|
try:
|
|
|
|
|
yield from glob('*.rst')
|
|
|
|
|
for directory in SOURCE_DIRECTORIES:
|
|
|
|
|
yield from glob(f'{directory}/**/*.rst', recursive=True)
|
|
|
|
|
finally:
|
|
|
|
|
os.chdir(cwd)
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
|
|
|
|
|
2019-12-04 13:51:45 +01:00
|
|
|
|
filenames = list(sorted(rst_filenames()))
|
2014-04-25 10:41:04 +02:00
|
|
|
|
assert filenames
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
2014-04-25 10:41:04 +02:00
|
|
|
|
|
2019-12-04 18:09:51 +01:00
|
|
|
|
# HACK: hardcoded paths, venv should be irrelevant, etc.
|
2020-06-25 11:36:09 +02:00
|
|
|
|
# TODO: simplify by using the Python API instead of a subprocess
|
|
|
|
|
# then we wont’t need the paths.
|
2019-12-04 18:09:51 +01:00
|
|
|
|
VENV_BIN = Path(__file__).parent.parent / 'venv/bin'
|
|
|
|
|
VENV_PYTHON = VENV_BIN / 'python'
|
|
|
|
|
VENV_RST2PSEUDOXML = VENV_BIN / 'rst2pseudoxml.py'
|
|
|
|
|
|
|
|
|
|
|
2020-06-25 11:36:09 +02:00
|
|
|
|
@pytest.mark.skipif(
|
|
|
|
|
not VENV_RST2PSEUDOXML.exists(),
|
|
|
|
|
reason='docutils not installed',
|
|
|
|
|
)
|
2014-04-25 10:41:04 +02:00
|
|
|
|
@pytest.mark.parametrize('filename', filenames)
|
2014-04-25 11:39:59 +02:00
|
|
|
|
def test_rst_file_syntax(filename):
|
2014-04-25 10:41:04 +02:00
|
|
|
|
p = subprocess.Popen(
|
2019-12-04 18:09:51 +01:00
|
|
|
|
[
|
|
|
|
|
VENV_PYTHON,
|
|
|
|
|
VENV_RST2PSEUDOXML,
|
|
|
|
|
'--report=1',
|
|
|
|
|
'--exit-status=1',
|
|
|
|
|
filename,
|
|
|
|
|
],
|
2015-10-22 19:32:16 +02:00
|
|
|
|
stderr=subprocess.PIPE,
|
2019-12-04 13:33:13 +01:00
|
|
|
|
stdout=subprocess.PIPE,
|
2019-12-04 13:51:45 +01:00
|
|
|
|
shell=True,
|
2014-04-25 10:41:04 +02:00
|
|
|
|
)
|
|
|
|
|
err = p.communicate()[1]
|
2016-03-03 10:22:12 +01:00
|
|
|
|
assert p.returncode == 0, err.decode('utf8')
|