Skip to content

Commit

Permalink
rename methods in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikmuhs committed Jan 19, 2025
1 parent adc0961 commit fa239f2
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions python/tests/index/index_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_open_index():
if not os.path.exists(test_dir):
os.mkdir(test_dir)
index = Index(os.path.join(test_dir, "index"))
index.Set("a", "{}")
index.set("a", "{}")
del index
# required for pypy to ensure deletion/destruction of the index object
gc.collect()
Expand All @@ -35,12 +35,12 @@ def test_some_indexing():
os.mkdir(test_dir)
index = Index(os.path.join(test_dir, "index"))
for i in range(0, iterations):
index.Set("key-{}".format(i), "value-{}".format(i))
index.Flush()
index.set("key-{}".format(i), "value-{}".format(i))
index.flush()
for i in range(split, iterations):
assert "key-{}".format(i) in index
index.Delete("key-{}".format(i))
index.Flush()
index.delete("key-{}".format(i))
index.flush()

for i in range(0, split):
assert "key-{}".format(i) in index
Expand All @@ -65,10 +65,10 @@ def test_bulk_add():
for i in range(0, chunk_size * iterations):
key_values.append(("key-{}".format(i), "value-{}".format(i)))
if i % chunk_size == 0:
index.MSet(key_values)
index.mset(key_values)
key_values = []
index.MSet(key_values)
index.Flush()
index.mset(key_values)
index.flush()

for i in range(0, 50):
assert "key-{}".format(random.randrange(0,
Expand All @@ -84,36 +84,36 @@ def test_get_fuzzy():
if not os.path.exists(test_dir):
os.mkdir(test_dir)
write_index = Index(os.path.join(test_dir, "index"))
write_index.Set("apple", "{}")
write_index.Set("apples", "{}")
write_index.Set("banana", "{}")
write_index.Set("orange", "{}")
write_index.Set("avocado", "{}")
write_index.Set("peach", "{}")
write_index.Flush()
write_index.set("apple", "{}")
write_index.set("apples", "{}")
write_index.set("banana", "{}")
write_index.set("orange", "{}")
write_index.set("avocado", "{}")
write_index.set("peach", "{}")
write_index.flush()

read_only_index = ReadOnlyIndex(os.path.join(test_dir, "index"))

for index in [write_index, read_only_index]:
matches = list(index.GetFuzzy("appe", 1, 2))
matches = list(index.get_fuzzy("appe", 1, 2))
assert len(matches) == 1
assert u'apple' == matches[0].matched_string

matches = list(index.GetFuzzy("appes", 2, 2))
matches = list(index.get_fuzzy("appes", 2, 2))
assert len(matches) == 2
assert u'apple' == matches[0].matched_string
assert u'apples' == matches[1].matched_string
matches = list(index.GetFuzzy("apples", 1, 2))
matches = list(index.get_fuzzy("apples", 1, 2))
assert len(matches) == 2
assert u'apple' == matches[0].matched_string
assert u'apples' == matches[1].matched_string
matches = list(index.GetFuzzy("atocao", 2, 1))
matches = list(index.get_fuzzy("atocao", 2, 1))
assert len(matches) == 1
assert u'avocado' == matches[0].matched_string

write_index.Delete("avocado")
write_index.Flush()
matches = list(write_index.GetFuzzy("atocao", 2, 1))
write_index.delete("avocado")
write_index.flush()
matches = list(write_index.get_fuzzy("atocao", 2, 1))
assert len(matches) == 0

del write_index
Expand All @@ -129,43 +129,43 @@ def test_get_near():
os.mkdir(test_dir)
write_index = Index(os.path.join(test_dir, "index"))
# the following geohashes are created from openstreetmap coordinates and translated using a geohash encoder
write_index.Set(
write_index.set(
"u21xj502gs79", "{'city' : 'Kobarid', 'country': 'si'}")
write_index.Set(
write_index.set(
"u21xk2uxkhh2", "{'city' : 'Trnovo ob soci', 'country': 'si'}")
write_index.Set(
write_index.set(
"u21x75n34qrp", "{'city' : 'Srpnecia', 'country': 'si'}")
write_index.Set("u21x6v1nx0c3", "{'city' : 'Zaga', 'country': 'si'}")
write_index.Set(
write_index.set("u21x6v1nx0c3", "{'city' : 'Zaga', 'country': 'si'}")
write_index.set(
"u21xs20w9ssu", "{'city' : 'Cezsoca', 'country': 'si'}")
write_index.Set(
write_index.set(
"u21x6yx5cqy6", "{'city' : 'Log Cezsoski', 'country': 'si'}")
write_index.Set("u21xs7ses4s3", "{'city' : 'Bovec', 'country': 'si'}")
write_index.Flush()
write_index.set("u21xs7ses4s3", "{'city' : 'Bovec', 'country': 'si'}")
write_index.flush()

read_only_index = ReadOnlyIndex(os.path.join(test_dir, "index"))

for index in [write_index, read_only_index]:
# some coordinate nearby, greedy false, so it prefers as close as possible
matches = list(index.GetNear("u21xjjhhymt7", 4))
matches = list(index.get_near("u21xjjhhymt7", 4))
assert len(matches) == 1
assert u'u21xj502gs79' == matches[0].matched_string
assert u"{'city' : 'Kobarid', 'country': 'si'}" == matches[0].value

# greedy match, still closest should be the 1st match
matches = list(index.GetNear("u21xjjhhymt7", 4, True))
matches = list(index.get_near("u21xjjhhymt7", 4, True))
assert len(matches) == 7
assert u'u21xj502gs79' == matches[0].matched_string
assert u"{'city' : 'Kobarid', 'country': 'si'}" == matches[0].value

# closer match near Bovec and Cezsoca but closer to Cezsoca
matches = list(index.GetNear("u21xs20w9ssu", 5))
matches = list(index.get_near("u21xs20w9ssu", 5))
assert len(matches) == 1
assert u'u21xs20w9ssu' == matches[0].matched_string
assert u"{'city' : 'Cezsoca', 'country': 'si'}" == matches[0].value

# greedy should return Bovec, but not the other locations due to the prefix
matches = list(index.GetNear("u21xs20w9ssu", 5, True))
matches = list(index.get_near("u21xs20w9ssu", 5, True))
assert len(matches) == 2
assert u'u21xs20w9ssu' == matches[0].matched_string
assert u"{'city' : 'Cezsoca', 'country': 'si'}" == matches[0].value
Expand Down

0 comments on commit fa239f2

Please sign in to comment.