Skip to content

Commit 7a84a7a

Browse files
committed
asserts
1 parent 3c198ce commit 7a84a7a

File tree

4 files changed

+56
-58
lines changed

4 files changed

+56
-58
lines changed

extensions/positron-python/python_files/posit/positron/tests/test_access_keys.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929

3030
try:
31-
import torch # type: ignore [reportMissingImports] for 3.14
31+
import torch
3232
except ImportError:
3333
torch = None
3434

@@ -98,7 +98,6 @@ def test_encode_access_key_not_implemented_error(case: Any) -> None:
9898
@pytest.mark.parametrize(
9999
"type_name",
100100
[
101-
# for Python 3.14
102101
"torch.Tensor" if torch else "None",
103102
"function",
104103
],

extensions/positron-python/python_files/posit/positron/tests/test_inspectors.py

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,13 @@ def mutate(x):
643643

644644
@pytest.mark.skipif(geopandas is None, reason="geopandas is not available")
645645
def test_inspect_geopandas_dataframe() -> None:
646-
p1 = Polygon([(0, 0), (1, 0), (1, 1)]) # type: ignore
647-
p2 = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]) # type: ignore
648-
p3 = Polygon([(2, 0), (3, 0), (3, 1), (2, 1)]) # type: ignore
646+
assert Polygon
647+
assert geopandas
648+
p1 = Polygon([(0, 0), (1, 0), (1, 1)])
649+
p2 = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
650+
p3 = Polygon([(2, 0), (3, 0), (3, 1), (2, 1)])
649651

650-
value = geopandas.GeoDataFrame({"g": geopandas.GeoSeries([p1, p2, p3]), "data": [0, 1, 2]}) # type: ignore
652+
value = geopandas.GeoDataFrame({"g": geopandas.GeoSeries([p1, p2, p3]), "data": [0, 1, 2]})
651653

652654
rows, cols = value.shape
653655

@@ -725,11 +727,13 @@ def mutate(x):
725727

726728
@pytest.mark.skipif(geopandas is None, reason="geopandas is not available")
727729
def test_inspect_geopandas_series() -> None:
728-
value = geopandas.GeoSeries( # type: ignore
730+
assert Polygon
731+
assert geopandas
732+
value = geopandas.GeoSeries(
729733
[
730-
Polygon([(0, 0), (1, 0), (1, 1)]), # type: ignore
731-
Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]), # type: ignore
732-
Polygon([(2, 0), (3, 0), (3, 1), (2, 1)]), # type: ignore
734+
Polygon([(0, 0), (1, 0), (1, 1)]),
735+
Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]),
736+
Polygon([(2, 0), (3, 0), (3, 1), (2, 1)]),
733737
]
734738
)
735739
(rows,) = value.shape
@@ -888,12 +892,13 @@ def test_get_child(value: Any, key: Any, expected: Any) -> None:
888892
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires Python 3.10 or higher")
889893
@pytest.mark.skipif(ibis is None, reason="ibis not available")
890894
def test_inspect_ibis_exprs() -> None:
895+
assert ibis
891896
# Make sure we don't return an executed repr
892-
ibis.options.interactive = True # type: ignore
897+
ibis.options.interactive = True
893898

894899
test_df = pd.DataFrame({"a": [1, 2, 1, 1, 2], "b": ["foo", "bar", "baz", "qux", None]})
895900
_, columns = test_df.shape
896-
t = ibis.memtable(test_df, name="df") # type: ignore
901+
t = ibis.memtable(test_df, name="df")
897902
table_type = "ibis.Table"
898903

