mirror of
https://github.com/pyscript/pyscript.git
synced 2026-04-04 20:00:24 -04:00
TOML Error Cases (#815)
* TOML Error Cases * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove traceback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * any is a ts feature * full eslint * format and disable eslint for toml.js Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Madhur Tandon <madhurtandon23@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import tempfile
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from .support import PyScriptTest
|
||||
from .support import JsError, PyScriptTest
|
||||
|
||||
URL = "https://github.com/pyodide/pyodide/releases/download/0.20.0/pyodide-build-0.20.0.tar.bz2"
|
||||
TAR_NAME = "pyodide-build-0.20.0.tar.bz2"
|
||||
@@ -69,3 +69,30 @@ class TestRuntimeConfig(PyScriptTest):
|
||||
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="",
|
||||
extra_head="""
|
||||
<py-config type="json">
|
||||
[[
|
||||
</py-config>
|
||||
""",
|
||||
)
|
||||
|
||||
msg = str(exc.value)
|
||||
assert "SyntaxError" in msg
|
||||
|
||||
def test_invalid_toml_config(self):
|
||||
with pytest.raises(JsError) as exc:
|
||||
self.pyscript_run(
|
||||
snippet="",
|
||||
extra_head="""
|
||||
<py-config>
|
||||
[[
|
||||
</py-config>
|
||||
""",
|
||||
)
|
||||
msg = str(exc)
|
||||
assert "<ExceptionInfo JsError" in msg
|
||||
|
||||
@@ -130,6 +130,17 @@ describe('PyConfig', () => {
|
||||
instance.connectedCallback();
|
||||
});
|
||||
|
||||
it('should error out when passing an invalid JSON', () => {
|
||||
instance.setAttribute('type', 'json');
|
||||
instance.innerHTML = '[[';
|
||||
expect(()=>instance.connectedCallback()).toThrow(SyntaxError);
|
||||
});
|
||||
|
||||
it('should error out when passing an invalid TOML', () => {
|
||||
instance.innerHTML = '[[';
|
||||
expect(()=>instance.connectedCallback()).toThrow(SyntaxError);
|
||||
});
|
||||
|
||||
it('connectedCallback should call loadRuntimes', async () => {
|
||||
const mockedMethod = jest.fn();
|
||||
instance.loadRuntimes = mockedMethod;
|
||||
@@ -142,12 +153,12 @@ describe('PyConfig', () => {
|
||||
it('confirm connectedCallback happy path', async () => {
|
||||
const mockedMethod = jest.fn();
|
||||
instance.loadRuntimes = mockedMethod;
|
||||
instance.innerHTML = 'test';
|
||||
instance.innerHTML = 'test = 42';
|
||||
|
||||
instance.connectedCallback();
|
||||
|
||||
expect(instance.code).toBe('test');
|
||||
expect(instance.values['0']).toBe('test');
|
||||
expect(instance.code).toBe('test = 42');
|
||||
expect(instance.values['test']).toBe(42);
|
||||
});
|
||||
|
||||
it('log should add new message to the page', async () => {
|
||||
|
||||
Reference in New Issue
Block a user