Skip to content

Fix docs/google snippet error and add to snippets_test#7803

Merged
pavoljuhas merged 14 commits intoquantumlib:mainfrom
ToastCheng:i7787-2
Feb 25, 2026
Merged

Fix docs/google snippet error and add to snippets_test#7803
pavoljuhas merged 14 commits intoquantumlib:mainfrom
ToastCheng:i7787-2

Conversation

@ToastCheng
Copy link
Contributor

@ToastCheng ToastCheng commented Dec 13, 2025

The PR fixes the md files' snippet errors under docs/google by adding test substitution and MagicMock, also fixing some outdated APIs. On the test side, adding necessary imports for cirq_google to let the tests being able to find necessary variables.

This also extends the test_substitution markup to allow multi-line replacement text.

Partially implements #7787

1. Use test substitution to replace undefined variables
2. Use test substitution to replace cloud APIs with mock class
3. Fix EngineJob constructor

Partially fix quantumlib#7787.
1. Use test substitution to replace undefined variables
2. Use test substitution to replace cloud APIs with mock class
3. Fix unexpected indent and import

Partially fix quantumlib#7787.
1. Use test substitution to replace undefined variables
2. Use test substitution to replace cloud APIs with mock class
3. Fix outdated import paths

Partially fix quantumlib#7787.
@github-actions github-actions bot added the size: M 50< lines changed <250 label Dec 13, 2025
@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.62%. Comparing base (66cc4c8) to head (7b5e4ba).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7803   +/-   ##
=======================================
  Coverage   99.62%   99.62%           
=======================================
  Files        1104     1104           
  Lines       99317    99325    +8     
=======================================
+ Hits        98943    98951    +8     
  Misses        374      374           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add all md files under docs/google to run the snippets_test, also add
necessary import (like cirq_google).
@mhucka mhucka self-assigned this Feb 18, 2026
Allow more mockery than just MagicMock.
- use `create_autospec` so mocked objects fail when asked for
  attributes or passed arguments that are invalid in real objects

- remove non-existing `gate_set` argument from engine.run_sweep
- fix typo in `EngineProcessor.list_calibrations` name

- disable and add a TODO note for obsolete example that
  uses the deleted `Engine.get_job` function
Adjust example to use qubits present on the willow_pink device.
Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have adjusted the mocks to mimic interfaces of real objects which allows to find cases when calling non-existing function or passing wrong number of arguments. For the specification.md it was possible to use virtual engine instead a mock.

@ToastCheng - can you please take a quick look if the PR is good with you? Otherwise LGTM.

@github-actions github-actions bot added size: L 250< lines changed <1000 and removed size: M 50< lines changed <250 labels Feb 24, 2026
Copy link
Contributor Author

@ToastCheng ToastCheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment. Please check, thanks!

def find_markdown_test_overrides(content: str) -> list[tuple[Pattern, str]]:
test_sub_text = find_code_snippets("<!---test_substitution\n(.*?)--->", content)
substitutions = [line.split('\n')[:-1] for line, _ in test_sub_text]
substitutions = [line.rstrip().split('\n', maxsplit=1) for line, _ in test_sub_text]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the behavior changed, maybe add a short explanation?

"""This function finds all the `<!---test_substitution-->` blocks in `content`, and replace `pattern` with `substitutions`:
```
<!---test_substitution
pattern
substitutions
-->
```

noted that `substitutions` could be a multi-line string because `maxsplit` is set to 1, while `pattern` is strictly to be a single line string.
"""

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done in 7b5e4ba.

And also note expansion of the `re.sub` escape sequences.
@pavoljuhas pavoljuhas added this pull request to the merge queue Feb 25, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 25, 2026
@pavoljuhas pavoljuhas added this pull request to the merge queue Feb 25, 2026
Merged via the queue into quantumlib:main with commit e5173b7 Feb 25, 2026
41 checks passed
ToastCheng added a commit to ToastCheng/Cirq that referenced this pull request Feb 28, 2026
Similar to quantumlib#7803, this commit fix the errors from the temporarily
excluded md files.

1. Use mocked Service instance for ionq documents
2. Remove the outdated Circuit initialization in pasqal doc, the
device argument has been removed since quantumlib#5189.
github-merge-queue bot pushed a commit that referenced this pull request Mar 12, 2026
Similar to #7803, this commit fix the errors from the temporarily
excluded md files.

1. Use mocked Service instance for ionq documents
2. Remove the outdated Circuit initialization in pasqal doc, the device
argument has been removed since #5189.

Fixes #7787

---------

Co-authored-by: Pavol Juhas <juhas@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants