httpie-cli/tests/test_docs.py
Mickaël Schoentgen a3a08a9a22
Use relative imports (#1057)
* Use relative imports in test

* Use relative imports

* Add myself to contributors :)
2021-05-05 14:13:39 +02:00

70 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import subprocess
from glob import glob
from pathlib import Path
import pytest
from .utils import TESTS_ROOT
SOURCE_DIRECTORIES = [
'extras',
'httpie',
'tests',
]
def has_docutils():
try:
# noinspection PyUnresolvedReferences,PyPackageRequirements
import docutils
return True
except ImportError:
return False
def rst_filenames():
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)
filenames = list(sorted(rst_filenames()))
assert filenames
# HACK: hardcoded paths, venv should be irrelevant, etc.
# TODO: simplify by using the Python API instead of a subprocess
# then we wontt need the paths.
VENV_BIN = Path(__file__).parent.parent / 'venv/bin'
VENV_PYTHON = VENV_BIN / 'python'
VENV_RST2PSEUDOXML = VENV_BIN / 'rst2pseudoxml.py'
@pytest.mark.skipif(
not VENV_RST2PSEUDOXML.exists(),
reason='docutils not installed',
)
@pytest.mark.parametrize('filename', filenames)
def test_rst_file_syntax(filename):
p = subprocess.Popen(
[
VENV_PYTHON,
VENV_RST2PSEUDOXML,
'--report=1',
'--exit-status=1',
filename,
],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
shell=True,
)
err = p.communicate()[1]
assert p.returncode == 0, err.decode('utf8')