mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-23 12:12:59 -05:00
fix error management bug and improve examples automation (#717)
* add build to the make examples cmd so that it automates more to the user * temporarily improve error managament when executing eval until we properly refactor the whole io and error workflow * add minimal test for format_mime
This commit is contained in:
@@ -65,16 +65,17 @@ examples:
|
||||
find ./examples/toga -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../../build/+g {} \;
|
||||
find ./examples/webgl -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../../../build/+g {} \;
|
||||
find ./examples -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../build/+g {} \;
|
||||
npm run build
|
||||
cp -R ./build/ ./examples/build
|
||||
@echo "To serve examples run: $(conda_run) python -m http.server 8080 --directory examples"
|
||||
|
||||
test:
|
||||
make examples
|
||||
npm run build
|
||||
make test-ts
|
||||
make test-py
|
||||
|
||||
test-local:
|
||||
make examples
|
||||
npm run build
|
||||
pytest -vvs $(ARGS) tests/integration/ --log-cli-level=warning
|
||||
|
||||
test-py:
|
||||
|
||||
@@ -165,18 +165,28 @@ export class BaseEvalElement extends HTMLElement {
|
||||
|
||||
this.postEvaluate();
|
||||
} catch (err) {
|
||||
if (Element === undefined) {
|
||||
Element = <Element>runtime.globals.get('Element');
|
||||
console.error(err);
|
||||
try{
|
||||
if (Element === undefined) {
|
||||
Element = <Element>runtime.globals.get('Element');
|
||||
}
|
||||
const out = Element(this.errorElement.id);
|
||||
|
||||
addClasses(this.errorElement, ['bg-red-200', 'p-2']);
|
||||
out.write.callKwargs(err.toString(), { append: this.appendOutput });
|
||||
if (this.errorElement.children.length === 0){
|
||||
this.errorElement.setAttribute('error', '');
|
||||
}else{
|
||||
this.errorElement.children[this.errorElement.children.length - 1].setAttribute('error', '');
|
||||
}
|
||||
|
||||
this.errorElement.hidden = false;
|
||||
this.errorElement.style.display = 'block';
|
||||
this.errorElement.style.visibility = 'visible';
|
||||
} catch (internalErr){
|
||||
console.error("Unnable to write error to error element in page.")
|
||||
}
|
||||
const out = Element(this.errorElement.id);
|
||||
|
||||
addClasses(this.errorElement, ['bg-red-200', 'p-2']);
|
||||
out.write.callKwargs(err, { append: this.appendOutput });
|
||||
|
||||
this.errorElement.children[this.errorElement.children.length - 1].setAttribute('error', '');
|
||||
this.errorElement.hidden = false;
|
||||
this.errorElement.style.display = 'block';
|
||||
this.errorElement.style.visibility = 'visible';
|
||||
}
|
||||
} // end evaluate
|
||||
|
||||
|
||||
@@ -20,3 +20,11 @@ class TestElement:
|
||||
assert pyscript.document.querySelector.call_count == 1
|
||||
pyscript.document.querySelector.assert_called_with("#something")
|
||||
assert real_element == call_result
|
||||
|
||||
|
||||
def test_format_mime_str():
|
||||
obj = "just a string"
|
||||
|
||||
res = pyscript.format_mime(obj)
|
||||
assert res[0] == obj
|
||||
assert res[1] == "text/plain"
|
||||
|
||||
Reference in New Issue
Block a user