Skip to content

Commit

Permalink
test(style): remove pydocstyle tests on charmcraft code (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Oct 16, 2023
1 parent 4a57370 commit e7c55c8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 46 deletions.
41 changes: 40 additions & 1 deletion tests/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,59 @@
# For further info, check https://github.com/canonical/charmcraft

import datetime
import io
import os
import re
import subprocess
import sys
from argparse import Namespace
from unittest.mock import patch

import pydocstyle
import pytest
from craft_cli import CraftError
from flake8.api.legacy import get_style_guide

from charmcraft.commands.init import DEFAULT_PROFILE, PROFILES, InitCommand
from charmcraft.models.charmcraft import Project
from charmcraft.utils import S_IXALL
from tests.test_infra import get_python_filepaths, pep8_test, pep257_test
from tests.test_infra import get_python_filepaths


def pep8_test(python_filepaths):
"""Helper to check PEP8 (used from this module and from test_init.py to check templates)."""
style_guide = get_style_guide()
fake_stdout = io.TextIOWrapper(io.BytesIO())
with patch("sys.stdout", fake_stdout):
report = style_guide.check_files(python_filepaths)

# if flake8 didn't report anything, we're done
if report.total_errors == 0:
return

# grab on which files we have issues
fake_stdout.seek(0)
flake8_issues = fake_stdout.read().split("\n")

if flake8_issues:
msg = "Please fix the following flake8 issues!\n" + "\n".join(flake8_issues)
pytest.fail(msg, pytrace=False)


def pep257_test(python_filepaths):
"""Helper to check PEP257 (used from this module and from test_init.py to check templates)."""
to_ignore = {
"D105", # Missing docstring in magic method
"D107", # Missing docstring in __init__
}
to_include = pydocstyle.violations.conventions.pep257 - to_ignore
errors = list(pydocstyle.check(python_filepaths, select=to_include))

if errors:
report = ["Please fix files as suggested by pydocstyle ({:d} issues):".format(len(errors))]
report.extend(str(e) for e in errors)
msg = "\n".join(report)
pytest.fail(msg, pytrace=False)


@pytest.fixture()
Expand Down
45 changes: 0 additions & 45 deletions tests/test_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@
#
# For further info, check https://github.com/canonical/charmcraft

import io
import itertools
import os
import re
import subprocess
import sys
from unittest.mock import patch

import black
import click.testing
import pydocstyle
import pytest
from flake8.api.legacy import get_style_guide

from charmcraft import __version__, main

Expand All @@ -45,47 +41,6 @@ def get_python_filepaths(*, roots=None, python_paths=None):
return python_paths


def pep8_test(python_filepaths):
"""Helper to check PEP8 (used from this module and from test_init.py to check templates)."""
style_guide = get_style_guide()
fake_stdout = io.TextIOWrapper(io.BytesIO())
with patch("sys.stdout", fake_stdout):
report = style_guide.check_files(python_filepaths)

# if flake8 didn't report anything, we're done
if report.total_errors == 0:
return

# grab on which files we have issues
fake_stdout.seek(0)
flake8_issues = fake_stdout.read().split("\n")

if flake8_issues:
msg = "Please fix the following flake8 issues!\n" + "\n".join(flake8_issues)
pytest.fail(msg, pytrace=False)


def test_pep257():
"""Verify all files have nice docstrings."""
pep257_test(get_python_filepaths(roots=["charmcraft"]))


def pep257_test(python_filepaths):
"""Helper to check PEP257 (used from this module and from test_init.py to check templates)."""
to_ignore = {
"D105", # Missing docstring in magic method
"D107", # Missing docstring in __init__
}
to_include = pydocstyle.violations.conventions.pep257 - to_ignore
errors = list(pydocstyle.check(python_filepaths, select=to_include))

if errors:
report = ["Please fix files as suggested by pydocstyle ({:d} issues):".format(len(errors))]
report.extend(str(e) for e in errors)
msg = "\n".join(report)
pytest.fail(msg, pytrace=False)


def test_ensure_copyright():
"""Check that all non-empty Python files have copyright somewhere in the first 5 lines."""
issues = []
Expand Down

0 comments on commit e7c55c8

Please sign in to comment.