Skip to content

Commit

Permalink
Merge pull request #45 from DerThorsten/mocktime
Browse files Browse the repository at this point in the history
added time mock
  • Loading branch information
martinRenou authored Jul 6, 2023
2 parents 862cdd7 + 8ea350b commit 450aef7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ jobs:
run: |
micromamba activate pyjs-wasm
python -m pip install git+https://github.com/emscripten-forge/empack@rootpack --no-deps --ignore-installed
python -m pip install git+https://github.com/DerThorsten/pyjs-code-runner@relocate_env --no-deps --ignore-installed
emsdk activate ${{matrix.emsdk_ver}}
source $CONDA_EMSDK_DIR/emsdk_env.sh
Expand All @@ -59,7 +56,7 @@ jobs:
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
--yes \
python pybind11 nlohmann_json pybind11_json numpy pytest bzip2 sqlite zlib libffi
python pybind11 nlohmann_json pybind11_json numpy "pytest==7.1.1" bzip2 sqlite zlib libffi exceptiongroup
mkdir build
Expand Down Expand Up @@ -94,7 +91,7 @@ jobs:
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
--yes \
python pytest numpy
python "pytest==7.1.1" numpy exceptiongroup
- name: Test in browser-main
Expand Down Expand Up @@ -133,7 +130,7 @@ jobs:
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
--yes \
python pytest
python "pytest==7.1.1" exceptiongroup
- name: Test in browser-main-no-numpy
run: |
Expand Down
5 changes: 3 additions & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ dependencies:
- python=3.10
- yarn
- click
- empack >=3.0.1
- emsdk >=3.1.11
- empack >=1.1.0
- microsoft::playwright
- ninja
- nodejs >= 18.7.0
- pyjs_code_runner == 1.1.0
- pyjs_code_runner >= 2.0.1
- exceptiongroup
25 changes: 16 additions & 9 deletions include/pyjs/pre_js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,22 @@ _add_resolve_done_callback

Module._is_initialized = true

// Module.exec(`
// import sys
// import sysconfig
// side_path = "${side_path}"
// from pathlib import Path
// Path(side_path).mkdir(parents=True, exist_ok=True)
// if True and side_path not in sys.path:
// sys.path.append(side_path)
// `)
// make sure time.sleep is working
Module.exec(`
import time
def _mock_time_sleep():
def sleep(seconds):
"""Delay execution for a given number of seconds. The argument may be
a floating point number for subsecond precision.
"""
start = now = time.time()
while now - start < seconds:
now = time.time()
time.sleep = sleep
_mock_time_sleep()
del _mock_time_sleep
`)

return p

Expand Down
14 changes: 14 additions & 0 deletions tests/tests/test_pyjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,17 @@ def test_int_container():
js_obj = jsf()
py_obj = pyjs.to_py(js_obj)
assert py_obj



def test_sleep():
import time
start = time.time()
time.sleep(2)
end = time.time()

assert end - start >= 2

# probably we can also do more precise tests
# but lets keept it simple for now
assert end - start < 2.1

0 comments on commit 450aef7

Please sign in to comment.