123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import contextlib
- import time
- from urllib.request import urlopen
- import pytest
- from testbook import testbook
- @pytest.mark.filterwarnings("ignore::RuntimeWarning")
- @pytest.mark.teste2e
- @testbook("tests/gui/notebook/simple_gui.ipynb")
- def test_notebook_simple_gui(tb, helpers):
- tb.execute_cell("import")
- tb.execute_cell("page_declaration")
- tb.execute_cell("gui_init")
- tb.execute_cell("gui_run")
- while not helpers.port_check():
- time.sleep(0.1)
- assert ">Hello</h1>" in urlopen("http://127.0.0.1:5000/taipy-jsx/page1").read().decode("utf-8")
- assert 'defaultValue=\\"10\\"' in urlopen("http://127.0.0.1:5000/taipy-jsx/page1").read().decode("utf-8")
-
- tb.execute_cell("get_variable")
- assert "10" in tb.cell_output_text("get_variable")
- assert 'defaultValue=\\"10\\"' in urlopen("http://127.0.0.1:5000/taipy-jsx/page1").read().decode("utf-8")
- tb.execute_cell("set_variable")
- assert 'defaultValue=\\"20\\"' in urlopen("http://127.0.0.1:5000/taipy-jsx/page1").read().decode("utf-8")
- tb.execute_cell("re_get_variable")
- assert "20" in tb.cell_output_text("re_get_variable")
-
- tb.execute_cell("gui_stop")
- with pytest.raises(Exception) as exc_info:
- urlopen("http://127.0.0.1:5000/taipy-jsx/page1")
- assert "501: Gateway error" in str(exc_info.value)
- tb.execute_cell("gui_re_run")
- while True:
- with contextlib.suppress(Exception):
- urlopen("http://127.0.0.1:5000/taipy-jsx/page1")
- break
- assert ">Hello</h1>" in urlopen("http://127.0.0.1:5000/taipy-jsx/page1").read().decode("utf-8")
- tb.execute_cell("gui_reload")
- while True:
- with contextlib.suppress(Exception):
- urlopen("http://127.0.0.1:5000/taipy-jsx/page1")
- break
- assert ">Hello</h1>" in urlopen("http://127.0.0.1:5000/taipy-jsx/page1").read().decode("utf-8")
- tb.execute_cell("gui_re_stop")
- with pytest.raises(Exception) as exc_info:
- urlopen("http://127.0.0.1:5000/taipy-jsx/page1")
- assert "501: Gateway error" in str(exc_info.value)
|