Ejemplo n.º 1
0
def test_js_python_serialization_agree(run_js, c):
    json1 = JSON.stringify(c)
    # print("json1:", json1)        
    json2 = run_js(f"return JSON.stringify(parse({json1}))")
    # print("json2:", json2)
    o1 = json.loads(json1)
    o2 = json.loads(json2)
    o2.pop("color_vec", None)
    assert o1 == o2
Ejemplo n.º 2
0
 async def add_ui(self, source_id, ui):
     # print("Handling new user...")
     # Might as well make sure that we don't have other charts that are out of date.
     # So let's send an update to the existing charts first.
     await self.update_a()
     self.ui_tabs[source_id] = ui
     # "initialize" command sets chart range and page in addition to setting the chart.
     # "initialize" does a superset of what "reset" does.
     try:
         await ui.initializeSseq(js_JSON.parse(JSON.stringify(self.chart)))
     except Exception as e:
         console.log(e)
Ejemplo n.º 3
0
 def update_1(self):
     self.chart.update()
     s1 = JSON.stringify(self.chart)
     s2 = self.driver(
         """
         return JSON.stringify(globalThis.chart);
         """
     )
     c1 = json.loads(s1)
     del c1["version"]
     c2 = json.loads(s2)
     assert c1 == c2
Ejemplo n.º 4
0
@pytest.mark.parametrize("c", examples_list.values(), ids=examples_list.keys())
def test_js_python_serialization_agree(run_js, c):
    json1 = JSON.stringify(c)
    # print("json1:", json1)        
    json2 = run_js(f"return JSON.stringify(parse({json1}))")
    # print("json2:", json2)
    o1 = json.loads(json1)
    o2 = json.loads(json2)
    o2.pop("color_vec", None)
    assert o1 == o2




if __name__ == "__main__":
    state = StateMachinePythonToJavascript()
    v1 = state.add_class(k=(0, 0))
    # c = state.chart.classes[0]
    # c.background_color = Color.
    state.update_1()
    state.teardown()
    import pprint
    chart = SseqChart("a")
    chart.add_class(0,0)
    pprint.pprint(JSON.stringify(chart))





Ejemplo n.º 5
0
 async def update_charts_a(self, messages):
     messages = js_JSON.parse(JSON.stringify(messages))
     for ui in self.ui_tabs.values():
         await ui.appplyMessages(messages)
Ejemplo n.º 6
0
 async def load_a(self, path=None):
     if path:
         self.save_path = path
     self.set_sseq(JSON.parse(self.save_path.read_text()))
     await self.reset_state_a()
Ejemplo n.º 7
0
 def _create_message(cmd, **kwargs):
     return JSON.stringify(dict(cmd=cmd, args=[], kwargs=kwargs))
Ejemplo n.º 8
0
def double_serialize(o):
    s1 = JSON.stringify(o)
    s2 = JSON.stringify(JSON.parse(s1))
    return [s1, s2]
Ejemplo n.º 9
0
 def save(self):
     self.file_path.write_text(JSON.stringify(self.chart))
Ejemplo n.º 10
0
def serialize_parse(o):
    return JSON.parse(JSON.stringify(o))
Ejemplo n.º 11
0
 def update_1(self):
     self.chart.update()
     s1 = JSON.stringify(self.chart)
     s2 = JSON.stringify(self.other_chart)
     assert json.loads(s1) == json.loads(s2)
Ejemplo n.º 12
0
 def __init__(self):
     super().__init__()
     self.other_chart = JSON.parse(JSON.stringify(self.chart))
     self.chart.other_chart = self.other_chart
     self.chart.update = update_patch.__get__(self.chart)
Ejemplo n.º 13
0
 def double_serialize(self):
     s1 = JSON.stringify(self.chart)
     s2 = JSON.stringify(JSON.parse(s1))
     assert json.loads(s1) == json.loads(s2)
Ejemplo n.º 14
0
def update_patch(self):
    messages = self._batched_messages
    for msg in messages:
        self.other_chart.handle_message(json.loads(JSON.stringify(msg)))
    self._clear_batched_messages()