Skip to content

Commit c9c4b27

Browse files
committed
fix tests and apply suggestions from code review
1 parent 9224885 commit c9c4b27

4 files changed

Lines changed: 74 additions & 17 deletions

File tree

packages/help/docfx_helper.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
15+
import argparse
1616
import pathlib
1717
import shutil
18-
import sys
1918
import yaml
2019
import pypandoc
2120

@@ -35,7 +34,7 @@ def build_docfx(current_dir, repo_root, docs_map):
3534
print("Pandoc not found. Downloading...")
3635
pypandoc.download_pandoc()
3736

38-
toc = []
37+
doc_items = []
3938

4039
for title, source in docs_map.items():
4140
source_path = pathlib.Path(source)
@@ -68,22 +67,33 @@ def build_docfx(current_dir, repo_root, docs_map):
6867
(output_dir / filename).write_text(f"# {title}\n\nContent missing.")
6968
href = filename
7069

71-
toc.append({"name": title, "href": href})
70+
doc_items.append({"name": title, "href": href})
71+
72+
# Create the structured TOC
73+
toc = [
74+
{
75+
"uid": "product-neutral-guides",
76+
"name": "Client library help",
77+
"items": doc_items
78+
}
79+
]
7280

7381
# Write toc.yaml
7482
toc_path = output_dir / "toc.yaml"
75-
with open(toc_path, "w") as f:
83+
with open(toc_path, "w", encoding="utf-8") as f:
84+
# Using block style for YAML as requested
7685
yaml.dump(toc, f, default_flow_style=False)
7786

7887
print(f"DocFX build complete in {output_dir}")
7988
print(f"Generated TOC: {toc}")
8089

8190
if __name__ == "__main__":
82-
# Simple argument parsing: current_dir, repo_root, then pairs of Title,Source
83-
curr = sys.argv[1]
84-
root = sys.argv[2]
85-
d_map = {}
86-
for i in range(3, len(sys.argv), 2):
87-
d_map[sys.argv[i]] = sys.argv[i+1]
91+
parser = argparse.ArgumentParser(description="Build DocFX documentation.")
92+
parser.add_argument("--current-dir", required=True, help="Current package directory")
93+
parser.add_argument("--repo-root", required=True, help="Repository root directory")
94+
parser.add_argument("--doc", action="append", nargs=2, metavar=("TITLE", "PATH"), help="Add a document title and its source path")
95+
96+
args = parser.parse_args()
8897

89-
build_docfx(curr, root, d_map)
98+
docs_map = {title: path for title, path in args.doc} if args.doc else {}
99+
build_docfx(args.current_dir, args.repo_root, docs_map)

packages/help/help/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

packages/help/noxfile.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from __future__ import absolute_import
18-
1917
import pathlib
2018
import nox
2119

2220
DEFAULT_PYTHON_VERSION = "3.14"
21+
ALL_PYTHON = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
2322
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
2423
REPO_ROOT = CURRENT_DIRECTORY.parent.parent
2524

@@ -31,12 +30,39 @@
3130

3231
nox.options.sessions = [
3332
"lint",
33+
"unit",
34+
"prerelease_deps",
35+
"core_deps_from_source",
3436
"docfx",
3537
]
3638

3739
# Error if a python version is missing
3840
nox.options.error_on_missing_interpreters = True
3941

42+
@nox.session(python=ALL_PYTHON)
43+
def unit(session):
44+
"""Run unit tests."""
45+
session.install("pytest", "pytest-cov")
46+
session.install("-e", ".")
47+
session.run("pytest", "tests")
48+
49+
@nox.session(python=DEFAULT_PYTHON_VERSION)
50+
def prerelease_deps(session):
51+
"""Run unit tests with prerelease dependencies."""
52+
# Since we have no dependencies, this is just a normal unit test run
53+
# but with --pre enabled for any test tools.
54+
session.install("pytest", "pytest-cov")
55+
session.install("-e", ".")
56+
session.run("pytest", "tests")
57+
58+
@nox.session(python=DEFAULT_PYTHON_VERSION)
59+
def core_deps_from_source(session):
60+
"""Run unit tests with core dependencies installed from source."""
61+
# We don't depend on core, so we just run unit tests.
62+
session.install("pytest", "pytest-cov")
63+
session.install("-e", ".")
64+
session.run("pytest", "tests")
65+
4066
@nox.session(python=DEFAULT_PYTHON_VERSION)
4167
def lint(session):
4268
"""Run linters."""
@@ -49,8 +75,11 @@ def docfx(session):
4975
session.install("PyYAML", "pypandoc")
5076

5177
# Construct arguments for the helper script
52-
args = [str(CURRENT_DIRECTORY), str(REPO_ROOT)]
78+
args = [
79+
"--current-dir", str(CURRENT_DIRECTORY),
80+
"--repo-root", str(REPO_ROOT),
81+
]
5382
for title, source in DOCS_MAP.items():
54-
args.extend([title, str(source)])
83+
args.extend(["--doc", title, str(source)])
5584

5685
session.run("python", "docfx_helper.py", *args)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from help import version
16+
17+
def test_version():
18+
assert version.__version__ is not None

0 commit comments

Comments
 (0)