Skip to content

Commit

Permalink
use Typeguard@HEAD
Browse files Browse the repository at this point in the history
for agronholm/typeguard#490, for Python 3.12 tests
  • Loading branch information
ryan-williams committed Oct 18, 2024
1 parent f82bf0b commit 5606b83
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion apis/python/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ ruff
pytest
pytest-cov
sparse
typeguard==4.3.0
# Python 3.12 support requires https://github.com/agronholm/typeguard/pull/490.
# Use Typeguard @ HEAD until that PR is included in a release.
typeguard @ git+https://github.com/agronholm/typeguard
types-setuptools
27 changes: 22 additions & 5 deletions apis/python/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,9 @@ def make_multiply_indexed_dataframe(
"domain": [[-1000, 1000]],
"coords": [{"bogus": True}],
"A": None,
"throws": TypeError,
# Disable Typeguard while asserting this error, otherwise a typeguard.TypeCheckError is
# raised (though that's not what would happen in production)
"throws": (TypeError, False),
},
{
"name": "bad index type bool",
Expand Down Expand Up @@ -890,15 +892,30 @@ def test_read_indexing(tmp_path, io):
read_kwargs.update(
{k: io[k] for k in ("coords", "partitions", "value_filter") if k in io}
)
if io.get("throws", None):
with pytest.raises(io["throws"]):

# `throws` can be `Type[Exception]`, or `(Type[Exception], bool)` indicating explicitly
# whether Typeguard should be enabled during the `with raises` check.
throws = io.get("throws", None)
if throws:
if isinstance(throws, tuple) and not throws[1]:
# Disable Typeguard, verify actual runtime error type (avoid
# `typeguard.TypeCheckError` short-circuit)
throws = throws[0]
throws_ctx = raises_no_typeguard
else:
throws_ctx = pytest.raises
else:
throws_ctx = None

if throws_ctx:
with throws_ctx(throws):
next(sdf.read(**read_kwargs))
else:
table = next(sdf.read(**read_kwargs))
assert table["A"].to_pylist() == io["A"]

if io.get("throws", None):
with pytest.raises(io["throws"]):
if throws_ctx:
with throws_ctx(throws):
next(sdf.read(**read_kwargs)).to_pandas()
else:
table = next(sdf.read(**read_kwargs)).to_pandas()
Expand Down
2 changes: 1 addition & 1 deletion apis/python/tests/test_sparse_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ def test_sparse_nd_array_error_corners(tmp_path):

with soma.SparseNDArray.open(tmp_path.as_posix()) as a:
# other coord types are illegal
with pytest.raises(TypeError):
with raises_no_typeguard(TypeError):
next(a.read("hi").tables())


Expand Down

0 comments on commit 5606b83

Please sign in to comment.