1212
1313PORT = 8181
1414
15+ # if any changes are needed in the files served out of the "samples" folder, you need to delete the .webcache folder
16+ # that is generated at the project root for the tests to be rerun
1517@pytest .fixture (scope = "module" )
1618def http_local_server ():
1719 # Get the directory containing the current file
@@ -26,6 +28,10 @@ def __init__(self, *args, **kwargs):
2628
2729 def spawn_http_server (arg ):
2830 with http .server .HTTPServer (("" , PORT ), Handler ) as httpd :
31+ # this is a behavior to treat extensionless files as CSS is used by
32+ # the test test_pretextbook_css_fetch below, see the docs on that test
33+ # method for more info
34+ Handler .extensions_map = {'' : 'text/css' }
2935 print ("serving at port" , PORT )
3036 try :
3137 httpd .serve_forever ()
@@ -106,6 +112,14 @@ def test_archive_path_as_relative_url(self):
106112 )
107113 assert rel_path == "../kolibri_1.2.3.png"
108114
115+ # If any changes are needed in the files served out of the "samples" folder, you need to delete the .webcache folder
116+ # that is generated at the project root for the tests to be rerun
117+ #
118+ # This test relies on behavior in the embedded http server declared above as a class level fixture
119+ # to treat any extensionless file as having a mime type of text/css.
120+ # Handler.extensions_map = {'': 'text/css'}
121+ # if another test needs different behavior this may need to be customized or have the fixture be scoped to this test
122+ # but for now it seems useful to share the resource between this and other future tests.
109123 def test_pretextbook_css_fetch (self ):
110124 sushi_url = "http://localhost:" + str (PORT ) + "/samples/PreTeXt_book_test/activecalculus.org/single2e/sec-5-2-FTC2.html"
111125 dest_dir = "active_calc_2e_again_" + datetime .now ().strftime ("%Y-%m-%d_%H:%M:%S" )
@@ -118,13 +132,15 @@ def test_pretextbook_css_fetch(self):
118132 book_dest_dir = downloads_dir / dest_dir / "localhost:8181" / "samples" / "PreTeXt_book_test"
119133 with open (book_dest_dir / "activecalculus.org" / "single2e" / "sec-5-2-FTC2.html" , 'r' ) as file :
120134 page_html = file .read ()
121- assert "link href=\" ../../fonts.googleapis.com/css2_family " in page_html
135+ assert "link href=\" ../../fonts.googleapis.com/css2_family_Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0/index.css " in page_html
122136
123137 with open (book_dest_dir / "fonts.googleapis.com" / "css2_family_Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" / "index.css" , 'r' ) as file :
124138 css_file_contents = file .read ()
139+ # this has an extra '..' compared to what is in the original extensionless css file, because in the course of generating an index.css
140+ # file to have clear extensions in the archived version the file ends up nested down another level
125141 assert "src: url(\" ../../fonts.gstatic.com/s/materialsymbolsoutlined" in css_file_contents
126142
127- font_size = os .path .getsize (book_dest_dir / "fonts.gstatic.com" / "s" / "materialsymbolsoutlined" / "v290" / "kJF1BvYX7BgnkSrUwT8OhrdQw4oELdPIeeII9v6oDMzByHX9rA6RzaxHMPdY43zj-jCxv3fzvRNU22ZXGJpEpjC_1v-p_4MrImHCIJIZrDCvHOel .woff" )
143+ font_size = os .path .getsize (book_dest_dir / "fonts.gstatic.com" / "s" / "materialsymbolsoutlined" / "v290" / "material_symbols .woff" )
128144 assert font_size > 0
129145 finally :
130146 shutil .rmtree (downloads_dir / dest_dir )
0 commit comments