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
Add tests for serialization with internal ids forscript.evaluate
and script.callFunction
.
#36041
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
|
||
from ... import recursive_compare, any_string | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"return_structure, result_type", | ||
[ | ||
("[data, data]", "array"), | ||
("new Map([['foo', data],['bar', data]])", "map"), | ||
("({ 'foo': data, 'bar': data })", "object"), | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"expression, type", | ||
[ | ||
("[1]", "array"), | ||
("new Map([[true, false]])", "map"), | ||
("new Set(['baz'])", "set"), | ||
("{ baz: 'qux' }", "object"), | ||
], | ||
) | ||
async def test_remote_values_with_internal_id( | ||
call_function, return_structure, result_type, expression, type | ||
): | ||
result = await call_function( | ||
f"() => {{ const data = {expression}; return {return_structure}; }}" | ||
) | ||
|
||
if result_type == "array": | ||
value = [ | ||
{"type": type, "internalId": any_string}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to check one of the items actually have the value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
{"type": type, "internalId": any_string}, | ||
] | ||
else: | ||
value = [ | ||
["foo", {"type": type, "internalId": any_string}], | ||
["bar", {"type": type, "internalId": any_string}], | ||
] | ||
|
||
recursive_compare({"type": result_type, "value": value}, result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to check the return type here? It looks like comparing the value will enough. Can simplify the test, and check only the internal IDs, without data types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be removed from the parameters as well them |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
|
||
from ... import recursive_compare, any_string | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"return_structure, result_type", | ||
[ | ||
("[data, data]", "array"), | ||
("new Map([['foo', data],['bar', data]])", "map"), | ||
("({ 'foo': data, 'bar': data })", "object"), | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"expression, type", | ||
[ | ||
("[1]", "array"), | ||
("new Map([[true, false]])", "map"), | ||
("new Set(['baz'])", "set"), | ||
("{ baz: 'qux' }", "object"), | ||
], | ||
) | ||
async def test_remote_values_with_internal_id( | ||
evaluate, return_structure, result_type, expression, type | ||
): | ||
result = await evaluate(f"{{const data = {expression}; {return_structure}}}") | ||
|
||
if result_type == "array": | ||
value = [ | ||
{"type": type, "internalId": any_string}, | ||
{"type": type, "internalId": any_string}, | ||
] | ||
else: | ||
value = [ | ||
["foo", {"type": type, "internalId": any_string}], | ||
["bar", {"type": type, "internalId": any_string}], | ||
] | ||
|
||
recursive_compare({"type": result_type, "value": value}, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result_type
can be removed from here nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it's still used to build the value here: https://github.com/web-platform-tests/wpt/pull/36041/files#diff-609470bfe4f5bba1b3da43624062982a560723dbd8cf36af1b27cdab9a34194fR31