Skip to content

Commit

Permalink
fix wasm build and tests (#148)
Browse files Browse the repository at this point in the history
* try using pytest-speed as a substitute for pytest-benchmark for wasm builds

* error on pytest error

* install hypothesis, crash

* skip test that fails on wasm
  • Loading branch information
samuelcolvin authored Jul 5, 2022
1 parent f8bdfb6 commit 1ed0b6a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ jobs:
env:
PYODIDE_VERSION: '0.21.0-alpha.2'
PYTHON_VERSION: '3.10.2'
EMSCRIPTEN_VERSION: '3.1.14'
NODE_VERSION: 18
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ docs/_build/
tests/package.json
tests/package-lock.json
tests/node_modules
/.hypothesis/
.hypothesis/
21 changes: 0 additions & 21 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import importlib.util
import json
import os
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -89,23 +88,3 @@ def _import_execute(source: str, *, custom_module_name: str = None):
print('KeyboardInterrupt')

return _import_execute


if sys.platform == 'emscripten':
# we have to stub pytest-benchmark since it can't currently be used with webassembly/emscripten

@pytest.fixture
def benchmark():
def result(func, *args, **kwargs):
return func(*args, **kwargs)

return result

def pytest_configure(config):
config.addinivalue_line('markers', 'benchmark: pytest-benchmark stub, ignored')

def pytest_addoption(parser):
parser.addoption('--benchmark-columns', action='store', default='-', help='pytest-benchmark stub, ignored')
parser.addoption('--benchmark-group-by', action='store', default='-', help='pytest-benchmark stub, ignored')
parser.addoption('--benchmark-warmup', action='store', default='-', help='pytest-benchmark stub, ignored')
parser.addoption('--benchmark-disable', action='store_true', default='-', help='pytest-benchmark stub, ignored')
5 changes: 4 additions & 1 deletion tests/emscripten_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function setupStreams(FS, TTY){
async function main() {
const wheelName = await findWheel(distDir);
const wheelURL = `file:${distDir}/${wheelName}`;

let errcode = 0;
try {
pyodide = await loadPyodide();
const FS = pyodide.FS;
Expand All @@ -93,6 +93,8 @@ async function main() {
await pyodide.loadPackage(['micropip', 'pytest', 'pytz']);
const micropip = pyodide.pyimport('micropip');
await micropip.install('dirty-equals');
await micropip.install('hypothesis');
await micropip.install('pytest-speed');
await micropip.install(wheelURL);
const pytest = pyodide.pyimport('pytest');
FS.chdir("/test_dir");
Expand All @@ -101,6 +103,7 @@ async function main() {
console.error(e);
process.exit(1);
}
process.exit(errcode);
}

main();
2 changes: 2 additions & 0 deletions tests/test_hypothesis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import sys
from datetime import datetime, timezone
from typing import Optional

Expand All @@ -20,6 +21,7 @@ def test_datetime_datetime(datetime_schema, data):
assert datetime_schema.validate_python(data) == data


@pytest.mark.skipif(sys.platform == 'emscripten', reason='OverflowError, see pyodide/pyodide#2841')
@given(strategies.integers(min_value=-11_676_096_000, max_value=253_402_300_799_000))
def test_datetime_int(datetime_schema, data):
if abs(data) > 20_000_000_000:
Expand Down

0 comments on commit 1ed0b6a

Please sign in to comment.