Skip to content

Commit 92f7c67

Browse files
Justineantoinejourdain
authored andcommitted
tests(translator): test with prefix and custom translation
1 parent 932ec90 commit 92f7c67

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

tests/test_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def on_change(**_):
109109
def another_method():
110110
pass
111111

112-
assert server.state._change_callbacks["a"][0] == on_change
112+
assert server.state._change_callbacks["a"][0][0] == on_change
113113
assert server.trigger_name(another_method) == "my_name"
114114
assert server.name == "test_enable_module"
115115

tests/test_translator.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def func2():
1616
def func3():
1717
return 3
1818

19+
1920
def test_translator():
2021
a_translator = Translator()
2122
a_translator.add_translation("foo", "a_foo")
@@ -33,6 +34,16 @@ def test_translator():
3334
assert b_translator.reverse_translate_key("b_foo") == "foo"
3435
assert b_translator.reverse_translate_key("b_bar") == "bar"
3536

37+
c_translator = Translator()
38+
c_translator.set_prefix("c_")
39+
c_translator.add_translation("foo", "still_foo")
40+
41+
assert c_translator.translate_key("foo") == "still_foo"
42+
assert c_translator.translate_key("bar") == "c_bar"
43+
assert c_translator.reverse_translate_key("still_foo") == "foo"
44+
assert c_translator.reverse_translate_key("c_foo") == "foo"
45+
assert c_translator.reverse_translate_key("c_bar") == "bar"
46+
3647

3748
def test_state_translation():
3849
root_state = State()
@@ -301,7 +312,7 @@ def test_change_callback():
301312
a_state = State(internal=root_state)
302313
a_state.translator.add_translation("foo", "a_foo")
303314

304-
def on_a_foo_change(*args, **kwargs):
315+
def on_a_foo_change(*_args, **kwargs):
305316
nonlocal test_passed
306317
assert "foo" in kwargs
307318
assert "a_foo" not in kwargs
@@ -324,7 +335,7 @@ def on_a_foo_change(*args, **kwargs):
324335
b_state = State(internal=root_state)
325336
b_state.translator.set_prefix("b_")
326337

327-
def on_b_foo_change(*args, **kwargs):
338+
def on_b_foo_change(*_args, **kwargs):
328339
nonlocal test_passed
329340
assert "foo" in kwargs
330341
assert "b_foo" not in kwargs

trame_server/state.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ def flush(self):
308308
if not inspect.iscoroutinefunction(callback):
309309
callback = reload(callback)
310310

311-
reverse_translated_state = translator.reverse_translate_dict(self._pushed_state)
311+
reverse_translated_state = translator.reverse_translate_dict(
312+
self._pushed_state
313+
)
312314
coroutine = callback(**reverse_translated_state)
313315
if inspect.isawaitable(coroutine):
314316
asynchronous.create_task(coroutine)

0 commit comments

Comments
 (0)