Skip to content

Commit

Permalink
ruff format (after adding flake8-commas)
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Feb 6, 2024
1 parent 06d6770 commit dc32ed5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 16 deletions.
15 changes: 11 additions & 4 deletions src/doctest_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def run(self) -> t.List[Node]:
node["options"][flag] = True # Skip the test
except InvalidSpecifier:
self.state.document.reporter.warning(
"'%s' is not a valid pyversion option" % spec, line=self.lineno,
"'%s' is not a valid pyversion option" % spec,
line=self.lineno,
)
if "skipif" in self.options:
node["skipif"] = self.options["skipif"]
Expand Down Expand Up @@ -328,7 +329,8 @@ def _find(
settings = OptionParser(components=(Parser,)).get_default_values()

doc = docutils.utils.new_document(
source_path=str(source_path), settings=settings,
source_path=str(source_path),
settings=settings,
)
parser.parse(string, doc)

Expand Down Expand Up @@ -371,7 +373,9 @@ def condition(node: Node) -> bool:
if sys.version_info < (3, 13):

def _from_module(
self, module: t.Optional[t.Union[str, types.ModuleType]], object: object,
self,
module: t.Optional[t.Union[str, types.ModuleType]],
object: object,
) -> bool:
"""Return true if the given object lives in the given module.
Expand Down Expand Up @@ -442,7 +446,10 @@ def testdocutils(
# 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.
text, _ = doctest._load_testfile( # type: ignore
filename, package, module_relative, encoding or "utf-8",
filename,
package,
module_relative,
encoding or "utf-8",
)

# If no name was given, then use the file's name.
Expand Down
7 changes: 5 additions & 2 deletions src/linkify_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def condition(node: nodes.Node) -> bool:
isinstance(node, nodes.Text)
and len(re.findall(issue_re, node.astext())) > 0
) and not isinstance(
node.parent, (nodes.literal, nodes.FixedTextElement, nodes.reference),
node.parent,
(nodes.literal, nodes.FixedTextElement, nodes.reference),
)
return cond

Expand Down Expand Up @@ -74,7 +75,9 @@ def setup(app: Sphinx) -> SetupDict:
app.add_transform(LinkifyIssues)
app.add_config_value("issue_re", re.compile(DEFAULT_ISSUE_RE), "env")
app.add_config_value(
"issue_url_tpl", r"https://github.com/git-pull/gp-libs/issues/{issue_id}", "env",
"issue_url_tpl",
r"https://github.com/git-pull/gp-libs/issues/{issue_id}",
"env",
)

return SetupDict(
Expand Down
22 changes: 16 additions & 6 deletions src/pytest_doctest_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def pytest_unconfigure() -> None:


def pytest_collect_file(
file_path: pathlib.Path, parent: pytest.Collector,
file_path: pathlib.Path,
parent: pytest.Collector,
) -> t.Optional[t.Union["DocTestDocutilsFile", "_pytest.doctest.DoctestModule"]]:
"""Test collector for pytest-doctest-docutils."""
config = parent.config
Expand All @@ -85,7 +86,8 @@ def pytest_collect_file(
),
):
mod: t.Union[
DocTestDocutilsFile, _pytest.doctest.DoctestModule,
DocTestDocutilsFile,
_pytest.doctest.DoctestModule,
] = _pytest.doctest.DoctestModule.from_parent(parent, path=file_path)
return mod
elif _is_doctest(config, file_path, parent):
Expand All @@ -94,7 +96,9 @@ def pytest_collect_file(


def _is_doctest(
config: pytest.Config, path: pathlib.Path, parent: pytest.Collector,
config: pytest.Config,
path: pathlib.Path,
parent: pytest.Collector,
) -> bool:
if path.suffix in (".rst", ".md") and parent.session.isinitpath(path):
return True
Expand Down Expand Up @@ -142,7 +146,9 @@ def report_unexpected_exception(
test: "doctest.DocTest",
example: "doctest.Example",
exc_info: t.Tuple[
t.Type[BaseException], BaseException, types.TracebackType,
t.Type[BaseException],
BaseException,
types.TracebackType,
],
) -> None:
if isinstance(exc_info[1], OutcomeException):
Expand Down Expand Up @@ -247,7 +253,9 @@ class DocutilsDocTestRunner(doctest.DocTestRunner):
"""DocTestRunner for doctest_docutils."""

def summarize( # type: ignore
self, out: "_Out", verbose: t.Optional[bool] = None,
self,
out: "_Out",
verbose: t.Optional[bool] = None,
) -> t.Tuple[int, int]:
"""Summarize the test runs."""
string_io = io.StringIO()
Expand All @@ -261,7 +269,9 @@ def summarize( # type: ignore
return res

def _DocTestRunner__patched_linecache_getlines(
self, filename: str, module_globals: t.Any = None,
self,
filename: str,
module_globals: t.Any = None,
) -> t.Any:
# this is overridden from DocTestRunner adding the try-except below
m = self._DocTestRunner__LINECACHE_FILENAME_RE.match(filename) # type: ignore
Expand Down
9 changes: 7 additions & 2 deletions tests/test_doctest_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ def __init__(self, file_path_mode: str) -> None:


@pytest.mark.parametrize(
DocTestFinderFixture._fields, FIXTURES, ids=[f.test_id for f in FIXTURES],
DocTestFinderFixture._fields,
FIXTURES,
ids=[f.test_id for f in FIXTURES],
)
@pytest.mark.parametrize("file_path_mode", ["relative", "absolute"])
def test_DocutilsDocTestFinder(
Expand Down Expand Up @@ -230,7 +232,10 @@ def test_DocutilsDocTestFinder(
# Test
finder = doctest_docutils.DocutilsDocTestFinder()
text, _ = doctest._load_testfile( # type: ignore
str(first_test_filename), package=None, module_relative=False, encoding="utf-8",
str(first_test_filename),
package=None,
module_relative=False,
encoding="utf-8",
)
tests = finder.find(text, str(first_test_filename))
tests.sort(key=lambda test: test.name)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_linkify_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class LinkTestFixture(t.NamedTuple):


@pytest.mark.parametrize(
LinkTestFixture._fields, FIXTURES, ids=[f.test_id for f in FIXTURES],
LinkTestFixture._fields,
FIXTURES,
ids=[f.test_id for f in FIXTURES],
)
def test_links_show(
make_app: t.Callable[[t.Any], SphinxTestApp],
Expand Down
4 changes: 3 additions & 1 deletion tests/test_pytest_doctest_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ def hello(statement: str) -> None:


@pytest.mark.parametrize(
PytestDocTestFinderFixture._fields, FIXTURES, ids=[f.test_id for f in FIXTURES],
PytestDocTestFinderFixture._fields,
FIXTURES,
ids=[f.test_id for f in FIXTURES],
)
def test_pluginDocutilsDocTestFinder(
pytester: _pytest.pytester.Pytester,
Expand Down

0 comments on commit dc32ed5

Please sign in to comment.