Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare dicts not JSON string with dicts #63

Merged
merged 2 commits into from
Feb 20, 2023

Conversation

bnavigator
Copy link
Contributor

@bnavigator bnavigator commented Feb 5, 2023

The test fails for me otherwise. YArray().to_json() produces a string, which cannot be compared to a list of dicts or dict.

[    6s] =================================== FAILURES ===================================
[    6s] ______________________________ test_ypy_yjs_1[1] _______________________________
[    6s] 
[    6s] yws_server = <ypy_websocket.websocket_server.WebsocketServer object at 0x7f97d5a6eb20>
[    6s] yjs_client = <subprocess.Popen object at 0x7f97d5ac3e50>
[    6s] 
[    6s]     @pytest.mark.asyncio
[    6s]     @pytest.mark.parametrize("yjs_client", "1", indirect=True)
[    6s]     async def test_ypy_yjs_1(yws_server, yjs_client):
[    6s]         # wait for the JS client to connect
[    6s]         tt, dt = 0, 0.1
[    6s]         while True:
[    6s]             await asyncio.sleep(dt)
[    6s]             if "/my-roomname" in yws_server.rooms:
[    6s]                 break
[    6s]             tt += dt
[    6s]             if tt >= 1:
[    6s]                 raise RuntimeError("Timeout waiting for client to connect")
[    6s]         ydoc = yws_server.rooms["/my-roomname"].ydoc
[    6s]         ytest = YTest(ydoc)
[    6s]         ytest.run_clock()
[    6s]         await ytest.clock_run()
[    6s]         ycells = ydoc.get_array("cells")
[    6s]         ystate = ydoc.get_map("state")
[    6s] >       assert ycells.to_json() == [{"metadata": {"foo": "bar"}, "source": "1 + 2"}]
[    6s] E       assert '[{"source":"1 + 2","metadata":{"foo":"bar"}}]' == [{'metadata': {'foo': 'bar'}, 'source': '1 + 2'}]
[    6s] E        +  where '[{"source":"1 + 2","metadata":{"foo":"bar"}}]' = <built-in method to_json of builtins.YArray object at 0x7f97d59c15b0>()
[    6s] E        +    where <built-in method to_json of builtins.YArray object at 0x7f97d59c15b0> = YArray([{'metadata': {'foo': 'bar'}, 'source': '1 + 2'}]).to_json
[    6s] 
[    6s] tests/test_ypy_yjs.py:73: AssertionError

Note that comparing the .to_json() output to a hardcoded string literal fails unpredictably because the dict key order is not stable.

@bnavigator bnavigator changed the title Compare dicts not not JSON string with dicts Compare dicts not JSON string with dicts Feb 5, 2023
@davidbrochart
Copy link
Collaborator

Maybe because you're working from the main branch? y-crdt/ypy#102 has not been released yet.

@bnavigator
Copy link
Contributor Author

Dang, you are right! I accidentally packaged the main branch of y-py instead of 0.5.5

Ok, so you'll have this PR for the next release with y-py 0.6 as dependency, I guess.

@davidbrochart davidbrochart merged commit 5aaf6c9 into y-crdt:main Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants