Skip to content

Commit

Permalink
Get pytest working in CI; fix py tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luciaquirke committed Apr 4, 2024
1 parent a872623 commit dd216a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/rust-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ jobs:
run: cargo build --verbose
- name: Run Rust tests
run: cargo test --verbose
- name: Install Python tokengrams
run: |
python -m pip install --upgrade pip
pip install ./tokengrams[dev]
- name: Run Python tests
run: pytest --verbose
working-directory: ./tokengrams
run: |
python -m pip install --upgrade pip
pip install pytest hypothesis numpy maturin
maturin build
pytest --verbose
8 changes: 4 additions & 4 deletions tokengrams/tests/test_gram_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ def check_gram_index(index: InMemoryIndex | MemmapIndex, tokens: list[int]):
)
def test_gram_index(tokens: list[int]):
# Construct index
index = InMemoryIndex(tokens)
index = InMemoryIndex(tokens, False)
check_gram_index(index, tokens)

# Save to disk and check that we can load it back
with NamedTemporaryFile() as f:
memmap = np.memmap(f, dtype=np.uint16, mode="w+", shape=(len(tokens),))
memmap[:] = tokens

index = InMemoryIndex.from_token_file(f.name, None)
index = InMemoryIndex.from_token_file(f.name, False, None)
check_gram_index(index, tokens)

with NamedTemporaryFile() as idx:
index = MemmapIndex.build(f.name, idx.name)
index = MemmapIndex.build(f.name, idx.name, False)
check_gram_index(index, tokens)

index = MemmapIndex(f.name, idx.name)
check_gram_index(index, tokens)

# Now check limited token loading
for limit in range(1, len(tokens) + 1):
index = InMemoryIndex.from_token_file(f.name, limit)
index = InMemoryIndex.from_token_file(f.name, False, limit)
check_gram_index(index, tokens[:limit])
4 changes: 2 additions & 2 deletions tokengrams/tokengrams.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class InMemoryIndex:
"""An n-gram index."""

def __init__(self, tokens: list[int]) -> None:
def __init__(self, tokens: list[int], verbose: bool) -> None:
...

@staticmethod
def from_token_file(path: str, token_limit: int | None, verbose: bool) -> "InMemoryIndex":
def from_token_file(path: str, verbose: bool, token_limit: int | None) -> "InMemoryIndex":
"""Construct a `InMemoryIndex` from a file containing raw little-endian tokens."""

def contains(self, query: list[int]) -> bool:
Expand Down

0 comments on commit dd216a4

Please sign in to comment.