Skip to content

Commit c1ce97f

Browse files
committed
more fixes
1 parent 1def4a6 commit c1ce97f

7 files changed

Lines changed: 23 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ lint.per-file-ignores."tests/**" = [
126126
"S311",
127127
"S603",
128128
]
129+
lint.per-file-ignores."src/cachier/cores/sql.py" = ["S301"]
129130
lint.unfixable = [
130131
"F401",
131132
]

src/cachier/_version.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
def _get_git_sha() -> str:
1919
from subprocess import DEVNULL, check_output
2020

21-
out = check_output(["git", "rev-parse", "--short", "HEAD"], stderr=DEVNULL) # noqa: S603, S607
21+
out = check_output(
22+
["git", "rev-parse", "--short", "HEAD"], stderr=DEVNULL
23+
) # noqa: S603, S607
2224
return out.decode("utf-8").strip()
2325

2426

src/cachier/cores/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Defines the interface of a cachier caching core."""
2+
23
# This file is part of Cachier.
34
# https://github.com/python-cachier/cachier
45

src/cachier/cores/mongo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def get_entry_by_key(self, key: str) -> Tuple[str, Optional[CacheEntry]]:
7575
)
7676
if not res:
7777
return key, None
78-
val = pickle.loads(res["value"]) if "value" in res else None # noqa: S301
78+
val = (
79+
pickle.loads(res["value"]) if "value" in res else None
80+
) # noqa: S301
7981
entry = CacheEntry(
8082
value=val,
8183
time=res.get("time", None),

src/cachier/cores/sql.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
Base = declarative_base()
4343

4444
class CacheTable(Base):
45+
"""SQLAlchemy model for cachier cache entries."""
46+
4547
__tablename__ = "cachier_cache"
4648
id = Column(String, primary_key=True)
4749
function_id = Column(String, index=True, nullable=False)
@@ -57,8 +59,10 @@ class CacheTable(Base):
5759

5860

5961
class _SQLCore(_BaseCore):
60-
"""SQLAlchemy-based core for Cachier, supporting SQLite, PostgreSQL, MySQL,
61-
etc.
62+
"""SQLAlchemy-based core for Cachier, supporting SQL-based backends.
63+
64+
This should work with SQLite, PostgreSQL and so on.
65+
6266
"""
6367

6468
def __init__(

tests/test_general.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ def fn_minus(a, b=2):
485485
assert cachier_(dummy_)(1) == expected, f"for {fn.__name__} wrapped"
486486

487487
dummy_ = functools.partial(fn, b=2)
488-
assert cachier_(dummy_)(1, b=2) == expected, (
489-
f"for {fn.__name__} wrapped"
490-
)
488+
assert (
489+
cachier_(dummy_)(1, b=2) == expected
490+
), f"for {fn.__name__} wrapped"
491491

492492
assert cachier_(fn)(1, 2) == expected, f"for {fn.__name__} inline"
493493
assert cachier_(fn)(a=1, b=2) == expected, f"for {fn.__name__} inline"

tests/test_sql_core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ def f(x):
144144
assert f(123) == 123
145145

146146

147+
class DummyWriteError(Exception):
148+
pass
149+
150+
147151
@pytest.mark.sql
148152
def test_sql_failed_write(monkeypatch):
149153
@cachier(backend="sql", sql_engine=SQL_CONN_STR)
@@ -155,10 +159,10 @@ def f(x):
155159
orig = _SQLCore.set_entry
156160

157161
def fail_set_entry(self, key, func_res):
158-
raise Exception("fail")
162+
raise DummyWriteError("fail")
159163

160164
monkeypatch.setattr(_SQLCore, "set_entry", fail_set_entry)
161-
with pytest.raises(Exception):
165+
with pytest.raises(DummyWriteError, match="fail"):
162166
f(1)
163167
monkeypatch.setattr(_SQLCore, "set_entry", orig)
164168

0 commit comments

Comments
 (0)