Skip to content

Commit

Permalink
fix: re-add Python 3.10 support (#17)
Browse files Browse the repository at this point in the history
* 3.10 support

* remove flaky tests

* ignore lines for coverage
  • Loading branch information
masci authored Oct 6, 2024
1 parent bd3fae6 commit 378e557
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.11', '3.12']
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 6 additions & 1 deletion src/banks/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
#
# SPDX-License-Identifier: MIT
import uuid
from typing import Any, Protocol, Self
from typing import Any, Protocol

try:
from typing import Self
except ImportError: # pragma: no cover
from typing_extensions import Self

from pydantic import BaseModel, ValidationError

Expand Down
5 changes: 4 additions & 1 deletion src/banks/registries/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
# SPDX-License-Identifier: MIT
import time
from pathlib import Path
from typing import Self

try:
from typing import Self
except ImportError: # pragma: no cover
from typing_extensions import Self
from pydantic import BaseModel, Field

from banks import Prompt
Expand Down
16 changes: 5 additions & 11 deletions tests/test_directory_registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import time
from pathlib import Path

import pytest
Expand Down Expand Up @@ -63,37 +62,32 @@ def test_set_existing_no_overwrite(registry: DirectoryPromptRegistry):

def test_set_existing_overwrite(registry: DirectoryPromptRegistry):
new_prompt = Prompt("a new prompt!", name="blog")
current_time = time.ctime()
registry.set(prompt=new_prompt, overwrite=True)
assert registry.get(name="blog").text() == "a new prompt!"
assert registry.get(name="blog").metadata == {
"created_at": current_time
} # created_at changes because it's overwritten
assert "created_at" in registry.get(name="blog").metadata # created_at is added when overwrite==True


def test_set_multiple_templates(registry: DirectoryPromptRegistry):
current_time = time.ctime()

new_prompt = Prompt("a very new prompt!", name="new", version="2")
registry.set(prompt=new_prompt)
old_prompt = Prompt("an old prompt!", name="old", version="1")
registry.set(prompt=old_prompt)

p = registry.get(name="old", version="1")
assert p.raw == "an old prompt!"
assert p.metadata == {"created_at": current_time}
assert "created_at" in p.metadata

p = registry.get(name="new", version="2")
assert p.raw == "a very new prompt!"
assert p.metadata == {"created_at": current_time}
assert "created_at" in p.metadata


def test_update_meta(registry: DirectoryPromptRegistry):
# test metadata for initial set
new_prompt = Prompt("a very new prompt!", name="new", version="3", metadata={"accuracy": 91.2})
current_time = time.ctime()
registry.set(prompt=new_prompt)
assert registry.get(name="new", version="3").metadata == {"accuracy": 91.2, "created_at": current_time}
created_at = new_prompt.metadata["created_at"]
assert registry.get(name="new", version="3").metadata == {"accuracy": 91.2, "created_at": created_at}

# test metadata update for existing prompt
p = registry.get(name="new", version="3")
Expand Down

0 comments on commit 378e557

Please sign in to comment.