Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test infra #369

Merged
merged 8 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Berenice Larsen Pereyra <[email protected]>
David Litvak Bruno <[email protected]>
Diego Duncan <[email protected]>
Diego Mascialino <[email protected]>
Eduardo Enriquez <[email protected]>
Facundo Batista <[email protected]>
FaQ <[email protected]>
Filipe Ximenes <[email protected]>
Expand Down
11 changes: 11 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ def create_tempfile(testcase, lines):
f.write(line + '\n')

return tempfile


def get_python_filepaths(roots):
"""Helper to retrieve paths of Python files."""
python_paths = []
for root in roots:
for dirpath, dirnames, filenames in os.walk(root):
for filename in filenames:
if filename.endswith(".py"):
python_paths.append(os.path.join(dirpath, filename))
return python_paths
68 changes: 28 additions & 40 deletions tests/test_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@

import io
import logging
import os
import unittest

from unittest.mock import patch

import docutils.core
import pep257
import rst2html5_

from flake8.api.legacy import get_style_guide
from pyuca import Collator

from tests import get_python_filepaths

FLAKE8_ROOTS = ['fades', 'tests']
FLAKE8_OPTIONS = ['--max-line-length=99', '--select=E,W,F,C,N']
PEP257_ROOTS = ['fades']
Expand All @@ -40,44 +37,35 @@
logging.getLogger(logger_name).setLevel(logging.CRITICAL)


class InfrastructureTestCase(unittest.TestCase):
def test_flake8_pytest(mocker):
python_filepaths = get_python_filepaths(FLAKE8_ROOTS)
style_guide = get_style_guide(paths=FLAKE8_OPTIONS)
fake_stdout = io.StringIO()
mocker.patch('sys.stdout', fake_stdout)
report = style_guide.check_files(python_filepaths)
assert report.total_errors == 0, "There are issues!\n" + fake_stdout.getvalue()


def _get_python_filepaths(self, roots):
"""Helper to retrieve paths of Python files."""
python_paths = []
for root in roots:
for dirpath, dirnames, filenames in os.walk(root):
for filename in filenames:
if filename.endswith(".py"):
python_paths.append(os.path.join(dirpath, filename))
return python_paths
def test_pep257_pytest():
python_filepaths = get_python_filepaths(PEP257_ROOTS)
result = list(pep257.check(python_filepaths))
assert len(result) == 0, "There are issues!\n" + '\n'.join(map(str, result))

def test_flake8(self):
python_filepaths = self._get_python_filepaths(FLAKE8_ROOTS)
style_guide = get_style_guide(paths=FLAKE8_OPTIONS)
fake_stdout = io.StringIO()
with patch('sys.stdout', fake_stdout):
report = style_guide.check_files(python_filepaths)
self.assertEqual(report.total_errors, 0, "There are issues!\n" + fake_stdout.getvalue())

def test_pep257(self):
python_filepaths = self._get_python_filepaths(PEP257_ROOTS)
result = list(pep257.check(python_filepaths))
self.assertEqual(len(result), 0, "There are issues!\n" + '\n'.join(map(str, result)))
def test_readme_sanity(mocker):
fake_stdout = io.StringIO() # just to ignore the output
fake_stderr = io.StringIO() # will have content if there are problems
with open('README.rst', 'rt', encoding='utf8') as fh:
mocker.patch('sys.stdout', fake_stdout)
mocker.patch('sys.stderr', fake_stderr)
docutils.core.publish_file(source=fh, writer=rst2html5_.HTML5Writer())

def test_readme_sanity(self):
fake_stdout = io.StringIO() # just to ignore the output
fake_stderr = io.StringIO() # will have content if there are problems
with open('README.rst', 'rt', encoding='utf8') as fh:
with patch('sys.stdout', fake_stdout):
with patch('sys.stderr', fake_stderr):
docutils.core.publish_file(source=fh, writer=rst2html5_.HTML5Writer())
errors = fake_stderr.getvalue()
assert not bool(errors), "There are issues!\n" + errors

errors = fake_stderr.getvalue()
self.assertFalse(bool(errors), "There are issues!\n" + errors)

def test_authors_ordering(self):
with open('AUTHORS', 'rt', encoding='utf8') as fh:
authors = fh.readlines()
ordered_authors = sorted(authors, key=Collator().sort_key)
self.assertEqual(authors, ordered_authors)
def test_authors_ordering():
with open('AUTHORS', 'rt', encoding='utf8') as fh:
authors = fh.readlines()
ordered_authors = sorted(authors, key=Collator().sort_key)
assert authors == ordered_authors