11"""Test working of extension."""
22
33import os
4+
45import pytest
56
6- from tests import TEST_DOCS_SRC
77from sphinx_search .extension import ASSETS_FILES
8-
9-
10- @pytest .mark .sphinx (srcdir = TEST_DOCS_SRC )
11- def test_static_files_exists (app , status , warning ):
12- """Test if the static files are present in the _build folder."""
13- app .build ()
14- path = app .outdir
15-
16- static_files = ASSETS_FILES ['minified' ] + ASSETS_FILES ['un-minified' ]
17-
18- for file in static_files :
19- file_path = os .path .join (path , '_static' , file )
20- assert (
21- os .path .exists (file_path )
22- ), f'{ file_path } should be present in the _build folder'
8+ from tests import TEST_DOCS_SRC
239
2410
2511@pytest .mark .sphinx (
@@ -36,12 +22,15 @@ def test_minified_static_files_injected_in_html(selenium, app, status, warning):
3622 selenium .get (f'file://{ path } ' )
3723 page_source = selenium .page_source
3824
39- assert app .config .rtd_sphinx_search_file_type == 'minified'
40-
4125 file_type = app .config .rtd_sphinx_search_file_type
42- files = ASSETS_FILES [file_type ]
26+ assert file_type == 'minified'
27+
28+ for file in ASSETS_FILES [file_type ]:
29+ file_path = os .path .join (app .outdir , '_static' , file )
30+ assert (
31+ os .path .exists (file_path )
32+ ), f'{ file_path } should be present in the _build folder'
4333
44- for file in files :
4534 file_name = file .split ('/' )[- 1 ]
4635 assert (
4736 page_source .count (file_name ) == 1
@@ -62,13 +51,16 @@ def test_un_minified_static_files_injected_in_html(selenium, app, status, warnin
6251 selenium .get (f'file://{ path } ' )
6352 page_source = selenium .page_source
6453
65- assert app .config .rtd_sphinx_search_file_type == 'un-minified'
66-
6754 file_type = app .config .rtd_sphinx_search_file_type
68- files = ASSETS_FILES [file_type ]
55+ assert file_type == 'un-minified'
56+
57+ for file in ASSETS_FILES [file_type ]:
58+ file_path = os .path .join (app .outdir , '_static' , file )
59+ assert (
60+ os .path .exists (file_path )
61+ ), f'{ file_path } should be present in the _build folder'
6962
70- for file in files :
7163 file_name = file .split ('/' )[- 1 ]
7264 assert (
7365 page_source .count (file_name ) == 1
74- ), f'{ file_name } should be present in the page source'
66+ ), f'{ file } should be present in the page source'
0 commit comments