Skip to content

Commit 587c629

Browse files
committed
feat: add WHEREIN to NEARBY
1 parent 41e81dd commit 587c629

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

pyle38/commands/nearby.py

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self, client: Client, key: str, hook=None) -> None:
5656
self._options = {}
5757
self._hook = hook
5858
self._where = []
59+
self._wherein = []
5960

6061
def key(self, key: str) -> Nearby:
6162
"""Set key to search in
@@ -372,6 +373,7 @@ def compile(self) -> Compiled:
372373
self._key,
373374
*(self.__compile_options()),
374375
*(self.compile_where()),
376+
*(self.compile_wherein()),
375377
*(self.__compile_fence()),
376378
*(self._output if self._output else []),
377379
*(self._query.get()),

tests/test_command_nearby.py

+46
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
"bar",
4444
1,
4545
1,
46+
"WHEREIN",
47+
"foo",
48+
1,
49+
1,
50+
"WHEREIN",
51+
"bar",
52+
1,
53+
1,
4654
"FENCE",
4755
"DETECT",
4856
"enter,exit",
@@ -70,6 +78,8 @@ async def test_command_nearby_compile(tile38, format, precision, expected):
7078
.limit(10)
7179
.where("foo", 1, 1)
7280
.where("bar", 1, 1)
81+
.wherein("foo", 1, [1])
82+
.wherein("bar", 1, [1])
7383
.fence()
7484
.detect(["enter", "exit"])
7585
.commands(["del", "set"])
@@ -127,6 +137,42 @@ async def test_command_nearby_where_point(tile38):
127137
assert len(response.objects) == 2
128138

129139

140+
@pytest.mark.asyncio
141+
async def test_command_nearby_wherein_point(tile38):
142+
await (
143+
tile38.set(key, id)
144+
.fields({"maxspeed": 120, "maxweight": 1000})
145+
.object(feature)
146+
.exec()
147+
)
148+
await (
149+
tile38.set(key, "truck1")
150+
.fields({"maxspeed": 100, "maxweight": 1000})
151+
.object(feature)
152+
.exec()
153+
)
154+
155+
response = (
156+
await tile38.nearby(key)
157+
.wherein("maxspeed", 1, [120])
158+
.point(52.250212, 13.370871)
159+
.asObjects()
160+
)
161+
assert response.ok
162+
assert len(response.objects) == 1
163+
assert response.objects[0].dict() == dict(expected, **{"fields": [120, 1000]})
164+
165+
response = (
166+
await tile38.nearby(key)
167+
.wherein("maxspeed", 2, [100, 120])
168+
.wherein("maxweight", 1, [1000])
169+
.point(52.250212, 13.370871)
170+
.asObjects()
171+
)
172+
assert response.ok
173+
assert len(response.objects) == 2
174+
175+
130176
@pytest.mark.asyncio
131177
async def test_command_nearby_point_with_radius(tile38):
132178
response = await tile38.set(key, id).object(feature).exec()

0 commit comments

Comments
 (0)