Skip to content

Commit dd204c9

Browse files
authored
Fix stats_reset() behavior (#2172)
1 parent 2d6cd80 commit dd204c9

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

tiledb/stats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def stats_disable():
2020

2121
def stats_reset():
2222
"""Reset all TileDB internal statistics to 0."""
23-
from .main import init_stats
23+
from .main import reset_stats
2424

25-
init_stats()
25+
reset_stats()
2626

2727

2828
def stats_dump(

tiledb/tests/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ def assert_dict_arrays_equal(d1, d2, ordered=True):
363363
assert_unordered_equal(array1, array2, True)
364364

365365

366-
def assert_captured(cap, expected):
366+
def assert_captured(cap, val, expected=True):
367+
"""Assert that the captured output contains
368+
or does not contain a value"""
367369
if sys.platform != "win32":
368370
import ctypes
369371

@@ -372,7 +374,7 @@ def assert_captured(cap, expected):
372374

373375
out, err = cap.readouterr()
374376
assert not err
375-
assert expected in out
377+
assert (val in out) == expected
376378

377379

378380
@pytest.fixture(scope="module", params=["hilbert", "row-major", "col-major"])

tiledb/tests/test_stats.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,25 @@ def test_stats(self, capfd):
2222
with tiledb.from_numpy(path, np.arange(10)) as T:
2323
pass
2424

25-
# basic output check for read stats
25+
# check that Writer stats are printed
26+
tiledb.stats_dump()
27+
28+
if tiledb.libtiledb.version() >= (2, 27):
29+
assert_captured(capfd, "Context.Query.Writer")
30+
else:
31+
assert_captured(capfd, "Context.StorageManager.Query.Writer")
32+
33+
# check that Writer stats are not printed because of reset
2634
tiledb.stats_reset()
35+
tiledb.stats_dump()
36+
37+
if tiledb.libtiledb.version() >= (2, 27):
38+
assert_captured(capfd, "Context.Query.Writer", expected=False)
39+
else:
40+
assert_captured(
41+
capfd, "Context.StorageManager.Query.Writer", expected=False
42+
)
43+
2744
with tiledb.open(path) as T:
2845
tiledb.stats_enable()
2946
assert_array_equal(T, np.arange(10))
@@ -32,6 +49,13 @@ def test_stats(self, capfd):
3249
tiledb.stats_dump()
3350
assert_captured(capfd, "TileDB Embedded Version:")
3451

52+
# check that Reader stats are printed
53+
tiledb.stats_dump()
54+
if tiledb.libtiledb.version() >= (2, 27):
55+
assert_captured(capfd, "Context.Query.Reader")
56+
else:
57+
assert_captured(capfd, "Context.StorageManager.Query.Reader")
58+
3559
# test string version
3660
stats_v = tiledb.stats_dump(print_out=False)
3761
if tiledb.libtiledb.version() < (2, 3):
@@ -51,6 +75,16 @@ def test_stats(self, capfd):
5175
else:
5276
self.assertTrue("==== READ ====" in stats_quiet)
5377

78+
# check that Writer stats are not printed because of reset
79+
tiledb.stats_reset()
80+
tiledb.stats_dump()
81+
if tiledb.libtiledb.version() >= (2, 27):
82+
assert_captured(capfd, "Context.Query.Reader", expected=False)
83+
else:
84+
assert_captured(
85+
capfd, "Context.StorageManager.Query.Reader", expected=False
86+
)
87+
5488
def test_stats_include_python_json(self):
5589
tiledb.stats_enable()
5690

0 commit comments

Comments
 (0)