-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_settings_api.py
More file actions
44 lines (32 loc) · 1.43 KB
/
Copy pathtest_settings_api.py
File metadata and controls
44 lines (32 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest
from pyritone.settings import AsyncSettingsNamespace
class DummyAsyncClient:
def __init__(self) -> None:
self.calls: list[tuple[object, ...]] = []
self.settings = AsyncSettingsNamespace(self)
async def set(self, *args):
self.calls.append(args)
command_text = "set " + " ".join(str(value).lower() if isinstance(value, bool) else str(value) for value in args)
return {"raw": {}, "command_text": command_text}
@pytest.mark.asyncio
async def test_async_settings_handle_methods():
client = DummyAsyncClient()
set_dispatch = await client.settings.allowSprint.set(True)
get_dispatch = await client.settings.allowSprint.get()
toggle_dispatch = await client.settings.allowSprint.toggle()
reset_dispatch = await client.settings.allowSprint.reset()
assert set_dispatch["command_text"] == "set allowSprint true"
assert get_dispatch["command_text"] == "set allowSprint"
assert toggle_dispatch["command_text"] == "set toggle allowSprint"
assert reset_dispatch["command_text"] == "set reset allowSprint"
assert client.calls == [
("allowSprint", True),
("allowSprint",),
("toggle", "allowSprint"),
("reset", "allowSprint"),
]
@pytest.mark.asyncio
async def test_async_settings_private_attribute_access_raises():
client = DummyAsyncClient()
with pytest.raises(AttributeError):
_ = client.settings._missing_private