mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 11:15:36 -05:00
examples inspector plugin (#1040)
* replace unnecessary elements from hello_world example and replace with py-tutor tag * add py_tutor plugin * port altair example * add code for more granular tutor mode * add support for including modules source in pytutor * remove js dependencies in hello_world * put antigravity on a diet ;) * use py-tutor on antigravity example * use py-tutor on d3 example * use py-tutor on bokeh example * use py-tutor on bokeh_interactive example * fix issue when module_paths is undefined * remove prism js dependency leftovers * ooops, really remove prism js dependency leftovers * port follium example to pytutor * port pymarkdown and matplotlib example to pytutor * port message_passing and numpy_convas_fractals examples to pytutor * port the panel complex examples to pytutor * port the panel complex examples to pytutor * port last examples to py-tutor * remove prism * remore most debugging logs and replace log with info * add new d3.py file * add comments to connect method * clean pyscript class from logs * revert class pySrc attribute * add check_tutor_generated_code to test code inspector plugin in examples * add doctsting to PyTutor connect * add check for tutor code inspection on all examples * Update pyscriptjs/src/plugins/python/py_tutor.py fix template indentation Co-authored-by: Fábio Rosado <fabioglrosado@gmail.com> * Update examples/todo-pylist.html fix typo (stray = ) Co-authored-by: Fábio Rosado <fabioglrosado@gmail.com> * fix pymarkdown example Co-authored-by: Fabio Pliger <fpliger@anaconda.com> Co-authored-by: Fábio Rosado <fabioglrosado@gmail.com>
This commit is contained in:
@@ -303,6 +303,72 @@ class PyScriptTest:
|
||||
text = "\n".join(loc.all_inner_texts())
|
||||
raise AssertionError(f"Found {n} alert banners:\n" + text)
|
||||
|
||||
def check_tutor_generated_code(self, modules_to_check=None):
|
||||
"""
|
||||
Ensure that the source code viewer injected by the PyTutor plugin
|
||||
is presend. Raise AssertionError if not found.
|
||||
|
||||
Args:
|
||||
|
||||
modules_to_check(str): iterable with names of the python modules
|
||||
that have been included in the tutor config
|
||||
and needs to be checked (if they are included
|
||||
in the displayed source code)
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
# Given: a page that has a <py-tutor> tag
|
||||
assert self.page.locator("py-tutor").count()
|
||||
|
||||
# EXPECT that"
|
||||
#
|
||||
# the page has the "view-code-button"
|
||||
view_code_button = self.page.locator("#view-code-button")
|
||||
vcb_count = view_code_button.count()
|
||||
if vcb_count != 1:
|
||||
raise AssertionError(
|
||||
f"Found {vcb_count} code view button. Should have been 1!"
|
||||
)
|
||||
|
||||
# the page has the code-section element
|
||||
code_section = self.page.locator("#code-section")
|
||||
code_section_count = code_section.count()
|
||||
code_msg = (
|
||||
f"One (and only one) code section should exist. Found: {code_section_count}"
|
||||
)
|
||||
assert code_section_count == 1, code_msg
|
||||
|
||||
pyconfig_tag = self.page.locator("py-config")
|
||||
code_section_inner_html = code_section.inner_html()
|
||||
|
||||
# the code_section has the index.html section
|
||||
assert "<p>index.html</p>" in code_section_inner_html
|
||||
|
||||
# the section has the tags highlighting the HTML code
|
||||
assert (
|
||||
'<pre class="prism-code language-html" tabindex="0">'
|
||||
' <code class="language-html">' in code_section_inner_html
|
||||
)
|
||||
|
||||
# if modules were included, these are also presented in the code section
|
||||
if modules_to_check:
|
||||
for module in modules_to_check:
|
||||
assert f"{module}" in code_section_inner_html
|
||||
|
||||
# the section also includes the config
|
||||
assert "<</span>py-config</span>" in code_section_inner_html
|
||||
|
||||
# the contents of the py-config tag are included in the code section
|
||||
assert pyconfig_tag.inner_html() in code_section_inner_html
|
||||
|
||||
# the code section to be invisible by default (by having the hidden class)
|
||||
assert "code-section-hidden" in code_section.get_attribute("class")
|
||||
|
||||
# once the view_code_button is pressed, the code section becomes visible
|
||||
view_code_button.click()
|
||||
assert "code-section-visible" in code_section.get_attribute("class")
|
||||
|
||||
|
||||
# ============== Helpers and utility functions ==============
|
||||
|
||||
|
||||
Reference in New Issue
Block a user