mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Bootstrap python tests (#697)
* move current integration tests to the integration folder * move pyscript.py into its own python folder * change the path for python unit testing files * change pyscript.py path * Update Makefile * remove echo * replace conda run with pytest directly * oops, add python test files I embarrassingly forgot to add Co-authored-by: Peter W <34256109+pww217@users.noreply.github.com>
This commit is contained in:
@@ -2,14 +2,15 @@ tag := latest
|
||||
git_hash ?= $(shell git log -1 --pretty=format:%h)
|
||||
|
||||
base_dir ?= $(shell git rev-parse --show-toplevel)
|
||||
src_dir ?= $(base_dir)/src
|
||||
src_dir ?= $(base_dir)/pyscriptjs/src
|
||||
examples ?= ../$(base_dir)/examples
|
||||
app_dir ?= $(shell git rev-parse --show-prefix)
|
||||
|
||||
CONDA_EXE := conda
|
||||
CONDA_ENV ?= ./env
|
||||
CONDA_ENV ?= $(base_dir)/pyscriptjs/env
|
||||
env := $(CONDA_ENV)
|
||||
conda_run := $(CONDA_EXE) run -p $(env)
|
||||
PYTEST_EXE := $(CONDA_ENV)/bin/pytest
|
||||
GOOD_NODE_VER := 14
|
||||
GOOD_NPM_VER := 6
|
||||
NODE_VER := $(shell node -v | cut -d. -f1 | sed 's/^v\(.*\)/\1/')
|
||||
@@ -74,11 +75,11 @@ test:
|
||||
test-local:
|
||||
make examples
|
||||
npm run build
|
||||
pytest -vvs $(ARGS) tests/ --log-cli-level=warning
|
||||
pytest -vvs $(ARGS) tests/integration/ --log-cli-level=warning
|
||||
|
||||
test-py:
|
||||
@echo "Tests are coming :( this is a placeholder and it's meant to fail!"
|
||||
$(conda_run) pytest -vv $(ARGS) tests/ --log-cli-level=warning
|
||||
@echo "Tests from $(src_dir)"
|
||||
$(PYTEST_EXE) -vv $(ARGS) tests/py-unit/ --log-cli-level=warning
|
||||
|
||||
test-ts:
|
||||
@echo "Tests are coming :( this is a placeholder and it's meant to fail!"
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { PyodideInterface } from './pyodide';
|
||||
|
||||
// eslint-disable-next-line
|
||||
// @ts-ignore
|
||||
import pyscript from './pyscript.py';
|
||||
import pyscript from './python/pyscript.py';
|
||||
|
||||
let pyodide: PyodideInterface;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import time
|
||||
import py
|
||||
import pytest
|
||||
|
||||
ROOT = py.path.local(__file__).dirpath("..", "..")
|
||||
ROOT = py.path.local(__file__).dirpath("..", "..", "..")
|
||||
BUILD = ROOT.join("pyscriptjs", "build")
|
||||
|
||||
|
||||
0
pyscriptjs/tests/py-unit/__init__.py
Normal file
0
pyscriptjs/tests/py-unit/__init__.py
Normal file
8
pyscriptjs/tests/py-unit/conftest.py
Normal file
8
pyscriptjs/tests/py-unit/conftest.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""All data required for testing examples"""
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
# current working directory
|
||||
base_path = pathlib.Path().absolute()
|
||||
python_source = base_path / "src" / "python"
|
||||
sys.path.append(str(python_source))
|
||||
5
pyscriptjs/tests/py-unit/js.py
Normal file
5
pyscriptjs/tests/py-unit/js.py
Normal file
@@ -0,0 +1,5 @@
|
||||
"""Mock module that emulates some of the pyodide js module features for the sake of tests"""
|
||||
from unittest.mock import Mock
|
||||
|
||||
document = Mock()
|
||||
console = Mock()
|
||||
4
pyscriptjs/tests/py-unit/micropip.py
Normal file
4
pyscriptjs/tests/py-unit/micropip.py
Normal file
@@ -0,0 +1,4 @@
|
||||
"""Mock module that emulates some of the pyodide js module features for the sake of tests"""
|
||||
from unittest.mock import Mock
|
||||
|
||||
install = Mock()
|
||||
22
pyscriptjs/tests/py-unit/test_pyscript.py
Normal file
22
pyscriptjs/tests/py-unit/test_pyscript.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pyscript
|
||||
|
||||
|
||||
class TestElement:
|
||||
def test_id_is_correct(self):
|
||||
el = pyscript.Element("something")
|
||||
assert el.id == "something"
|
||||
|
||||
def test_element(self, monkeypatch):
|
||||
el = pyscript.Element("something")
|
||||
document_mock = Mock()
|
||||
call_result = "some_result"
|
||||
document_mock.querySelector = Mock(return_value=call_result)
|
||||
monkeypatch.setattr(pyscript, "document", document_mock)
|
||||
assert not el._element
|
||||
real_element = el.element
|
||||
assert real_element
|
||||
assert pyscript.document.querySelector.call_count == 1
|
||||
pyscript.document.querySelector.assert_called_with("#something")
|
||||
assert real_element == call_result
|
||||
Reference in New Issue
Block a user