1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-24 08:22:22 +02:00
httpie-cli/tests/test_docs.py
Mickaël Schoentgen c6cbc7dfa5
Uniformize UTF-8 naming (#1115)
* Uniformize UTF-8 naming

Replace `utf8` -> `utf-8` everywhere.
It should have no impact, `utf8` is an alias of `utf-8` [1].

[1] ee03bad25e/Lib/encodings/aliases.py (L534)

* Always specify the encoding

Let's be explicit over implicit. And prevent future warnings from PEP-597 [1].

[1] https://www.python.org/dev/peps/pep-0597/#using-the-default-encoding-is-a-common-mistake

* Update `UTF8` constant (`utf-8` -> `utf_8`)

* Remove default argument from `str.encode()` and `bytes.decode()`

* Clean-up
2021-08-05 20:58:43 +02:00

70 lines
1.5 KiB
Python

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 # noqa
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 = 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 wont’t 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()