Skip to content

Commit

Permalink
Final tranche of Toolproof Python API tests to meet Node API parity
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Sep 29, 2024
1 parent a53f3c2 commit 035f7a7
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Python API > Build a synthetic index to disk via the api
platforms:
- linux
- mac

steps:
- ref: ./background.toolproof.yml
- step: I have a "public/run.py" file with the content {python}
python: |2-
import sys
sys.path.append('%repo_wd%/wrappers/python/src')
import asyncio
import json
import logging
import os
from pagefind.index import PagefindIndex, IndexConfig
async def main():
async with PagefindIndex() as index:
await index.add_html_file(
content="<html><body><h1>Testing, testing</h1></body></html>",
source_path="dogs/index.html",
)
print("Complete")
if __name__ == "__main__":
asyncio.run(main())
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py"
- step: stdout should contain "Complete"
- step: The file "public/pagefind/pagefind.js" should not be empty
- step: I serve the directory "public"
- step: In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
let pagefind = await import("/pagefind/pagefind.js");
let search = await pagefind.search("testing");
let data = await search.results[0].data();
toolproof.assert_eq(data.url, `/dogs/`);
- step: In my browser, the console should be empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Python API > Build a synthetic index with overridden urls to disk via the api

platforms:
- linux
- mac

steps:
- ref: ./background.toolproof.yml
- step: I have a "public/run.py" file with the content {python}
python: |2-
import sys
sys.path.append('%repo_wd%/wrappers/python/src')
import asyncio
import json
import logging
import os
from pagefind.index import PagefindIndex, IndexConfig
async def main():
async with PagefindIndex() as index:
await index.add_html_file(
content="<html><body><h1>Testing, testing</h1></body></html>",
url="/my-custom-url/",
)
print("Complete")
if __name__ == "__main__":
asyncio.run(main())
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py"
- step: stdout should contain "Complete"
- step: The file "public/pagefind/pagefind.js" should not be empty
- step: I serve the directory "public"
- step: In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
let pagefind = await import("/pagefind/pagefind.js");
let search = await pagefind.search("testing");
let data = await search.results[0].data();
toolproof.assert_eq(data.url, `/my-custom-url/`);
- step: In my browser, the console should be empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Python API > Build a true index to disk via the api
platforms:
- linux
- mac

steps:
- ref: ./background.toolproof.yml
- step: >-
I have a "public/custom_files/real/index.html" file with the content
{html}
html: >-
<!DOCTYPE html><html lang="en"><head></head><body> <p>A testing file that
exists on disk</p></body></html>
- step: I have a "public/run.py" file with the content {python}
python: |2-
import sys
sys.path.append('%repo_wd%/wrappers/python/src')
import asyncio
import json
import logging
import os
from pagefind.index import PagefindIndex, IndexConfig
async def main():
async with PagefindIndex() as index:
await index.add_directory(
path="custom_files",
)
print("Complete")
if __name__ == "__main__":
asyncio.run(main())
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py"
- step: stdout should contain "Complete"
- step: The file "public/pagefind/pagefind.js" should not be empty
- step: I serve the directory "public"
- step: In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
let pagefind = await import("/pagefind/pagefind.js");
let search = await pagefind.search("testing");
let data = await search.results[0].data();
toolproof.assert_eq(data.url, `/real/`);
- step: In my browser, the console should be empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Python API > Build an index to a custom disk location via the api
platforms:
- linux
- mac

steps:
- ref: ./background.toolproof.yml
- step: I have a "output/index.html" file with the content {html}
html: >-
<!DOCTYPE html><html lang="en"><head></head><body> <p
data-url>Nothing</p></body></html>
- step: I have a "public/run.py" file with the content {python}
python: |2-
import sys
sys.path.append('%repo_wd%/wrappers/python/src')
import asyncio
import json
import logging
import os
from pagefind.index import PagefindIndex, IndexConfig
async def main():
config = IndexConfig(
output_path="../output/pagefind",
)
async with PagefindIndex(config=config) as index:
await index.add_html_file(
content="<html><body><h1>Testing, testing</h1></body></html>",
source_path="dogs/index.html",
)
print("Complete")
if __name__ == "__main__":
asyncio.run(main())
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py"
- step: stdout should contain "Complete"
- step: The file "output/pagefind/pagefind.js" should not be empty
- step: I serve the directory "output"
- step: In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
let pagefind = await import("/pagefind/pagefind.js");
let search = await pagefind.search("testing");
let data = await search.results[0].data();
toolproof.assert_eq(data.url, `/dogs/`);
- step: In my browser, the console should be empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Python API > Force language takes precedence over records
platforms:
- linux
- mac

