diff --git a/AUTHORS b/AUTHORS index 34e6452..c514925 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,6 +5,7 @@ Berenice Larsen Pereyra David Litvak Bruno Diego Duncan Diego Mascialino +Eduardo Enriquez Facundo Batista FaQ Filipe Ximenes diff --git a/tests/__init__.py b/tests/__init__.py index 6c311de..332d5dc 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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 diff --git a/tests/test_infra.py b/tests/test_infra.py index d1bfa20..1e62833 100644 --- a/tests/test_infra.py +++ b/tests/test_infra.py @@ -18,11 +18,6 @@ import io import logging -import os -import unittest - -from unittest.mock import patch - import docutils.core import pep257 import rst2html5_ @@ -30,6 +25,8 @@ 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'] @@ -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