Repository: pyscript/pyscript
File: pyscriptjs/tests/integration/test_py_config.py (Python)

Code before:
            js.console.log("config name:", config.name)
        </py-script>
        """
        )
        assert self.console.log.lines[-1] == "config name: app with external config"

    # The default pyodide version is 0.21.2 as of writing
    # this test which is newer than the one we are loading below
    # (after downloading locally) -- which is 0.20.0

    # The test checks if loading a different runtime is possible
    # and that too from a locally downloaded file without needing
    # the use of explicit `indexURL` calculation.
    def test_runtime_config(self, tar_location):
        unzip(
            location=tar_location,
            extract_to=self.tmpdir,
        )

        self.pyscript_run(
            """
            <py-config type="json">
                {
                    "runtimes": [{
                        "src": "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js",
                        "name": "pyodide-0.21.3",
                        "lang": "python"
                    }]
                }
            </py-config>

            <py-script>
                import sys, js
                pyodide_version = sys.modules["pyodide"].__version__
                js.console.log("version", pyodide_version)
                pyodide_version
            </py-script>
        """,
        )

        assert self.console.log.lines == [self.PY_COMPLETE, "version 0.21.3"]
        version = self.page.locator("py-script").inner_text()
        assert version == "0.21.3"

    def test_invalid_json_config(self):
        with pytest.raises(JsError) as exc:
            self.pyscript_run(
                snippet="""
                <py-config type="json">
                    [[
                </py-config>

Review comment (refactor):
@tedpatrick IMO, we shouldn't remove this test. The reason is that we want to check if passing a runtime from a local path works instead of a hosted one. This is useful when you have the pyodide distribution downloaded and are without an internet access.

Here, we check for `0.20` as another sanity check, to check if indeed the local and correct one is loaded since the default was `0.21.2`


Code after:
            js.console.log("config name:", config.name)
        </py-script>
        """
        )
        assert self.console.log.lines[-1] == "config name: app with external config"

    # The default pyodide version is 0.21.2 as of writing
    # this test which is newer than the one we are loading below
    # (after downloading locally) -- which is 0.20.0

    # The test checks if loading a different runtime is possible
    # and that too from a locally downloaded file without needing
    # the use of explicit `indexURL` calculation.
    def test_runtime_config(self, tar_location):
        unzip(
            location=tar_location,
            extract_to=self.tmpdir,
        )

        self.pyscript_run(
            """
            <py-config type="json">
                {
                    "runtimes": [{
                        "src": "/pyodide/pyodide.js",
                        "name": "pyodide-0.20.0",
                        "lang": "python"
                    }]
                }
            </py-config>

            <py-script>
                import sys, js
                pyodide_version = sys.modules["pyodide"].__version__
                js.console.log("version", pyodide_version)
                pyodide_version
            </py-script>
        """,
        )

        assert self.console.log.lines == [self.PY_COMPLETE, "version 0.20.0"]
        version = self.page.locator("py-script").inner_text()
        assert version == "0.20.0"

    def test_invalid_json_config(self):
        with pytest.raises(JsError) as exc:
            self.pyscript_run(
                snippet="""
                <py-config type="json">
                    [[
                </py-config>