From 5aa9ed795ea85eba4f28d53279f0b92365f6a2fe Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Wed, 4 Dec 2019 13:51:45 +0100 Subject: [PATCH] Switch to explicitly listed directories to search in for `*.rst` #820 --- tests/test_docs.py | 27 +++++++++++++++++++-------- tests/utils.py | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/test_docs.py b/tests/test_docs.py index 304d8ef9..f850c588 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -1,12 +1,19 @@ import os -import fnmatch import subprocess +from glob import glob import pytest from utils import TESTS_ROOT +SOURCE_DIRECTORIES = [ + 'extras', + 'httpie', + 'tests', +] + + def has_docutils(): try: # noinspection PyUnresolvedReferences,PyPackageRequirements @@ -17,25 +24,29 @@ def has_docutils(): def rst_filenames(): - # noinspection PyShadowingNames - for root, dirnames, filenames in os.walk(os.path.dirname(TESTS_ROOT)): - if '.tox' not in root and 'site-packages' not in root: - for filename in fnmatch.filter(filenames, '*.rst'): - yield os.path.join(root, filename) + 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(rst_filenames()) +filenames = list(sorted(rst_filenames())) assert filenames @pytest.mark.skipif(not has_docutils(), reason='docutils not installed') @pytest.mark.parametrize('filename', filenames) def test_rst_file_syntax(filename): + print(filename) p = subprocess.Popen( ['rst2pseudoxml.py', '--report=1', '--exit-status=1', filename], stderr=subprocess.PIPE, stdout=subprocess.PIPE, - shell=True + shell=True, ) err = p.communicate()[1] assert p.returncode == 0, err.decode('utf8') diff --git a/tests/utils.py b/tests/utils.py index 9c2f2a04..690765af 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -14,7 +14,7 @@ from httpie.context import Environment from httpie.core import main -TESTS_ROOT = os.path.abspath(os.path.dirname(__file__)) +TESTS_ROOT = Path(__file__).parent CRLF = '\r\n' COLOR = '\x1b[' HTTP_OK = '200 OK'