Skip to content

Commit 79e1e1d

Browse files
authored
v1 API update_time, name, batch_restore_version increase coverage (#2668)
#### Reference Issues/PRs <!--Example: Fixes #1234. See also #3456.--> #### What does this implement or fix? update_time - no coverage in tests. A test for existing/non-existing symbol + versions valid/invalid batch_restore_version - Good coverage exists. Missing: Test with as_of negative number and a snapshot, unuqual lists name() - not covered - we could add an a small coverage in a test #### Any other comments? #### Checklist <details> <summary> Checklist for code changes... </summary> - [ ] Have you updated the relevant docstrings, documentation and copyright notice? - [ ] Is this contribution tested against [all ArcticDB's features](../docs/mkdocs/docs/technical/contributing.md)? - [ ] Do all exceptions introduced raise appropriate [error messages](https://docs.arcticdb.io/error_messages/)? - [ ] Are API changes highlighted in the PR description? - [ ] Is the PR labelled as enhancement or bug so it appears in autogenerated release notes? </details> <!-- Thanks for contributing a Pull Request to ArcticDB! Please ensure you have taken a look at: - ArcticDB's Code of Conduct: https://github.com/man-group/ArcticDB/blob/master/CODE_OF_CONDUCT.md - ArcticDB's Contribution Licensing: https://github.com/man-group/ArcticDB/blob/master/docs/mkdocs/docs/technical/contributing.md#contribution-licensing --> --------- Co-authored-by: Georgi Rusev <Georgi Rusev>
1 parent f935133 commit 79e1e1d

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

python/tests/integration/arcticdb/version_store/test_basic_version_store.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)
3232
from arcticdb import QueryBuilder
3333
from arcticdb.flattener import Flattener
34+
from arcticdb.util.utils import generate_random_numpy_array, generate_random_series
3435
from arcticdb.version_store import NativeVersionStore
3536
from arcticdb.version_store._store import VersionedItem
3637
from arcticdb_ext.exceptions import _ArcticLegacyCompatibilityException, StorageException
@@ -1144,6 +1145,37 @@ def test_update_times(basic_store):
11441145
assert update_times_versioned[0] < update_times_versioned[1] < update_times_versioned[2]
11451146

11461147

1148+
@pytest.mark.storage
1149+
def test_update_time(basic_store):
1150+
lib: NativeVersionStore = basic_store
1151+
1152+
nparr = generate_random_numpy_array(50, np.float32, seed=None)
1153+
series = generate_random_series(np.uint64, 50, "numbers")
1154+
df = pd.DataFrame(data={"col1": np.arange(10)}, index=pd.date_range(pd.Timestamp(0), periods=10))
1155+
lib.write("sym1", nparr)
1156+
lib.write("sym1", series)
1157+
lib.snapshot("snap")
1158+
lib.write("sym1", df)
1159+
1160+
# Negative number for as_of works as expected (dataframes)
1161+
assert lib.update_time("sym1") == lib.update_time("sym1", -1) == lib.update_time("sym1", 2)
1162+
# Snapshots are accepted (series)
1163+
assert lib.update_time("sym1", 1) == lib.update_time("sym1", -2) == lib.update_time("sym1", "snap")
1164+
# and now check for np array
1165+
assert lib.update_time("sym1", 0) == lib.update_time("sym1", -3)
1166+
1167+
# Times are ordered
1168+
assert lib.update_time("sym1") > lib.update_time("sym1", 1) > lib.update_time("sym1", 0)
1169+
1170+
# Correct exception thrown if symbol does not exist
1171+
with pytest.raises(NoDataFoundException):
1172+
lib.update_time("sym12")
1173+
1174+
# Correct exception thrown if version does not exist
1175+
with pytest.raises(NoDataFoundException):
1176+
lib.update_time("sym1", 11)
1177+
1178+
11471179
@pytest.mark.storage
11481180
@pytest.mark.parametrize(
11491181
"index_names",
@@ -2540,6 +2572,7 @@ def test_batch_restore_version_mixed_as_ofs(lmdb_version_store):
25402572
second_ts = pd.Timestamp(2000)
25412573
ManualClockVersionStore.time = second_ts.value
25422574
lib.batch_write(syms, second_data, second_metadata)
2575+
lib.snapshot("snap")
25432576

25442577
third_ts = pd.Timestamp(3000)
25452578
ManualClockVersionStore.time = third_ts.value
@@ -2571,6 +2604,32 @@ def test_batch_restore_version_mixed_as_ofs(lmdb_version_store):
25712604
assert latest["s2"].metadata == "s2-2"
25722605
assert latest["s3"].metadata == "s3-1"
25732606

2607+
# check restore from snapshot and negative ver number
2608+
res = lib.batch_restore_version(syms, [-3, "snap", -1])
2609+
2610+
# check returned data
2611+
assert res[0].symbol == "s1"
2612+
assert res[1].symbol == "s2"
2613+
assert res[2].symbol == "s3"
2614+
assert res[0].version == 3
2615+
assert res[1].version == 4
2616+
assert res[2].version == 3 # We restored last version (-1 is last)
2617+
assert res[0].metadata == "s1-1"
2618+
assert res[1].metadata == "s2-2"
2619+
assert res[2].metadata == "s3-1"
2620+
2621+
# check latest version of symbols from the read
2622+
latest = lib.batch_read(syms)
2623+
assert latest["s1"].version == 3
2624+
assert latest["s2"].version == 4
2625+
assert latest["s3"].version == 3
2626+
assert_equal(latest["s1"].data, first_data[0])
2627+
assert_equal(latest["s2"].data, second_data[1])
2628+
assert_equal(latest["s3"].data, first_data[2])
2629+
assert latest["s1"].metadata == "s1-1"
2630+
assert latest["s2"].metadata == "s2-2"
2631+
assert latest["s3"].metadata == "s3-1"
2632+
25742633

25752634
@pytest.mark.parametrize("bad_thing", ("symbol", "as_of", "duplicate"))
25762635
def test_batch_restore_version_bad_input_noop(lmdb_version_store, bad_thing):
@@ -2709,6 +2768,15 @@ def test_batch_restore_version(basic_store_tombstone):
27092768
assert_equal(read_df, dfs[d])
27102769

27112770

2771+
@pytest.mark.storage
2772+
def test_name_method(basic_store_factory):
2773+
2774+
for lib_name in ["my name", "1243"]:
2775+
lib: NativeVersionStore = basic_store_factory(name=lib_name)
2776+
assert lib_name == lib.name()
2777+
lib.version_store.clear()
2778+
2779+
27122780
@pytest.mark.storage
27132781
def test_batch_append(basic_store_tombstone, three_col_df):
27142782
lmdb_version_store = basic_store_tombstone

0 commit comments

Comments
 (0)