Skip to content

Commit

Permalink
Add first Python API Toolproof test
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Sep 29, 2024
1 parent d66e887 commit 0d495b3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pagefind/integration_tests/python_api/background.toolproof.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Requirements:
# venv
# python>=3.11

name: Python API Setup
type: reference
steps:
- step: I have a "public/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 run 'python3 -m venv "$PWD/.venv"'
- step: I run 'source "$PWD/.venv/bin/activate"'
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Python API > Build a synthetic index to memory via the api
platforms:
- linux
- mac

steps:
- ref: ./background.toolproof.yml
- step: I have a "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",
)
files = await index.get_files()
for file in files:
if "pagefind.js" in file["path"]:
print(file["content"])
print(f"JS is at {file["path"]}")
fragments = [file for file in files if "fragment" in file["path"]]
print(f"{len(fragments)} fragment(s)")
if __name__ == "__main__":
asyncio.run(main())
- step: I run "PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py"
- step: stdout should contain "pagefind_version="
- step: stdout should contain "JS is at pagefind.js"
- step: stdout should contain "1 fragment(s)"
- step: I run "ls -lh public/pagefind/pagefind.js" and expect it to fail
notes: "TODO: Build a file existence check into toolproof"

0 comments on commit 0d495b3

Please sign in to comment.