Skip to content

Commit e24fbce

Browse files
committed
Refactor tests to pass new Hypothesis healthcheck for differing executors
This may have been the source of intermittent failures related to random bytes generation.
1 parent 73071ec commit e24fbce

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

tiledb/tests/test_hypothesis.py

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,53 @@
77

88
import tiledb
99

10-
from .common import DiskTestCase
11-
1210
pd = pytest.importorskip("pandas")
1311
tm = pd._testing
1412

1513

16-
class AttrDataTest(DiskTestCase):
17-
@hp.settings(deadline=None, verbosity=hp.Verbosity.verbose)
18-
@hp.given(st.binary())
19-
@pytest.mark.parametrize("mode", ["np", "df"])
20-
def test_bytes_npdf(self, mode, data):
21-
start = time.time()
14+
@pytest.mark.parametrize("mode", ["np", "df"])
15+
@hp.settings(deadline=None, verbosity=hp.Verbosity.verbose)
16+
@hp.given(st.binary())
17+
def test_bytes_npdf(checked_path, mode, data):
18+
start = time.time()
19+
20+
uri = "mem://" + checked_path.path()
21+
hp.note(f"!!! path '{uri}' time: {time.time() - start}")
22+
23+
array = np.array([data], dtype="S0")
24+
25+
start_ingest = time.time()
26+
if mode == "np":
27+
with tiledb.from_numpy(uri, array) as A:
28+
pass
29+
else:
30+
series = pd.Series(array)
31+
df = pd.DataFrame({"": series})
32+
# NOTE: ctx required here for mem://
33+
tiledb.from_pandas(uri, df, sparse=False, ctx=tiledb.default_ctx())
2234

23-
uri = "mem://" + self.path()
24-
hp.note(f"!!! self.path() '{uri}' time: {time.time() - start}")
35+
hp.note(f"{mode} ingest time: {time.time() - start_ingest}")
2536

26-
array = np.array([data], dtype="S0")
37+
# DEBUG
38+
tiledb.stats_enable()
39+
tiledb.stats_reset()
40+
# END DEBUG
2741

28-
start_ingest = time.time()
42+
with tiledb.open(uri) as A:
2943
if mode == "np":
30-
with tiledb.from_numpy(uri, array) as A:
31-
pass
44+
np.testing.assert_array_equal(A.multi_index[:][""], array)
3245
else:
33-
series = pd.Series(array)
34-
df = pd.DataFrame({"": series})
35-
# NOTE: ctx required here for mem://
36-
tiledb.from_pandas(uri, df, sparse=False, ctx=tiledb.default_ctx())
37-
38-
hp.note(f"{mode} ingest time: {time.time() - start_ingest}")
39-
40-
# DEBUG
41-
tiledb.stats_enable()
42-
tiledb.stats_reset()
43-
# END DEBUG
44-
45-
with tiledb.open(uri) as A:
46-
if mode == "np":
47-
np.testing.assert_array_equal(A.multi_index[:][""], array)
48-
else:
49-
tm.assert_frame_equal(A.df[:], df)
50-
51-
hp.note(tiledb.stats_dump(print_out=False))
52-
53-
# DEBUG
54-
tiledb.stats_disable()
55-
56-
duration = time.time() - start
57-
hp.note(f"!!! test_bytes_{mode} duration: {duration}")
58-
if duration > 2:
59-
# Hypothesis setup is (maybe) causing deadline exceeded errors
60-
# https://github.com/TileDB-Inc/TileDB-Py/issues/1194
61-
# Set deadline=None and use internal timing instead.
62-
pytest.fail(f"!!! {mode} function body duration exceeded 2s: {duration}")
46+
tm.assert_frame_equal(A.df[:], df)
47+
48+
hp.note(tiledb.stats_dump(print_out=False))
49+
50+
# DEBUG
51+
tiledb.stats_disable()
52+
53+
duration = time.time() - start
54+
hp.note(f"!!! test_bytes_{mode} duration: {duration}")
55+
if duration > 2:
56+
# Hypothesis setup is (maybe) causing deadline exceeded errors
57+
# https://github.com/TileDB-Inc/TileDB-Py/issues/1194
58+
# Set deadline=None and use internal timing instead.
59+
pytest.fail(f"!!! {mode} function body duration exceeded 2s: {duration}")

tiledb/tests/test_multi_index-hp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ def create_array(uri):
8181

8282
return uri
8383

84-
@pytest.mark.parametrize("order", ["C", "F", "U"])
85-
@given(st.lists(bounded_ntuple(length=2, min_value=-100, max_value=100)))
86-
def test_multi_index_two_way_query(self, order, sparse_array_1d, ranges):
84+
@given(
85+
order=st.sampled_from(["C", "F", "U"]),
86+
ranges=st.lists(bounded_ntuple(length=2, min_value=-100, max_value=100)),
87+
)
88+
def test_multi_index_two_way_query(self, order, ranges, sparse_array_1d):
8789
"""This test checks the result of "direct" range queries using PyQuery
8890
against the result of `multi_index` on the same ranges."""
8991

0 commit comments

Comments
 (0)