-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
624fa42
commit 1da63b4
Showing
48 changed files
with
2,953 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package: | ||
name: Jinja2 | ||
version: 3.1.2 | ||
tag: | ||
- core | ||
- min-scipy-stack | ||
top-level: | ||
- jinja2 | ||
requirements: | ||
run: | ||
- MarkupSafe | ||
source: | ||
sha256: 6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61 | ||
url: https://files.pythonhosted.org/packages/bc/c3/f068337a370801f372f2f8f6bad74a5c140f6fda3d9de154052708dd3c65/Jinja2-3.1.2-py3-none-any.whl | ||
about: | ||
home: https://palletsprojects.com/p/jinja/ | ||
PyPI: https://pypi.org/project/Jinja2 | ||
summary: A very fast and expressive template engine. | ||
license: BSD-3-Clause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pytest_pyodide import run_in_pyodide | ||
|
||
|
||
@run_in_pyodide(packages=["Jinja2"]) | ||
def test_jinja2(selenium): | ||
import jinja2 | ||
|
||
template = jinja2.Template("Hello {{ name }}!") | ||
content = template.render(name="Zach") | ||
assert content == "Hello Zach!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package: | ||
name: cpp-exceptions-test | ||
version: "0.1" | ||
tag: | ||
- core | ||
- pyodide.test | ||
- library | ||
source: | ||
path: src | ||
build: | ||
type: shared_library | ||
script: | | ||
em++ -c throw.cpp -o throw.o ${SIDE_MODULE_CFLAGS} -fexceptions -I${PYTHONINCLUDE} -flto -fno-lto | ||
em++ -c catch.cpp -o catch.o ${SIDE_MODULE_CFLAGS} -fexceptions -I${PYTHONINCLUDE} -flto -fno-lto | ||
em++ throw.o ${SIDE_MODULE_LDFLAGS} -o ${DISTDIR}/cpp-exceptions-test-throw.so -fexceptions | ||
em++ catch.o ${SIDE_MODULE_LDFLAGS} -o ${DISTDIR}/cpp-exceptions-test-catch.so -fexceptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <exception> | ||
using namespace std; | ||
#include <Python.h> | ||
#include <setjmp.h> | ||
#include <stdexcept> | ||
#include <stdio.h> | ||
|
||
extern "C" char* | ||
throw_exc(int x); | ||
|
||
extern "C" int | ||
call_pyobj(PyObject* x); | ||
|
||
extern "C" char* | ||
catch_exc(int x) | ||
{ | ||
char* msg; | ||
try { | ||
char* res = throw_exc(x); | ||
asprintf(&msg, "result was: %s", res); | ||
} catch (int param) { | ||
asprintf(&msg, "caught int %d", param); | ||
} catch (char param) { | ||
asprintf(&msg, "caught char %d", param); | ||
} catch (runtime_error& e) { | ||
asprintf(&msg, "caught runtime_error %s", e.what()); | ||
} catch (...) { | ||
asprintf(&msg, "caught ????"); | ||
} | ||
return msg; | ||
} | ||
|
||
extern "C" char* | ||
catch_call_pyobj(PyObject* x) | ||
{ | ||
char* msg; | ||
try { | ||
int res = call_pyobj(x); | ||
asprintf(&msg, "result was: %d", res); | ||
} catch (int param) { | ||
asprintf(&msg, "caught int %d", param); | ||
} catch (char param) { | ||
asprintf(&msg, "caught char %d", param); | ||
} catch (runtime_error& e) { | ||
asprintf(&msg, "caught runtime_error %s", e.what()); | ||
} catch (...) { | ||
asprintf(&msg, "caught ????"); | ||
} | ||
return msg; | ||
} | ||
|
||
jmp_buf my_jump_buffer; | ||
void | ||
longjmp_func(int status); | ||
|
||
extern "C" int | ||
set_jmp_func() | ||
{ | ||
int status = setjmp(my_jump_buffer); | ||
if (status == 0) { | ||
longjmp_func(4); | ||
} | ||
return status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <Python.h> | ||
#include <exception> | ||
#include <stdexcept> | ||
|
||
#include <setjmp.h> | ||
#include <stdnoreturn.h> | ||
|
||
jmp_buf my_jump_buffer; | ||
using namespace std; | ||
|
||
class myexception : public exception | ||
{ | ||
virtual const char* what() const throw() { return "My exception happened"; } | ||
} myex; | ||
|
||
extern "C" char* | ||
throw_exc(int x) | ||
{ | ||
if (x == 1) { | ||
throw 1000; | ||
} else if (x == 2) { | ||
throw 'c'; | ||
} else if (x == 3) { | ||
throw runtime_error("abc"); | ||
} else if (x == 4) { | ||
throw myex; | ||
} else { | ||
throw "abc"; | ||
} | ||
} | ||
|
||
extern "C" int | ||
call_pyobj(PyObject* x) | ||
{ | ||
PyObject* result = PyObject_CallNoArgs(x); | ||
int r = PyLong_AsLong(result); | ||
Py_DECREF(result); | ||
return r; | ||
} | ||
|
||
noreturn void | ||
longjmp_func(int status) | ||
{ | ||
longjmp(my_jump_buffer, status + 1); // will return status+1 out of setjmp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
def test_uncaught_cpp_exceptions(selenium): | ||
assert ( | ||
selenium.run_js( | ||
""" | ||
await pyodide.loadPackage("cpp-exceptions-test"); | ||
const Tests = pyodide._api.tests; | ||
const throwlib = pyodide._module.LDSO.loadedLibsByName["/usr/lib/cpp-exceptions-test-throw.so"].exports; | ||
function t(x){ | ||
try { | ||
throwlib.throw_exc(x); | ||
} catch(e){ | ||
let errString = Tests.convertCppException(e).toString(); | ||
errString = errString.replace(/[0-9]+/, "xxx"); | ||
return errString; | ||
} | ||
} | ||
return [t(1), t(2), t(3), t(4), t(5)]; | ||
""" | ||
) | ||
== [ | ||
"CppException int: The exception is an object of type int at address xxx " | ||
"which does not inherit from std::exception", | ||
"CppException char: The exception is an object of type char at address xxx " | ||
"which does not inherit from std::exception", | ||
"CppException std::runtime_error: abc", | ||
"CppException myexception: My exception happened", | ||
"CppException char const*: The exception is an object of type char const* at " | ||
"address xxx which does not inherit from std::exception", | ||
] | ||
) | ||
|
||
|
||
def test_cpp_exception_catching(selenium): | ||
assert ( | ||
selenium.run_js( | ||
""" | ||
await pyodide.loadPackage("cpp-exceptions-test"); | ||
const Module = pyodide._module; | ||
const catchlib = pyodide._module.LDSO.loadedLibsByName["/usr/lib/cpp-exceptions-test-catch.so"].exports; | ||
function t(x){ | ||
const ptr = catchlib.catch_exc(x); | ||
const res = Module.UTF8ToString(ptr); | ||
Module._free(ptr); | ||
return res; | ||
} | ||
return [t(1), t(2), t(3), t(5)]; | ||
""" | ||
) | ||
== [ | ||
"caught int 1000", | ||
"caught char 99", | ||
"caught runtime_error abc", | ||
"caught ????", | ||
] | ||
) | ||
|
||
|
||
def test_sjlj(selenium): | ||
assert ( | ||
( | ||
selenium.run_js( | ||
""" | ||
await pyodide.loadPackage("cpp-exceptions-test"); | ||
const Module = pyodide._module; | ||
const catchlib = pyodide._module.LDSO.loadedLibsByName["/usr/lib/cpp-exceptions-test-catch.so"].exports; | ||
return catchlib.set_jmp_func(); | ||
""" | ||
) | ||
) | ||
== 5 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package: | ||
name: distutils | ||
version: 1.0.0 # Nonsense | ||
tag: | ||
- always | ||
top-level: | ||
- distutils | ||
source: | ||
sha256: $(PYTHON_ARCHIVE_SHA256) | ||
url: $(PYTHON_ARCHIVE_URL) | ||
build: | ||
type: cpython_module | ||
script: | | ||
cd Lib && tar --exclude=__pycache__ --exclude=tests -cf - distutils | tar -C $DISTDIR -xf - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from pytest_pyodide import run_in_pyodide | ||
|
||
|
||
@run_in_pyodide(packages=["test", "distutils"], pytest_assert_rewrites=False) | ||
def test_distutils(selenium): | ||
import sys | ||
import unittest | ||
import unittest.mock | ||
from test import libregrtest # type:ignore[attr-defined] | ||
|
||
name = "test_distutils" | ||
|
||
ignore_tests = [ | ||
"test_check_environ_getpwuid", # no pwd | ||
"test_get_platform", # no _osx_support | ||
"test_simple_built", | ||
"test_optional_extension", # thread | ||
"test_customize_compiler_before_get_config_vars", # subprocess | ||
"test_spawn", # subprocess | ||
"test_debug_mode", # no _osx_support | ||
"test_record", # no _osx_support | ||
"test_get_config_h_filename", # /include/python3.10/pyconfig.h not exists | ||
"test_srcdir", # /lib/python3.10/config-3.10-wasm32-emscripten not exists | ||
"test_mkpath_with_custom_mode", | ||
"test_finalize_options", # no executable | ||
] | ||
|
||
sys.modules["_osx_support"] = unittest.mock.Mock() | ||
try: | ||
libregrtest.main([name], ignore_tests=ignore_tests, verbose=True, verbose3=True) | ||
except SystemExit as e: | ||
if e.code != 0: | ||
raise RuntimeError(f"Failed with code: {e.code}") from None |
Oops, something went wrong.