From c7682952ae85ee8ae94413c32fd8a24cca880c44 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Mon, 4 Dec 2023 13:37:18 -0800 Subject: [PATCH] Add tests --- src/tests/test_jsproxy.py | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/tests/test_jsproxy.py b/src/tests/test_jsproxy.py index f383e6d89f8..d0c2afca6d6 100644 --- a/src/tests/test_jsproxy.py +++ b/src/tests/test_jsproxy.py @@ -1774,6 +1774,47 @@ def test_jsarray_count(selenium): )(a) +@run_in_pyodide +def test_jsarray_remove(selenium): + import pytest + + from pyodide.code import run_js + from pyodide.ffi import create_proxy + + l = [5, 7, 9, -1, 3, 5] + a = run_js(repr(l)) + l.remove(5) + a.remove(5) + with pytest.raises(ValueError, match="is not in list"): + a.remove(78) + assert a.to_py() == l + l.append([]) # type:ignore[arg-type] + p = create_proxy([], roundtrip=False) + a.append(p) + assert a.to_py() == l + l.remove([]) # type:ignore[arg-type] + a.remove([]) + p.destroy() + assert a.to_py() == l + a.push([]) + with pytest.raises(ValueError, match="is not in list"): + a.remove([]) + + +@run_in_pyodide +def test_jsarray_insert(selenium): + from pyodide.code import run_js + + l = [5, 7, 9, -1, 3, 5] + a = run_js(repr(l)) + l.insert(3, 66) + a.insert(3, 66) + assert a.to_py() == l + l.insert(-1, 97) + a.insert(-1, 97) + assert a.to_py() == l + + @run_in_pyodide def test_jsproxy_descr_get(selenium): from pyodide.code import run_js