From dc32ed501d1d4db9c2697ac341876ac4a06d3b6a Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Tue, 6 Feb 2024 07:45:37 -0600 Subject: [PATCH] ruff format (after adding flake8-commas) --- src/doctest_docutils.py | 15 +++++++++++---- src/linkify_issues.py | 7 +++++-- src/pytest_doctest_docutils.py | 22 ++++++++++++++++------ tests/test_doctest_docutils.py | 9 +++++++-- tests/test_linkify_issues.py | 4 +++- tests/test_pytest_doctest_docutils.py | 4 +++- 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/doctest_docutils.py b/src/doctest_docutils.py index 9ef82bf..9a39ee2 100644 --- a/src/doctest_docutils.py +++ b/src/doctest_docutils.py @@ -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"] @@ -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) @@ -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. @@ -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. diff --git a/src/linkify_issues.py b/src/linkify_issues.py index 4cc976e..49c6b77 100644 --- a/src/linkify_issues.py +++ b/src/linkify_issues.py @@ -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 @@ -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( diff --git a/src/pytest_doctest_docutils.py b/src/pytest_doctest_docutils.py index 47e5405..a98e97d 100644 --- a/src/pytest_doctest_docutils.py +++ b/src/pytest_doctest_docutils.py @@ -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 @@ -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): @@ -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 @@ -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): @@ -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() @@ -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 diff --git a/tests/test_doctest_docutils.py b/tests/test_doctest_docutils.py index 02ecb4b..8e66b17 100644 --- a/tests/test_doctest_docutils.py +++ b/tests/test_doctest_docutils.py @@ -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( @@ -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) diff --git a/tests/test_linkify_issues.py b/tests/test_linkify_issues.py index ce7c707..41b9a23 100644 --- a/tests/test_linkify_issues.py +++ b/tests/test_linkify_issues.py @@ -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], diff --git a/tests/test_pytest_doctest_docutils.py b/tests/test_pytest_doctest_docutils.py index 7f96cbf..71fa05b 100644 --- a/tests/test_pytest_doctest_docutils.py +++ b/tests/test_pytest_doctest_docutils.py @@ -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,