steps:
- ref: ./background.toolproof.yml
- step: I have a "public/run.py" file with the content {python}
python: |2-
import sys
sys.path.append('%repo_wd%/wrappers/python/src')
import asyncio
import json
import logging
import os
from pagefind.index import PagefindIndex, IndexConfig
async def main():
config = IndexConfig(
force_language="fr",
)
async with PagefindIndex(config=config) as index:
await index.add_custom_record(
url="/one/",
content="Testing file #1",
language="pt",
)
await index.add_html_file(
source_path="two/index.html",
content="<html lang='en'><body><h1>Testing file #2</h1></body></html>",
)
print("Complete")
if __name__ == "__main__":
asyncio.run(main())
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py"
- step: stdout should contain "Complete"
- step: The file "public/pagefind/pagefind.js" should not be empty
- step: I run "ls -lh public/pagefind/wasm.unknown.pagefind"
notes: "TODO: Build a file existence check into toolproof"
- step: I run "ls -lh public/pagefind/wasm.fr.pagefind"
notes: "TODO: Build a file existence check into toolproof"
- step: I run "ls -lh public/pagefind/wasm.pt.pagefind" and expect it to fail
notes: "TODO: Build a file existence check into toolproof"
- step: I run "ls -lh public/pagefind/wasm.en.pagefind" and expect it to fail
notes: "TODO: Build a file existence check into toolproof"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Python API > Pagefind empty index returns assets
platforms:
- linux
- mac

steps:
- ref: ./background.toolproof.yml
- step: I have a "public/run.py" file with the content {python}
python: |2-
import sys
sys.path.append('%repo_wd%/wrappers/python/src')
import asyncio
import json
import logging
import os
from pagefind.index import PagefindIndex, IndexConfig
async def main():
async with PagefindIndex() as index:
files = await index.get_files()
for file in files:
print(file["path"])
await index.delete_index()
print("Complete")
if __name__ == "__main__":
asyncio.run(main())
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py"
- step: stdout should contain "Complete"
- step: stdout should contain "pagefind.js"
- step: stdout should contain "pagefind-ui.js"
- step: stdout should contain "pagefind-ui.css"
- step: stdout should contain "pagefind-modular-ui.js"
- step: stdout should contain "pagefind-modular-ui.css"
- step: stdout should contain "wasm.unknown.pagefind"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Python API > Pagefind service config
platforms:
- linux
- mac

steps:
- ref: ./background.toolproof.yml
- step: I have a "public/run.py" file with the content {python}
python: |2-
import sys
sys.path.append('%repo_wd%/wrappers/python/src')
import asyncio
import json
import logging
import os
from pagefind.index import PagefindIndex, IndexConfig
async def main():
config = IndexConfig(
root_selector="h1",
exclude_selectors=["span"],
keep_index_url=True
)
async with PagefindIndex(config=config) as index:
await index.add_html_file(
content="<h1>Testing, <span>testing</span></h1>",
source_path="dogs/index.html",
)
print("Complete")
if __name__ == "__main__":
asyncio.run(main())
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py"
- step: stdout should contain "Complete"
- step: The file "public/pagefind/pagefind.js" should not be empty
- step: I serve the directory "public"
- step: In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
let pagefind = await import("/pagefind/pagefind.js");
let search = await pagefind.search("testing");
let data = await search.results[0].data();
toolproof.assert_eq(data.url, `/dogs/index.html`);
toolproof.assert_eq(data.content, `Testing,`);
- step: In my browser, the console should be empty

0 comments on commit 035f7a7

Please sign in to comment.