-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bootstrap python tests #697
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b8bb93a
move current integration tests to the integration folder
fpliger 14d0d67
move pyscript.py into its own python folder
fpliger 7048159
change the path for python unit testing files
fpliger b679434
change pyscript.py path
fpliger 2eff6df
Update Makefile
pww217 4f32c3f
remove echo
fpliger ceee05b
Merge branch 'fpliger/663_bootstrap_py_tests_2' of github.com:anacond…
fpliger 186b7e1
replace conda run with pytest directly
fpliger 644a1b4
oops, add python test files I embarrassingly forgot to add
fpliger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
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,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)) |
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,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() | ||
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,4 @@ | ||
"""Mock module that emulates some of the pyodide js module features for the sake of tests""" | ||
from unittest.mock import Mock | ||
|
||
install = Mock() |
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,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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this code is for (same for the
micropip.py
file).The other parts of tests we're using
console
are here for example:But it's not using this object, as far as I understand.
Can you please explain it?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are fixtures for the the apis that are
pyodide
specific. Thetests/integration
tests run a web server that actually run the code inpyodide
while the python tests are actually running python unit tests in localpython
. So thejs
andmicropip
modules are not there. We can potentially think of running the tests inpyodide
at some point but even then, I think it makes sense for us to mock their API to make sure that we are calling them correctly...In general, we'll be supporting other runtimes that are not
pyodide
so I think that it's important that we decouple our Python higher level API and test the interface itself.Makes sense?
(given your comment, I think it actually makes sense for us to put
js.py
andmicropip.py
in afixtures
folder but we can do it in a separate follow up PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes total sense =)
Thanks for the explanation.