Skip to content

Commit c151ddc

Browse files
committed
Fix docs path in snippet test and exclude subdirs
1 parent a764b67 commit c151ddc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

dev_tools/snippets_test.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
import cirq
6464

65+
DOCS_FOLDER = pathlib.Path(__file__).parent.parent / 'docs'
6566

6667
def test_can_run_readme_code_snippets():
6768
# Get the contents of the README.md file at the project root.
@@ -72,15 +73,18 @@ def test_can_run_readme_code_snippets():
7273

7374

7475
def find_docs_code_snippets_paths() -> Iterator[str]:
75-
docs_folder = pathlib.Path(__file__).parent
76-
for filename in docs_folder.rglob('*.md'):
77-
yield str(filename.relative_to(docs_folder))
76+
exclude_path = ['hardware', 'google']
77+
for filename in DOCS_FOLDER.rglob('*.md'):
78+
# Skip files under hardware and google, since there are a lot of
79+
# code snippets import cirq_* which can't resolved in the test.
80+
path = str(filename.relative_to(DOCS_FOLDER))
81+
if not any(path.startswith(excluded) for excluded in exclude_path):
82+
yield path
7883

7984

8085
@pytest.mark.parametrize('path', find_docs_code_snippets_paths())
8186
def test_can_run_docs_code_snippets(path):
82-
docs_folder = os.path.dirname(__file__)
83-
assert_file_has_working_code_snippets(os.path.join(docs_folder, path), assume_import=True)
87+
assert_file_has_working_code_snippets(os.path.join(DOCS_FOLDER, path), assume_import=True)
8488

8589

8690
def find_code_snippets(pattern: str, content: str) -> list[tuple[str, int]]:

0 commit comments

Comments
 (0)