async def test_update_model_simulataneous(mocker): schema = {"type": "object", "properties": {"text": {"type": "string"}}} model = Model("test_model", schema) # This callback will only receive the first argument, the model. cb = mocker.MagicMock() model.register_callback(cb) model.update_model({"text": "hi"}) model.update_model({"text": "bye"}) await asyncio.sleep(0.01) assert cb.call_args_list[0].args[0]["text"] == "hi" assert cb.call_args_list[1].args[0]["text"] == "bye"
async def test_model_update_dict(): schema = """ { "type": "object", "properties": { "prop": { "type": "object" } } } """ model = Model("test_model", schema) model.update_model({"prop": {"subprop1": 1, "subprop2": 2}}) assert model["prop"].value == {"subprop1": 1, "subprop2": 2} assert model["prop"].last_seen is not None assert model.last_seen is not None model.update_model({"prop": {"subprop2": 5}}) assert model["prop"].value == {"subprop1": 1, "subprop2": 5}