Lee-W commented on code in PR #71477:
URL: https://github.com/apache/airflow/pull/71477#discussion_r4130161659
##########
dev/registry/tests/test_extract_versions.py:
##########
@@ -210,3 +213,187 @@ def test_external_services_propagates_to_version_metadata(
assert result is not None
assert result["connection_types"][0]["external_services"] ==
["openai", "anthropic"]
+
+
+class TestExtractModulesGuideUrls:
+ """A class the provider's guides document in a section of its own must get
a
+ ``guide_url`` for every version, not just the latest. A superseded
version's
+ page is rendered only from the per-version file this module writes, so a
link
+ resolved on the latest path alone disappears the moment a new version
lands.
+ """
+
+ PROVIDER_YAML = {
+ "toolsets": [
+ {
+ "integration-name": "Test",
+ "python-modules": ["airflow.providers.test.toolsets.hook"],
+ }
+ ]
+ }
+ SOURCE = 'class HookToolset:\n """A toolset."""\n'
+ GUIDE = "``HookToolset``\n---------------\n\nProse.\n"
+
+ def _extract(self, layout="new",
docs_paths=("providers/test/docs/toolsets.rst",)):
+ def fake_git_show(_tag, path):
+ return self.SOURCE if path.endswith(".py") else None
+
+ def fake_git_cat_file_batch(_tag, paths):
+ return {p: self.GUIDE for p in paths}
+
+ with (
+ patch("extract_versions.git_ls_tree", autospec=True,
return_value=list(docs_paths)),
+ patch("extract_versions.git_show", autospec=True,
side_effect=fake_git_show),
+ patch("extract_versions.git_cat_file_batch", autospec=True,
side_effect=fake_git_cat_file_batch),
+ ):
+ return extract_modules_from_yaml(
+ self.PROVIDER_YAML, "providers-test/1.0.0", layout, "test",
"test", "1.0.0"
+ )
+
+ def test_documented_class_gets_a_versioned_guide_url(self):
+ modules = self._extract()
+
+ assert [m["name"] for m in modules] == ["HookToolset"]
+ assert modules[0]["guide_url"] == (
+
"https://airflow.apache.org/docs/apache-airflow-providers-test/1.0.0/toolsets.html#hooktoolset"
+ )
+
+ def test_undocumented_class_gets_no_guide_url(self):
+ modules = self._extract(docs_paths=())
+
+ assert [m["name"] for m in modules] == ["HookToolset"]
+ assert "guide_url" not in modules[0]
+
+ def test_old_layout_gets_no_guide_url(self):
+ # Pre-per-provider tags kept docs in a top-level tree, so there is no
+ # provider-relative page path to build a link from.
+ modules = self._extract(layout="old")
+
+ assert "guide_url" not in modules[0]
+
+
+class TestReadGuideDocs:
+ def
test_skips_generated_and_release_note_pages_before_calling_git_show(self):
+ docs_prefix = "providers/test/docs/"
+ paths = [
+ docs_prefix + "_api/x/index.rst",
+ docs_prefix + "changelog.rst",
+ docs_prefix + "toolsets.rst",
+ ]
+
+ with (
+ patch("extract_versions.git_ls_tree", autospec=True,
return_value=paths),
+ patch(
+ "extract_versions.git_cat_file_batch",
+ autospec=True,
+ side_effect=lambda tag, paths: {p: "Prose.\n" for p in paths},
+ ) as mock_git_cat_file_batch,
+ ):
+ result = read_guide_docs("providers-test/1.0.0", "new", "test")
+
+ # Mutation canary: if the `is_guide_page` filter in read_guide_docs is
+ # removed, this dict grows two more keys and this assertion goes red.
+ assert set(result) == {"toolsets.rst"}
+ # Mutation canary: without the filter, the two skipped paths would also
+ # be included in the batch call's path list -- this assertion goes red
+ # too, proving the filtering runs before the batch call, not just
+ # before the dict write.
+ assert mock_git_cat_file_batch.call_args_list == [
+ call("providers-test/1.0.0", [docs_prefix + "toolsets.rst"])
+ ]
+
+ def test_skips_a_page_whose_content_is_an_empty_string(self):
+ # Mutation canary: replacing `batch_result.get(full_path)` with
+ # `full_path in batch_result` in read_guide_docs's comprehension makes
+ # this page reappear as `{"empty.rst": ""}`, turning this assertion
red.
+ docs_prefix = "providers/test/docs/"
+ paths = [docs_prefix + "empty.rst"]
+
+ with (
+ patch("extract_versions.git_ls_tree", autospec=True,
return_value=paths),
+ patch(
+ "extract_versions.git_cat_file_batch",
+ autospec=True,
+ return_value={docs_prefix + "empty.rst": ""},
+ ),
+ ):
+ result = read_guide_docs("providers-test/1.0.0", "new", "test")
+
+ assert result == {}
+
+
+class TestGitLsTree:
+ def test_passes_quote_path_false_to_git(self):
+ mock_result = MagicMock()
Review Comment:
Both classes patch with `autospec=True` and return
`MagicMock(spec=subprocess.CompletedProcess)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]