Skip to content

Commit

Permalink
chore(ruff): Fix linting issues
Browse files Browse the repository at this point in the history
src/doctest_docutils.py:137:31: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
src/doctest_docutils.py:141:31: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
src/doctest_docutils.py:145:31: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
src/doctest_docutils.py:398:15: TRY003 Avoid specifying long messages outside the exception class
src/doctest_docutils.py:408:16: PTH119 `os.path.basename()` should be replaced by `Path.name`
tests/test_doctest_docutils.py:206:15: TRY003 Avoid specifying long messages outside the exception class
  • Loading branch information
tony committed Jul 4, 2023
1 parent 66ca1e1 commit 0633efd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/doctest_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ def run(self) -> t.List[Node]:


class TestsetupDirective(TestDirective):
option_spec: OptionSpec = {"skipif": directives.unchanged_required}
option_spec: t.ClassVar[OptionSpec] = {"skipif": directives.unchanged_required}


class TestcleanupDirective(TestDirective):
option_spec: OptionSpec = {"skipif": directives.unchanged_required}
option_spec: t.ClassVar[OptionSpec] = {"skipif": directives.unchanged_required}


class DoctestDirective(TestDirective):
option_spec: OptionSpec = {
option_spec: t.ClassVar[OptionSpec] = {
"hide": directives.flag,
"no-trim-doctest-flags": directives.flag,
"options": directives.unchanged,
Expand Down Expand Up @@ -374,6 +374,13 @@ def _get_test(
return self._parser.get_doctest(string, globs, name, filename, lineno)


class TestDocutilsPackageRelativeError(Exception):
def __init__(self):
return super().__init__(
"Package may only be specified for module-relative paths."
)


def testdocutils(
filename: str,
module_relative: bool = True,
Expand All @@ -395,7 +402,7 @@ def testdocutils(
global master

if package and not module_relative:
raise ValueError("Package may only be specified for module-" "relative paths.")
raise TestDocutilsPackageRelativeError()

# Keep the absolute file paths. This is needed for Include directies to work.
# The absolute path will be applied to source_path when creating the docutils doc.
Expand All @@ -405,7 +412,7 @@ def testdocutils(

# If no name was given, then use the file's name.
if name is None:
name = os.path.basename(filename)
name = pathlib.Path(filename).stem

# Assemble the globals.
globs = {} if globs is None else globs.copy()
Expand Down
7 changes: 6 additions & 1 deletion tests/test_doctest_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ class DocTestFinderFixture(t.NamedTuple):
]


class FilePathModeNotImplemented(Exception):
def __init__(self, file_path_mode: str) -> None:
return super().__init__(f"No file_path_mode supported for {file_path_mode}")


@pytest.mark.parametrize(
DocTestFinderFixture._fields, FIXTURES, ids=[f.test_id for f in FIXTURES]
)
Expand All @@ -203,7 +208,7 @@ def test_DocutilsDocTestFinder(
if file_path_mode == "absolute":
first_test_filename = str(tests_path / first_test_filename)
elif file_path_mode != "relative":
raise NotImplementedError(f"No file_path_mode supported for {file_path_mode}")
raise FilePathModeNotImplemented(file_path_mode)

tests_path.mkdir()
for file_name, text in files.items():
Expand Down

0 comments on commit 0633efd

Please sign in to comment.