899904
verify_inspector(
@@ -931,21 +936,16 @@ def test_inspect_ibis_exprs() -> None:
931936
@pytest.mark.parametrize(
932937
("value", "expected"),
933938
[
934-
(lambda: np.array([[1, 2, 3], [4, 5, 6]], dtype="int64"), 48),
935-
pytest.param(
936-
lambda: torch.Tensor([[1, 2, 3], [4, 5, 6]]), # type: ignore
937-
24,
938-
marks=pytest.mark.skipif(torch is None, reason="torch not available"),
939-
),
940-
(lambda: pd.Series([1, 2, 3, 4]), 32),
941-
(lambda: pl.Series([1, 2, 3, 4]), 32),
942-
(lambda: pd.DataFrame({"a": [1, 2], "b": ["3", "4"]}), 4),
943-
(lambda: pl.DataFrame({"a": [1, 2], "b": ["3", "4"]}), 4),
944-
(lambda: pd.Index([0, 1]), 16),
939+
(np.array([[1, 2, 3], [4, 5, 6]], dtype="int64"), 48),
940+
(torch.Tensor([[1, 2, 3], [4, 5, 6]]) if torch else None, 24),
941+
(pd.Series([1, 2, 3, 4]), 32),
942+
(pl.Series([1, 2, 3, 4]), 32),
943+
(pd.DataFrame({"a": [1, 2], "b": ["3", "4"]}), 4),
944+
(pl.DataFrame({"a": [1, 2], "b": ["3", "4"]}), 4),
945+
(pd.Index([0, 1]), 16),
945946
],
946947
)
947-
def test_arrays_maps_get_size(value: Callable, expected: int) -> None:
948-
value = value()
948+
def test_arrays_maps_get_size(value: Any, expected: int) -> None:
949949
if value is None:
950950
return
951951
inspector = get_inspector(value)
@@ -959,53 +959,52 @@ class VeryLongClassNameThatShouldDefinitelyBeTruncatedBecauseItIsWayTooLong:
959959
@pytest.mark.parametrize(
960960
"value",
961961
[
962-
pytest.param(lambda: "The quick brown fox jumps over the lazy dog", id="string"),
963-
pytest.param(lambda: sys.maxsize * 100, id="int"),
964-
pytest.param(lambda: sys.float_info.max, id="float"),
965-
pytest.param(lambda: complex(sys.float_info.min, sys.float_info.max), id="complex"),
962+
pytest.param("The quick brown fox jumps over the lazy dog", id="string"),
963+
pytest.param(sys.maxsize * 100, id="int"),
964+
pytest.param(sys.float_info.max, id="float"),
965+
pytest.param(complex(sys.float_info.min, sys.float_info.max), id="complex"),
966966
pytest.param(
967-
lambda: VeryLongClassNameThatShouldDefinitelyBeTruncatedBecauseItIsWayTooLong,
967+
VeryLongClassNameThatShouldDefinitelyBeTruncatedBecauseItIsWayTooLong,
968968
id="class",
969969
),
970-
pytest.param(lambda: b"The quick brown fox jumps over the lazy dog", id="bytes"),
970+
pytest.param(b"The quick brown fox jumps over the lazy dog", id="bytes"),
971+
pytest.param(bytearray(b"The quick brown fox jumps over the lazy dog"), id="bytearray"),
972+
pytest.param(set(range(20)), id="set"),
973+
pytest.param(frozenset(range(20)), id="frozenset"),
974+
pytest.param(list(range(20)), id="list"),
975+
pytest.param(LIST_WITH_CYCLE, id="list_cycle"),
976+
pytest.param(range(12345678901), id="range"),
977+
pytest.param(L(range(20)), id="fastcore_list"),
978+
pytest.param(FASTCORE_LIST_WITH_CYCLE, id="fastcore_list_cycle"),
979+
pytest.param({str(i): i for i in range(20)}, id="map"),
980+
pytest.param(MAP_WITH_CYCLE, id="map_cycle"),
971981
pytest.param(
972-
lambda: bytearray(b"The quick brown fox jumps over the lazy dog"), id="bytearray"
973-
),
974-
pytest.param(lambda: set(range(20)), id="set"),
975-
pytest.param(lambda: frozenset(range(20)), id="frozenset"),
976-
pytest.param(lambda: list(range(20)), id="list"),
977-
pytest.param(lambda: LIST_WITH_CYCLE, id="list_cycle"),
978-
pytest.param(lambda: range(12345678901), id="range"),
979-
pytest.param(lambda: L(range(20)), id="fastcore_list"),
980-
pytest.param(lambda: FASTCORE_LIST_WITH_CYCLE, id="fastcore_list_cycle"),
981-
pytest.param(lambda: {str(i): i for i in range(20)}, id="map"),
982-
pytest.param(lambda: MAP_WITH_CYCLE, id="map_cycle"),
983-
pytest.param(
984-
lambda: datetime.datetime(2021, 1, 1, 1, 23, 45, tzinfo=datetime.timezone.utc),
982+
datetime.datetime(2021, 1, 1, 1, 23, 45, tzinfo=datetime.timezone.utc),
985983
id="timestamp_datetime",
986984
),
987-
pytest.param(lambda: pd.Timestamp("2021-01-01 01:23:45"), id="timestamp_pandas"),
988-
pytest.param(lambda: pd.Index(list(range(20))), id="pandas_index"),
989-
pytest.param(lambda: pd.Series(list(range(20))), id="pandas_series"),
985+
pytest.param(pd.Timestamp("2021-01-01 01:23:45"), id="timestamp_pandas"),
986+
pytest.param(pd.Index(list(range(20))), id="pandas_index"),
987+
pytest.param(pd.Series(list(range(20))), id="pandas_series"),
990988
pytest.param(
991-
lambda: pd.DataFrame({"a": list(range(20)), "b": list(range(20))}),
989+
pd.DataFrame({"a": list(range(20)), "b": list(range(20))}),
992990
id="pandas_dataframe",
993991
),
994-
pytest.param(lambda: pl.Series(list(range(20))), id="polars_series"),
992+
pytest.param(pl.Series(list(range(20))), id="polars_series"),
995993
pytest.param(
996-
lambda: pl.DataFrame({"a": list(range(20)), "b": list(range(20))}),
994+
pl.DataFrame({"a": list(range(20)), "b": list(range(20))}),
997995
id="polars_dataframe",
998996
),
999-
pytest.param(lambda: np.ones((20, 20)), id="numpy_array"),
997+
pytest.param(np.ones((20, 20)), id="numpy_array"),
1000998
pytest.param(
1001-
lambda: torch.ones((20, 20)), # type: ignore
999+
torch.ones((20, 20)) if torch else None,
10021000
id="torch_tensor",
10031001
marks=pytest.mark.skipif(torch is None, reason="torch not available"),
10041002
),
10051003
],
10061004
)
10071005
def test_truncated_display_value(value, snapshot, monkeypatch) -> None:
1008-
value = value()
1006+
if value is None:
1007+
return
10091008
# Patch the maximum string length for faster and more readable tests.
10101009
monkeypatch.setattr(inspectors, "MAX_ITEMS_BY_LEVEL", (20, 10))
10111010
monkeypatch.setattr(inspectors, "MAX_CHARACTERS", 20)

extensions/positron-python/python_files/posit/positron/tests/test_patch/test_haystack.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
# Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
44
#
55

6-
import sys
6+
from importlib.util import find_spec
77
from typing import Any, Dict
88
from unittest.mock import patch
99

1010
import pytest
1111

1212
from positron.positron_ipkernel import PositronShell
1313

14+
missing_haystack = find_spec("haystack") is None and find_spec("haystack_ai") is None
1415

15-
@pytest.mark.skipif(
16-
sys.version_info >= (3, 14), reason="haystack is not installed at all on 3.14 yet"
17-
)
16+
17+
@pytest.mark.skipif(missing_haystack, reason="haystack is not installed")
1818
def test_haystack_patch_automatically_applied(shell: PositronShell):
1919
"""
2020
Test that the haystack is_in_jupyter function is automatically patched to return True.

extensions/positron-python/python_files/posit/positron/tests/test_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_set_console_width(ui_comm: DummyComm) -> None:
105105
assert pd.get_option("display.width") is None
106106
assert pl.Config.state()["POLARS_TABLE_WIDTH"] == str(width)
107107
if torch is not None:
108-
assert torch._tensor_str.PRINT_OPTS.linewidth == width # noqa: SLF001 # type: ignore
108+
assert torch._tensor_str.PRINT_OPTS.linewidth == width # type: ignore[reportGeneralTypeIssues] # noqa: SLF001
109109

110110

111111
def test_open_editor(ui_service: UiService, ui_comm: DummyComm) -> None:

0 commit comments

Comments
 (0)