Skip to content

Commit

Permalink
Improve JavaScript test fixture generation (#12531)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <[email protected]>
  • Loading branch information
jayaddison and AA-Turner committed Jul 10, 2024
1 parent 6e3a191 commit 84c11b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

from tests.utils import TESTS_ROOT

JAVASCRIPT_TEST_ROOTS = list((TESTS_ROOT / 'js' / 'roots').iterdir())
JAVASCRIPT_TEST_ROOTS = [
directory
for directory in (TESTS_ROOT / 'js' / 'roots').iterdir()
if (directory / 'conf.py').exists()
]


class DummyEnvironment:
Expand Down
13 changes: 9 additions & 4 deletions utils/generate_js_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env python3

import shutil
import subprocess
from pathlib import Path

SPHINX_ROOT = Path(__file__).resolve().parent.parent
TEST_JS_FIXTURES = SPHINX_ROOT / 'tests' / 'js' / 'fixtures'
TEST_JS_ROOTS = SPHINX_ROOT / 'tests' / 'js' / 'roots'
TEST_JS_ROOTS = [
directory
for directory in (SPHINX_ROOT / 'tests' / 'js' / 'roots').iterdir()
if (directory / 'conf.py').exists()
]


def build(srcdir: Path) -> None:
Expand All @@ -20,15 +25,15 @@ def build(srcdir: Path) -> None:
subprocess.run(cmd, check=True, capture_output=True)


for directory in TEST_JS_ROOTS.iterdir():
for directory in TEST_JS_ROOTS:
searchindex = directory / '_build' / 'searchindex.js'
destination = TEST_JS_FIXTURES / directory.name / 'searchindex.js'

print(f'Building {directory} ... ', end='')
build(directory)
print('done')

print(f'Moving {searchindex} to {destination} ... ', end='')
print(f'Copying {searchindex} to {destination} ... ', end='')
destination.parent.mkdir(exist_ok=True)
searchindex.replace(destination)
shutil.copy2(searchindex, destination)
print('done')

0 comments on commit 84c11b2

Please sign in to comment.