text stringlengths 0 105k |
|---|
import pathlib import tempfile from taipy.gui import Gui from taipy.gui.utils import _get_non_existent_file_path def test_empty_file_name(gui: Gui, helpers): assert _get_non_existent_file_path(pathlib.Path(tempfile.gettempdir()), "").name def test_non_existent_file(gui: Gui, helpers): assert not _get_non_existent_file_path(pathlib.Path(tempfile.gettempdir()), "").exists() def test_existent_file(gui: Gui, helpers): file_path = _get_non_existent_file_path(pathlib.Path(tempfile.gettempdir()), "") with open(file_path, "w") as file_handler: file_handler.write("hello") assert file_path.exists() file_stem = file_path.stem.split(".", 1)[0] file_suffix = file_path.suffixes[-1] index = int(file_path.suffixes[0][1:]) if len(file_path.suffixes) > 1 else -1 file_path = _get_non_existent_file_path(pathlib.Path(tempfile.gettempdir()), "") assert file_path.name == f"{file_stem}.{index + 1}{file_suffix}" with open(file_path, "w") as file_handler: file_handler.write("hello 2") assert file_path.exists() file_path = _get_non_existent_file_path(pathlib.Path(tempfile.gettempdir()), "") assert file_path.name == f"{file_stem}.{index + 2}{file_suffix}" |
import warnings import pytest from taipy.gui.utils.date import _string_to_date from taipy.gui.utils.types import _TaipyBase, _TaipyBool, _TaipyDate, _TaipyNumber def test_taipy_base(): tb = _TaipyBase("value", "hash") assert tb.get() == "value" assert tb.get_name() == "hash" tb.set("a value") assert tb.get() == "a value" assert tb.get_hash() == NotImplementedError def test_taipy_bool(): assert _TaipyBool(0, "v").get() is False assert _TaipyBool(1, "v").get() is True assert _TaipyBool(False, "v").get() is False assert _TaipyBool(True, "v").get() is True assert _TaipyBool("", "v").get() is False assert _TaipyBool("hey", "v").get() is True assert _TaipyBool([], "v").get() is False assert _TaipyBool(["an item"], "v").get() is True def test_taipy_number(): with pytest.raises(TypeError): _TaipyNumber("a string", "x").get() with warnings.catch_warnings(record=True): _TaipyNumber("a string", "x").cast_value("a string") _TaipyNumber(0, "x").cast_value(0) def test_taipy_date(): assert _TaipyDate(_string_to_date("2022-03-03 00:00:00 UTC"), "x").get() == "2022-03-03T00:00:00+00:00" assert _TaipyDate("2022-03-03 00:00:00 UTC", "x").get() == "2022-03-03 00:00:00 UTC" assert _TaipyDate(None, "x").get() is None _TaipyDate("", "x").cast_value("2022-03-03 00:00:00 UTC") _TaipyDate("", "x").cast_value(_string_to_date("2022-03-03 00:00:00 UTC")) |
import inspect from time import sleep import pytest from taipy.gui import Gui, State, invoke_long_callback def test_long_callback(gui: Gui): status = None # noqa: F841 def heavy_function(delay=1): sleep(delay) def heavy_function_with_exception(delay=1): sleep(delay) raise Exception("Heavy function Exception") def heavy_function_status(state: State, status: int): state.status = status def on_exception(state: State, function_name: str, e: Exception): state.status = -1 gui._set_frame(inspect.currentframe()) gui.run(run_server=False, single_client=True) state = gui._Gui__state with gui.get_flask_app().app_context(): assert state.status is None invoke_long_callback(state, heavy_function) invoke_long_callback(state, heavy_function_with_exception) invoke_long_callback(state, heavy_function, (), heavy_function_status) invoke_long_callback(state, heavy_function, (2), heavy_function_status, (), 1000) invoke_long_callback(state, heavy_function_with_exception, (), heavy_function_status) |
import inspect from flask import g from taipy.gui import Gui, Markdown, get_state_id def test_get_state_id(gui: Gui, helpers): name = "World!" # noqa: F841 btn_id = "button1" # noqa: F841 # set gui frame gui._set_frame(inspect.currentframe()) gui.add_page("test", Markdown("<|Hello {name}|button|id={btn_id}|>")) gui.run(run_server=False) flask_client = gui._server.test_client() cid = helpers.create_scope_and_get_sid(gui) # Get the jsx once so that the page will be evaluated -> variable will be registered flask_client.get(f"/taipy-jsx/test?client_id={cid}") with gui.get_flask_app().app_context(): g.client_id = cid assert cid == get_state_id(gui._Gui__state) |
import inspect from flask import g from taipy.gui import Gui, Markdown, State, download def test_download(gui: Gui, helpers): name = "World!" # noqa: F841 btn_id = "button1" # noqa: F841 def on_download_action(state: State): pass # set gui frame gui._set_frame(inspect.currentframe()) gui.add_page("test", Markdown("<|Hello {name}|button|id={btn_id}|>")) gui.run(run_server=False) flask_client = gui._server.test_client() # WS client and emit ws_client = gui._server._ws.test_client(gui._server.get_flask()) cid = helpers.create_scope_and_get_sid(gui) # Get the jsx once so that the page will be evaluated -> variable will be registered flask_client.get(f"/taipy-jsx/test?client_id={cid}") with gui.get_flask_app().test_request_context(f"/taipy-jsx/test/?client_id={cid}", data={"client_id": cid}): g.client_id = cid download(gui._Gui__state, "some text", "filename.txt", "on_download_action") received_messages = ws_client.get_received() helpers.assert_outward_ws_simple_message( received_messages[0], "DF", {"name": "filename.txt", "onAction": "on_download_action"} ) |
import inspect from flask import g from taipy.gui import Gui, Markdown, navigate def test_navigate(gui: Gui, helpers): name = "World!" # noqa: F841 btn_id = "button1" # noqa: F841 # set gui frame gui._set_frame(inspect.currentframe()) gui.add_page("test", Markdown("<|Hello {name}|button|id={btn_id}|>")) gui.run(run_server=False) flask_client = gui._server.test_client() # WS client and emit ws_client = gui._server._ws.test_client(gui._server.get_flask()) cid = helpers.create_scope_and_get_sid(gui) # Get the jsx once so that the page will be evaluated -> variable will be registered flask_client.get(f"/taipy-jsx/test?client_id={cid}") with gui.get_flask_app().test_request_context(f"/taipy-jsx/test/?client_id={cid}", data={"client_id": cid}): g.client_id = cid navigate(gui._Gui__state, "test") received_messages = ws_client.get_received() helpers.assert_outward_ws_simple_message(received_messages[0], "NA", {"to": "test"}) |
import inspect from flask import g from taipy.gui import Gui, Markdown, State, invoke_callback def test_invoke_callback(gui: Gui, helpers): name = "World!" # noqa: F841 btn_id = "button1" # noqa: F841 val = 1 # noqa: F841 def user_callback(state: State): state.val = 10 # set gui frame gui._set_frame(inspect.currentframe()) gui.add_page("test", Markdown("<|Hello {name}|button|id={btn_id}|>\n<|{val}|>")) gui.run(run_server=False, single_client=True) flask_client = gui._server.test_client() # client id cid = helpers.create_scope_and_get_sid(gui) # Get the jsx once so that the page will be evaluated -> variable will be registered flask_client.get(f"/taipy-jsx/test?client_id={cid}") with gui.get_flask_app().app_context(): g.client_id = cid invoke_callback(gui, cid, user_callback, []) assert gui._Gui__state.val == 10 |
import inspect from flask import g from taipy.gui import Gui, Markdown, hold_control def test_hold_control(gui: Gui, helpers): name = "World!" # noqa: F841 btn_id = "button1" # noqa: F841 # set gui frame gui._set_frame(inspect.currentframe()) gui.add_page("test", Markdown("<|Hello {name}|button|id={btn_id}|>")) gui.run(run_server=False) flask_client = gui._server.test_client() # WS client and emit ws_client = gui._server._ws.test_client(gui._server.get_flask()) cid = helpers.create_scope_and_get_sid(gui) # Get the jsx once so that the page will be evaluated -> variable will be registered flask_client.get(f"/taipy-jsx/test?client_id={cid}") with gui.get_flask_app().test_request_context(f"/taipy-jsx/test/?client_id={cid}", data={"client_id": cid}): g.client_id = cid hold_control(gui._Gui__state) received_messages = ws_client.get_received() helpers.assert_outward_ws_simple_message( received_messages[0], "BL", {"action": "_taipy_on_cancel_block_ui", "message": "Work in Progress..."} ) |
import inspect from flask import g from taipy.gui import Gui, Markdown, resume_control def test_resume_control(gui: Gui, helpers): name = "World!" # noqa: F841 btn_id = "button1" # noqa: F841 # set gui frame gui._set_frame(inspect.currentframe()) gui.add_page("test", Markdown("<|Hello {name}|button|id={btn_id}|>")) gui.run(run_server=False) flask_client = gui._server.test_client() # WS client and emit ws_client = gui._server._ws.test_client(gui._server.get_flask()) cid = helpers.create_scope_and_get_sid(gui) # Get the jsx once so that the page will be evaluated -> variable will be registered flask_client.get(f"/taipy-jsx/test?client_id={cid}") with gui.get_flask_app().test_request_context(f"/taipy-jsx/test/?client_id={cid}", data={"client_id": cid}): g.client_id = cid resume_control(gui._Gui__state) received_messages = ws_client.get_received() helpers.assert_outward_ws_simple_message(received_messages[0], "BL", {"message": None}) |
import inspect from flask import g from taipy.gui import Gui, Markdown, notify def test_notify(gui: Gui, helpers): name = "World!" # noqa: F841 btn_id = "button1" # noqa: F841 # set gui frame gui._set_frame(inspect.currentframe()) gui.add_page("test", Markdown("<|Hello {name}|button|id={btn_id}|>")) gui.run(run_server=False) flask_client = gui._server.test_client() # WS client and emit ws_client = gui._server._ws.test_client(gui._server.get_flask()) cid = helpers.create_scope_and_get_sid(gui) # Get the jsx once so that the page will be evaluated -> variable will be registered flask_client.get(f"/taipy-jsx/test?client_id={cid}") with gui.get_flask_app().test_request_context(f"/taipy-jsx/test/?client_id={cid}", data={"client_id": cid}): g.client_id = cid notify(gui._Gui__state, "Info", "Message") received_messages = ws_client.get_received() helpers.assert_outward_ws_simple_message(received_messages[0], "AL", {"atype": "Info", "message": "Message"}) |
import contextlib import time from urllib.request import urlopen import pytest from testbook import testbook @pytest.mark.filterwarnings("ignore::RuntimeWarning") @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") # Test state manipulation within notebook 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") # Test page reload 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) |
from taipy.gui import Gui, Markdown |
import inspect from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_redirect(page: "Page", gui: Gui, helpers): page_md = """ <|Redirect Successfully|id=text1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./") page.expect_websocket() page.wait_for_selector("#text1") text1 = page.query_selector("#text1") assert text1.inner_text() == "Redirect Successfully" |
import pytest @pytest.fixture(scope="session") def browser_context_args(browser_context_args, e2e_port, e2e_base_url): return { **browser_context_args, "base_url": f"http://127.0.0.1:{e2e_port}{e2e_base_url}", "timezone_id": "Europe/Paris", } @pytest.fixture(scope="function") def gui(helpers, e2e_base_url): from taipy.gui import Gui gui = Gui() gui.load_config({"base_url": e2e_base_url, "host": "0.0.0.0" if e2e_base_url != "/" else "127.0.0.1"}) yield gui # Delete Gui instance and state of some classes after each test gui.stop() helpers.test_cleanup() |
import inspect import re from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from playwright.sync_api import expect from taipy.gui import Gui @pytest.mark.teste2e def test_navbar_navigate(page: "Page", gui: Gui, helpers): gui._set_frame(inspect.currentframe()) gui.add_page(name="Data", page="<|navbar|id=nav1|> <|Data|id=text-data|>") gui.add_page(name="Test", page="<|navbar|id=nav1|> <|Test|id=text-test|>") helpers.run_e2e(gui) page.goto("./Data") page.expect_websocket() page.wait_for_selector("#text-data") page.click("#nav1 button:nth-child(2)") page.wait_for_selector("#text-test") expect(page).to_have_url(re.compile(".*Test")) page.click("#nav1 button:nth-child(1)") page.wait_for_selector("#text-data") expect(page).to_have_url(re.compile(".*Data")) |
import inspect from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui from taipy.gui.utils.date import _string_to_date @pytest.mark.teste2e def test_timzone_specified_1(page: "Page", gui: Gui, helpers): _timezone_test_template(page, gui, helpers, "Etc/GMT", ["2022-03-03 00:00:00 UTC"]) @pytest.mark.teste2e def test_timzone_specified_2(page: "Page", gui: Gui, helpers): _timezone_test_template( page, gui, helpers, "Europe/Paris", ["2022-03-03 01:00:00 GMT+1", "2022-03-03 01:00:00 UTC+1"] ) @pytest.mark.teste2e def test_timzone_specified_3(page: "Page", gui: Gui, helpers): _timezone_test_template( page, gui, helpers, "Asia/Ho_Chi_Minh", ["2022-03-03 07:00:00 GMT+7", "2022-03-03 07:00:00 UTC+7"] ) @pytest.mark.teste2e def test_timzone_specified_4(page: "Page", gui: Gui, helpers): _timezone_test_template( page, gui, helpers, "America/Sao_Paulo", ["2022-03-02 21:00:00 GMT-3", "2022-03-02 21:00:00 UTC−3"] ) @pytest.mark.teste2e def test_timezone_client_side(page: "Page", gui: Gui, helpers): _timezone_test_template(page, gui, helpers, "client", ["2022-03-03 01:00:00 GMT+1", "2022-03-03 01:00:00 UTC+1"]) def _timezone_test_template(page: "Page", gui: Gui, helpers, time_zone, texts): page_md = """ <|{t}|id=text1|> """ t = _string_to_date("2022-03-03T00:00:00.000Z") # noqa: F841 gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui, time_zone=time_zone) page.goto("./test") page.expect_websocket() page.wait_for_selector("#text1") text1 = page.query_selector("#text1") assert text1.inner_text() in texts def test_date_only(page: "Page", gui: Gui, helpers): page_md = """ <|{t}|id=text1|> """ t = _string_to_date("Wed Jul 28 1993") # noqa: F841 gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./test") page.expect_websocket() page.wait_for_selector("#text1") text1 = page.query_selector("#text1") assert text1.inner_text() in ["1993-07-28"] |
import inspect from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_accessor_json(page: "Page", gui: Gui, csvdata, helpers): table_data = csvdata # noqa: F841 gui._set_frame(inspect.currentframe()) gui.add_page( name="test", page="<|{table_data}|table|columns=Day;Entity;Code;Daily hospital occupancy|date_format=eee dd MMM yyyy|id=table1|>", ) helpers.run_e2e(gui, use_arrow=False) page.goto("./test") page.expect_websocket() page.wait_for_selector("#table1 tr:nth-child(32)") # wait for data to be loaded (30 rows of skeleton while loading) assert_table_content(page) @pytest.mark.teste2e def test_accessor_arrow(page: "Page", gui: Gui, csvdata, helpers): if util.find_spec("pyarrow"): table_data = csvdata # noqa: F841 gui._set_frame(inspect.currentframe()) gui.add_page( name="test", page="<|{table_data}|table|columns=Day;Entity;Code;Daily hospital occupancy|date_format=eee dd MMM yyyy|id=table1|>", ) helpers.run_e2e(gui, use_arrow=True) page.goto("./test") page.expect_websocket() page.wait_for_selector( "#table1 tr:nth-child(32)" ) # wait for data to be loaded (30 rows of skeleton while loading) assert_table_content(page) def assert_table_content(page: "Page"): # assert page.query_selector("#table1 tbody tr:nth-child(1) td:nth-child(1)").inner_text() == "Wed 01 Apr 2020" assert page.query_selector("#table1 tbody tr:nth-child(1) td:nth-child(2)").inner_text() == "Austria" assert page.query_selector("#table1 tbody tr:nth-child(1) td:nth-child(4)").inner_text() == "856" |
import inspect from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_theme_light(page: "Page", gui: Gui, helpers): page_md = """ <|Just a page|id=text1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui, dark_mode=False) page.goto("./") page.expect_websocket() page.wait_for_selector("#text1") background_color = page.evaluate( 'window.getComputedStyle(document.querySelector("main"), null).getPropertyValue("background-color")' ) assert background_color == "rgb(255, 255, 255)" @pytest.mark.teste2e def test_theme_dark(page: "Page", gui: Gui, helpers): page_md = """ <|Just a page|id=text1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui, dark_mode=True) page.goto("./") page.expect_websocket() page.wait_for_selector("#text1") background_color = page.evaluate( 'window.getComputedStyle(document.querySelector("main"), null).getPropertyValue("background-color")' ) assert background_color == "rgb(18, 18, 18)" |
import inspect from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_margin_1(page: "Page", gui: Gui, helpers): page_md = """ <|Just a page|id=text1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui, dark_mode=False, margin="10rem") page.goto("./") page.expect_websocket() page.wait_for_selector("#text1") margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")') assert margin == "160px" @pytest.mark.teste2e def test_margin_2(page: "Page", gui: Gui, helpers): page_md = """ <|Just a page|id=text1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui, dark_mode=False) page.goto("./") page.expect_websocket() page.wait_for_selector("#text1") margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")') assert margin == "16px" @pytest.mark.teste2e def test_margin_3(page: "Page", gui: Gui, helpers): page_md = """ <|Just a page|id=text1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui, dark_mode=False, margin="10rem", stylekit=True) page.goto("./") page.expect_websocket() page.wait_for_selector("#text1") margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")') assert margin == "160px" @pytest.mark.teste2e def test_margin_4(page: "Page", gui: Gui, helpers): page_md = """ <|Just a page|id=text1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui, dark_mode=False, stylekit={"root_margin": "20rem"}) page.goto("./") page.expect_websocket() page.wait_for_selector("#text1") margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")') assert margin == "320px" @pytest.mark.teste2e def test_margin_5(page: "Page", gui: Gui, helpers): page_md = """ <|Just a page|id=text1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui, dark_mode=False, stylekit={"root_margin": "20rem"}, margin="10rem") page.goto("./") page.expect_websocket() page.wait_for_selector("#text1") margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")') assert margin == "320px" |
import inspect import os import time from importlib import util from pathlib import Path from urllib.request import urlopen import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui, Html from taipy.gui.server import _Server @pytest.mark.teste2e def test_html_render_with_style(page: "Page", gui: Gui, helpers): html_content = """<!DOCTYPE html> <html lang="en"> <head> <style> .taipy-text { color: green; } .custom-text { color: blue; } </style> </head> <body> <taipy:text id="text1">Hey</taipy:text> <taipy:text id="text2" class="custom-text">There</taipy:text> </body> </html>""" gui._set_frame(inspect.currentframe()) gui.add_page("page1", Html(html_content)) helpers.run_e2e(gui) page.goto("./page1") page.expect_websocket() page.wait_for_selector("#text1") retry = 0 while ( retry < 10 and page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")') != "rgb(0, 128, 0)" ): retry += 1 time.sleep(0.2) assert ( page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")') == "rgb(0, 128, 0)" ) assert ( page.evaluate('window.getComputedStyle(document.querySelector("#text2"), null).getPropertyValue("color")') == "rgb(0, 0, 255)" ) @pytest.mark.teste2e def test_html_render_bind_assets(page: "Page", gui: Gui, helpers, e2e_base_url, e2e_port): gui._set_frame(inspect.currentframe()) gui.add_pages(pages=f"{Path(Path(__file__).parent.resolve())}{os.path.sep}test-assets") helpers.run_e2e(gui) assert ".taipy-text" in urlopen( f"http://127.0.0.1:{e2e_port}{e2e_base_url}test-assets/style/style.css" ).read().decode("utf-8") page.goto("./test-assets/page1") page.expect_websocket() page.wait_for_selector("#text1") retry = 0 while ( retry < 10 and page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")') != "rgb(0, 128, 0)" ): retry += 1 time.sleep(0.1) assert ( page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")') == "rgb(0, 128, 0)" ) assert ( page.evaluate('window.getComputedStyle(document.querySelector("#text2"), null).getPropertyValue("color")') == "rgb(0, 0, 255)" ) @pytest.mark.teste2e def test_html_render_path_mapping(page: "Page", gui: Gui, helpers, e2e_base_url, e2e_port): gui._server = _Server( gui, path_mapping={"style": f"{Path(Path(__file__).parent.resolve())}{os.path.sep}test-assets{os.path.sep}style"}, flask=gui._flask, async_mode="gevent", ) gui.add_page("page1", Html(f"{Path(Path(__file__).parent.resolve())}{os.path.sep}page1.html")) helpers.run_e2e(gui) assert ".taipy-text" in urlopen(f"http://127.0.0.1:{e2e_port}{e2e_base_url}/style/style.css").read().decode("utf-8") page.goto("./page1") page.expect_websocket() page.wait_for_selector("#text1") retry = 0 while ( retry < 10 and page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")') != "rgb(0, 128, 0)" ): retry += 1 time.sleep(0.1) assert ( page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")') == "rgb(0, 128, 0)" ) assert ( page.evaluate('window.getComputedStyle(document.querySelector("#text2"), null).getPropertyValue("color")') == "rgb(0, 0, 255)" ) |
import inspect import logging from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_markdown_render_with_style(page: "Page", gui: Gui, helpers): markdown_content = """ <|Hey|id=text1|> <|There|id=text2|class_name=custom-text|> """ style = """ .taipy-text { color: green; } .custom-text { color: blue; } """ gui._set_frame(inspect.currentframe()) gui.add_page("page1", markdown_content, style=style) helpers.run_e2e(gui) page.goto("./page1") page.expect_websocket() page.wait_for_selector("#text1") page.wait_for_selector("#Taipy_style", state="attached") function_evaluated = True try: page.wait_for_function( 'window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color") !== "rgb(255, 255, 255)"' ) except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: assert ( page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")') == "rgb(0, 128, 0)" ) assert ( page.evaluate('window.getComputedStyle(document.querySelector("#text2"), null).getPropertyValue("color")') == "rgb(0, 0, 255)" ) |
import inspect import logging from importlib import util import pytest from taipy.gui import Gui if util.find_spec("playwright"): from playwright._impl._page import Page from .assets2_class_scopes.page1 import Page1 from .assets2_class_scopes.page2 import Page2 def helpers_assert_value(page, s1, s2, v1): s1_val = page.input_value("#s1 input") assert str(s1_val).startswith(s1) s2_val = page.input_value("#s2 input") assert str(s2_val).startswith(s2) val1 = page.query_selector("#v1").inner_text() assert str(val1).startswith(v1) @pytest.mark.timeout(300) @pytest.mark.teste2e @pytest.mark.filterwarnings("ignore::Warning") def test_class_scopes_binding(page: "Page", gui: Gui, helpers): gui._set_frame(inspect.currentframe()) operand_1 = 0 # noqa: F841 gui.add_page("page1", Page1()) gui.add_page("page2", Page2()) helpers.run_e2e(gui) page.goto("./page1") page.expect_websocket() page.wait_for_selector("#s1") helpers_assert_value(page, "0", "0", "0") page.fill("#s1 input", "15") function_evaluated = True try: page.wait_for_function("document.querySelector('#v1').innerText !== '0'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "15", "0", "15") page.fill("#s2 input", "20") function_evaluated = True try: page.wait_for_function("document.querySelector('#v1').innerText !== '15'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "15", "20", "35") page.goto("./page2") page.expect_websocket() page.wait_for_selector("#s1") helpers_assert_value(page, "15", "0", "0") page.fill("#s2 input", "5") function_evaluated = True try: page.wait_for_function("document.querySelector('#v1').innerText !== '0'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "15", "5", "75") page.fill("#s1 input", "17") function_evaluated = True try: page.wait_for_function("document.querySelector('#v1').innerText !== '75'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "17", "5", "85") page.goto("./page1") page.expect_websocket() page.wait_for_selector("#s1") helpers_assert_value(page, "17", "20", "37") page.click("#btn_reset") try: page.wait_for_function("document.querySelector('#v1').innerText !== '37'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "17", "0", "17") |
import inspect import logging from importlib import util import pytest from taipy.gui import Gui if util.find_spec("playwright"): from playwright._impl._page import Page from .assets.page1 import page as page1 from .assets.page2 import page as page2 from .assets.page3 import page as page3 @pytest.mark.timeout(300) @pytest.mark.teste2e def test_page_scopes(page: "Page", gui: Gui, helpers): gui._set_frame(inspect.currentframe()) def on_change(state, var, val, module): if var == "x" and "page3" in module: state.y = val * 10 gui.add_page("page1", page1) gui.add_page("page2", page2) gui.add_page("page3", page3) helpers.run_e2e(gui) page.goto("./page1") page.expect_websocket() page.wait_for_selector("#x1") assert page.query_selector("#x1").inner_text() == "10" assert page.query_selector("#x2").inner_text() == "20" assert page.query_selector("#y1").inner_text() == "20" assert page.query_selector("#y2").inner_text() == "40" page.goto("./page2") page.expect_websocket() page.wait_for_selector("#x1") assert page.query_selector("#x1").inner_text() == "20" assert page.query_selector("#x2").inner_text() == "40" assert page.query_selector("#y1").inner_text() == "10" assert page.query_selector("#y2").inner_text() == "20" page.goto("./page3") page.expect_websocket() page.wait_for_selector("#x1") assert page.query_selector("#x1").inner_text() == "50" assert page.query_selector("#x2").inner_text() == "100" page.goto("./page1") page.expect_websocket() page.wait_for_selector("#x1") page.fill("#xinput", "15") function_evaluated = True try: page.wait_for_function("document.querySelector('#y2').innerText !== '40'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return assert page.query_selector("#x1").inner_text() == "15" assert page.query_selector("#x2").inner_text() == "30" assert page.query_selector("#y1").inner_text() == "45" assert page.query_selector("#y2").inner_text() == "90" page.goto("./page2") page.expect_websocket() page.wait_for_selector("#x1") assert page.query_selector("#x1").inner_text() == "45" assert page.query_selector("#x2").inner_text() == "90" assert page.query_selector("#y1").inner_text() == "15" assert page.query_selector("#y2").inner_text() == "30" page.fill("#xinput", "37") function_evaluated = True try: page.wait_for_function("document.querySelector('#y2').innerText !== '30'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return assert page.query_selector("#x1").inner_text() == "37" assert page.query_selector("#x2").inner_text() == "74" assert page.query_selector("#y1").inner_text() == "185" assert page.query_selector("#y2").inner_text() == "370" page.goto("./page1") page.expect_websocket() page.wait_for_selector("#x1") assert page.query_selector("#x1").inner_text() == "185" assert page.query_selector("#x2").inner_text() == "370" assert page.query_selector("#y1").inner_text() == "37" assert page.query_selector("#y2").inner_text() == "74" page.goto("./page3") page.expect_websocket() page.wait_for_selector("#x1") assert page.query_selector("#x1").inner_text() == "50" assert page.query_selector("#x2").inner_text() == "100" |
import inspect import logging from importlib import util import pytest from taipy.gui import Gui, Markdown if util.find_spec("playwright"): from playwright._impl._page import Page from .assets3.page1 import page as page1 def helpers_assert_text(page, s): val1 = page.query_selector("#t1").inner_text() assert str(val1).startswith(s) # for issue #583 @pytest.mark.teste2e @pytest.mark.filterwarnings("ignore::Warning") def test_page_scopes_main_var_access(page: "Page", gui: Gui, helpers): gui._set_frame(inspect.currentframe()) n = "Hello" # noqa: F841 root_md = Markdown( """ <|{n}|input|id=i1|> """ ) gui.add_pages({"/": root_md, "page1": page1}) helpers.run_e2e(gui) page.goto("./") page.expect_websocket() page.wait_for_selector("#t1") page.wait_for_selector("#i1") helpers_assert_text(page, "Hello") page.fill("#i1", "Hello World") function_evaluated = True try: page.wait_for_function("document.querySelector('#t1').innerText !== 'Hello'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_text(page, "Hello World") |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
import inspect import logging from importlib import util import pytest from taipy.gui import Gui, Markdown if util.find_spec("playwright"): from playwright._impl._page import Page from .assets3_class_scopes.page1 import Page1 def helpers_assert_text(page, s): val1 = page.query_selector("#t1").inner_text() assert str(val1).startswith(s) # for issue #583 @pytest.mark.teste2e @pytest.mark.filterwarnings("ignore::Warning") def test_class_scopes_main_var_access(page: "Page", gui: Gui, helpers): gui._set_frame(inspect.currentframe()) n = "Hello" # noqa: F841 root_md = Markdown( """ <|{n}|input|id=i1|> """ ) gui.add_pages({"/": root_md, "page1": Page1()}) helpers.run_e2e(gui) page.goto("./") page.expect_websocket() page.wait_for_selector("#t1") page.wait_for_selector("#i1") helpers_assert_text(page, "Hello") page.fill("#i1", "Hello World") function_evaluated = True try: page.wait_for_function("document.querySelector('#t1').innerText !== 'Hello'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_text(page, "Hello World") |
import inspect import logging from importlib import util import pytest from taipy.gui import Gui if util.find_spec("playwright"): from playwright._impl._page import Page from .assets4.page1 import page as page1 from .assets4.page1 import reset_d @pytest.mark.timeout(300) @pytest.mark.teste2e @pytest.mark.filterwarnings("ignore::Warning") def test_page_scopes_state_runtime(page: "Page", gui: Gui, helpers): gui._set_frame(inspect.currentframe()) def test(state): reset_d(state) def test2(state): state["page1"].d = 30 page_md = """ <|button|on_action=test|id=btn1|> <|button|on_action=test2|id=btn2|> """ gui.add_page("page1", page1) gui.add_page(name=Gui._get_root_page_name(), page=page_md) helpers.run_e2e(gui) page.goto("./page1") page.expect_websocket() page.wait_for_selector("#n1") text1 = page.query_selector("#t1") assert text1.inner_text() == "20" page.fill("#n1", "21") function_evaluated = True try: page.wait_for_function("document.querySelector('#t1').innerText !== '20'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return text1 = page.query_selector("#t1") assert text1.inner_text() == "21" page.click("#btn1") try: page.wait_for_function("document.querySelector('#t1').innerText !== '21'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return text1 = page.query_selector("#t1") assert text1.inner_text() == "20" page.click("#btn2") try: page.wait_for_function("document.querySelector('#t1').innerText !== '20'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return text1 = page.query_selector("#t1") assert text1.inner_text() == "30" |
import inspect import logging from importlib import util import pytest from taipy.gui import Gui if util.find_spec("playwright"): from playwright._impl._page import Page from .assets2.page1 import page as page1 from .assets2.page2 import page as page2 def helpers_assert_value(page, s1, s2, v1): s1_val = page.input_value("#s1 input") assert str(s1_val).startswith(s1) s2_val = page.input_value("#s2 input") assert str(s2_val).startswith(s2) val1 = page.query_selector("#v1").inner_text() assert str(val1).startswith(v1) @pytest.mark.timeout(300) @pytest.mark.teste2e @pytest.mark.filterwarnings("ignore::Warning") def test_page_scopes_binding(page: "Page", gui: Gui, helpers): gui._set_frame(inspect.currentframe()) operand_1 = 0 # noqa: F841 gui.add_page("page1", page1) gui.add_page("page2", page2) helpers.run_e2e(gui) page.goto("./page1") page.expect_websocket() page.wait_for_selector("#s1") helpers_assert_value(page, "0", "0", "0") page.fill("#s1 input", "15") function_evaluated = True try: page.wait_for_function("document.querySelector('#v1').innerText !== '0'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "15", "0", "15") page.fill("#s2 input", "20") function_evaluated = True try: page.wait_for_function("document.querySelector('#v1').innerText !== '15'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "15", "20", "35") page.goto("./page2") page.expect_websocket() page.wait_for_selector("#s1") helpers_assert_value(page, "15", "0", "0") page.fill("#s2 input", "5") function_evaluated = True try: page.wait_for_function("document.querySelector('#v1').innerText !== '0'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "15", "5", "75") page.fill("#s1 input", "17") function_evaluated = True try: page.wait_for_function("document.querySelector('#v1').innerText !== '75'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return helpers_assert_value(page, "17", "5", "85") page.goto("./page1") page.expect_websocket() page.wait_for_selector("#s1") helpers_assert_value(page, "17", "20", "37") |
from taipy.gui import Markdown, Page class Page1(Page): def __init__(self): self.operand_2 = 0 super().__init__() def create_page(self): return Markdown("page1.md") def reset(state): state.operand_2 = 0 |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
from taipy.gui import Markdown, Page class Page2(Page): def __init__(self): self.operand_2 = 0 super().__init__() def create_page(self): return Markdown("page2.md") |
from taipy.gui import Markdown, Page class Page1(Page): def create_page(self): return Markdown( """ <|{n}|id=t1|> """ ) |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
from taipy.gui import Markdown x = 10 y = 20 def on_change(state, var, val): if var == "x": state.y = val * 3 page = Markdown( """ x = <|{x}|id=x1|> x * 2 = <|{x*2}|id=x2|> x number: <|{x}|number|id=xinput|> y = <|{y}|id=y1|> y * 2 = <|{y*2}|id=y2|> """ ) |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
from taipy.gui import Markdown from .page1 import x as y from .page1 import y as x def on_change(state, var, val): if var == "x": state.y = val * 5 page = Markdown( """ y = <|{x}|id=x1|> y * 2 = <|{x*2}|id=x2|> y number: <|{x}|number|id=xinput|> x = <|{y}|id=y1|> x * 2 = <|{y*2}|id=y2|> """ ) |
from taipy.gui import Markdown x = 50 page = Markdown( """ <|{x}|id=x1|> x * 2 = <|{x*2}|id=x2|> <|{x}|number|id=xinput|> """ ) |
from taipy.gui import Markdown page = Markdown( """ # Page1 - Add Operand 1: <|{operand_1}|slider|id=s1|> Operand 2: <|{operand_2}|slider|id=s2|> Operand 1 + Operand 2 = <|{operand_1 + operand_2}|id=v1|> """ ) operand_2 = 0 |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
from taipy.gui import Markdown page = Markdown( """ # Page2 - Multiply Operand 1: <|{operand_1}|slider|id=s1|> Operand 2: <|{operand_2}|slider|id=s2|> Operand 1 * Operand 2 = <|{operand_1 * operand_2}|id=v1|> """ ) operand_2 = 0 |
from taipy.gui import Markdown d = 20 def reset_d(state): state.d = d # a page = Markdown( """ <|{d}|text|id=t1|> <|{d}|number|id=n1|> """ ) |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
from taipy.gui import Markdown page = Markdown( """ <|{n}|id=t1|> """ ) |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
import inspect import logging from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_slider_action(page: "Page", gui: Gui, helpers): page_md = """ <|{x}|id=text1|> <|{x}|slider|id=slider1|> """ x = 10 # noqa: F841 gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./test") page.expect_websocket() page.wait_for_selector("#text1") text1 = page.query_selector("#text1") assert text1.inner_text() == "10" page.wait_for_selector("#slider1") page.fill("#slider1 input", "20") function_evaluated = True try: page.wait_for_function("document.querySelector('#text1').innerText !== '10'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: text1_2 = page.query_selector("#text1") assert text1_2.inner_text() == "20" @pytest.mark.teste2e def test_slider_action_on_change(page: "Page", gui: Gui, helpers): d = {"v1": 10, "v2": 10} # noqa: F841 def on_change(state, var, val): if var == "d.v2": d = {"v1": 2 * val} state.d.update(d) page_md = """ Value: <|{d.v1}|id=text1|> Slider: <|{d.v2}|slider|id=slider1|> """ gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./test") page.expect_websocket() page.wait_for_selector("#text1") text1 = page.query_selector("#text1") assert text1.inner_text() == "10" page.wait_for_selector("#slider1") page.fill("#slider1 input", "20") function_evaluated = True try: page.wait_for_function("document.querySelector('#text1').innerText !== '10'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: text1_2 = page.query_selector("#text1") assert text1_2.inner_text() == "40" |
import inspect import logging from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_button_action(page: "Page", gui: Gui, helpers): page_md = """ <|{x}|id=text1|> <|Action|button|on_action=do_something_fn|id=button1|> """ x = 10 # noqa: F841 def do_something_fn(state): state.x = state.x * 2 gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./test") page.expect_websocket() page.wait_for_selector("#text1") text1 = page.query_selector("#text1") assert text1.inner_text() == "10" page.click("#button1") function_evaluated = True try: page.wait_for_function("document.querySelector('#text1').innerText !== '10'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: text1_2 = page.query_selector("#text1") assert text1_2.inner_text() == "20" |
import inspect import time from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui, State @pytest.mark.teste2e def test_selector_action(page: "Page", gui: Gui, helpers): page_md = """ <|{x}|selector|lov=Item 1;Item 2;Item 3|id=selector1|> """ x = "Item 1" # noqa: F841 def on_init(state: State): assert state.x == "Item 1" def on_change(state: State, var, val): if var == "x": assert val == "Item 3" gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./test") page.expect_websocket() page.wait_for_selector("ul#selector1") page.click('#selector1 > div[data-id="Item 3"]') page.wait_for_function( "document.querySelector('#selector1 > div[data-id=\"Item 3\"]').classList.contains('Mui-selected')" ) |
import inspect import logging from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui def edit_and_assert_page(page: "Page"): assert_input(page, "0") page.fill("#input2 input", "20") function_evaluated = True try: page.wait_for_function("document.querySelector('#val1').innerText !== '0'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return assert_input(page, "20") page.fill("#input1", "30") function_evaluated = True try: page.wait_for_function("document.querySelector('#val1').innerText !== '20'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if not function_evaluated: return assert_input(page, "30") def assert_input(page: "Page", val: str): val1 = page.query_selector("#val1").inner_text() assert str(val1).startswith(val) val2 = page.query_selector("#val2").inner_text() assert str(val2).startswith(f"Val: {val}") inp1 = page.input_value("input#input1") assert str(inp1).startswith(val) inp2 = page.input_value("#input2 input") assert str(inp2).startswith(val) @pytest.mark.filterwarnings("ignore::Warning") @pytest.mark.teste2e def test_slider_input_reload(page: "Page", gui: Gui, helpers): page_md = """ #Test Multi Number <|{val}|id=val1|> <|Val: {val}|id=val2|> <|{val}|number|id=input1|> <|{val}|slider|id=input2|> """ val = 0 # noqa: F841 gui._set_frame(inspect.currentframe()) gui.add_page(name="page1", page=page_md) helpers.run_e2e_multi_client(gui) page.goto("./page1") page.expect_websocket() page.wait_for_selector("#val1") edit_and_assert_page(page) page.reload() page.expect_websocket() page.wait_for_selector("#val1") assert_input(page, "30") page.evaluate("window.localStorage.removeItem('TaipyClientId')") page.reload() page.expect_websocket() page.wait_for_selector("#val1") assert_input(page, "0") |
import inspect import logging from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_dict(page: "Page", gui: Gui, helpers): page_md = """ <|{a_dict[a_key]}|input|id=inp1|> <|{a_dict.key}|input|id=inp2|> <|test|button|on_action=on_action_1|id=btn1|> <|test|button|on_action=on_action_2|id=btn2|> """ a_key = "key" a_dict = {a_key: "Taipy"} # noqa: F841 def on_action_1(state): state.a_dict.key = "Hello" def on_action_2(state): state.a_dict[state.a_key] = "World" gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./test") page.expect_websocket() page.wait_for_selector("#inp1") assert_text(page, "Taipy", "Taipy") page.fill("input#inp1", "Taipy is the best") function_evaluated = True try: page.wait_for_function("document.querySelector('#inp2').value !== 'Taipy'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: assert_text(page, "Taipy is the best", "Taipy is the best") page.fill("#inp2", "Taipy-Gui") function_evaluated = True try: page.wait_for_function("document.querySelector('#inp1').value !== 'Taipy is the best'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: assert_text(page, "Taipy-Gui", "Taipy-Gui") page.click("#btn1") function_evaluated = True try: page.wait_for_function("document.querySelector('#inp1').value !== 'Taipy-Gui'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: assert_text(page, "Hello", "Hello") page.click("#btn2") function_evaluated = True try: page.wait_for_function("document.querySelector('#inp1').value !== 'Hello'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: assert_text(page, "World", "World") def assert_text(page, inp1, inp2): assert page.input_value("input#inp1") == inp1 assert page.input_value("input#inp2") == inp2 |
import inspect import logging from importlib import util import pytest if util.find_spec("playwright"): from playwright._impl._page import Page from taipy.gui import Gui @pytest.mark.teste2e def test_text_edit(page: "Page", gui: Gui, helpers): page_md = """ <|{x}|text|id=text1|> <|{x}|input|id=input1|> """ x = "Hey" # noqa: F841 gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./test") page.expect_websocket() page.wait_for_selector("#text1") text1 = page.query_selector("#text1") assert text1.inner_text() == "Hey" page.wait_for_selector("#input1") page.fill("#input1", "There") function_evaluated = True try: page.wait_for_function("document.querySelector('#text1').innerText !== 'Hey'") except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: text1_2 = page.query_selector("#text1") assert text1_2.inner_text() == "There" @pytest.mark.teste2e def test_number_edit(page: "Page", gui: Gui, helpers): page_md = """ <|{x}|text|id=text1|> <|{x}|number|id=number1|> """ x = 10 # noqa: F841 gui._set_frame(inspect.currentframe()) gui.add_page(name="test", page=page_md) helpers.run_e2e(gui) page.goto("./test") page.expect_websocket() page.wait_for_selector("#text1") text1 = page.query_selector("#text1") assert text1.inner_text() == "10" page.wait_for_selector("#number1") page.fill("#number1", "20") function_evaluated = True try: page.wait_for_function("document.querySelector('#text1').innerText !== '10'") function_evaluated = True except Exception as e: function_evaluated = False logging.getLogger().debug(f"Function evaluation timeout.\n{e}") if function_evaluated: text1_2 = page.query_selector("#text1") assert text1_2.inner_text() == "20" |
import inspect from datetime import datetime from importlib import util import pandas # type: ignore from flask import g from taipy.gui import Gui from taipy.gui.data.data_format import _DataFormat from taipy.gui.data.decimator import ScatterDecimator from taipy.gui.data.pandas_data_accessor import _PandasDataAccessor def test_simple_data(gui: Gui, helpers, small_dataframe): accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) ret_data = accessor.get_data(gui, "x", pd, {"start": 0, "end": -1}, _DataFormat.JSON) assert ret_data value = ret_data["value"] assert value assert value["rowcount"] == 3 data = value["data"] assert len(data) == 3 def test_simple_data_with_arrow(gui: Gui, helpers, small_dataframe): if util.find_spec("pyarrow"): accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) ret_data = accessor.get_data(gui, "x", pd, {"start": 0, "end": -1}, _DataFormat.APACHE_ARROW) assert ret_data value = ret_data["value"] assert value assert value["rowcount"] == 3 data = value["data"] assert isinstance(data, bytes) def test_get_all_simple_data(gui: Gui, helpers, small_dataframe): accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) ret_data = accessor.get_data(gui, "x", pd, {"alldata": True}, _DataFormat.JSON) assert ret_data assert ret_data["alldata"] is True value = ret_data["value"] assert value data = value["data"] assert data == small_dataframe def test_slice(gui: Gui, helpers, small_dataframe): accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) value = accessor.get_data(gui, "x", pd, {"start": 0, "end": 1}, _DataFormat.JSON)["value"] assert value["rowcount"] == 3 data = value["data"] assert len(data) == 2 value = accessor.get_data(gui, "x", pd, {"start": "0", "end": "1"}, _DataFormat.JSON)["value"] data = value["data"] assert len(data) == 2 def test_sort(gui: Gui, helpers, small_dataframe): accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) query = {"columns": ["name", "value"], "start": 0, "end": -1, "orderby": "name", "sort": "desc"} data = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON)["value"]["data"] assert data[0]["name"] == "C" def test_aggregate(gui: Gui, helpers, small_dataframe): accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) pd = pandas.concat( [pd, pandas.DataFrame(data={"name": ["A"], "value": [4]})], axis=0, join="outer", ignore_index=True ) query = {"columns": ["name", "value"], "start": 0, "end": -1, "aggregates": ["name"], "applies": {"value": "sum"}} value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON)["value"] assert value["rowcount"] == 3 data = value["data"] assert next(v.get("value") for v in data if v.get("name") == "A") == 5 def test_filters(gui: Gui, helpers, small_dataframe): accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) pd = pandas.concat( [pd, pandas.DataFrame(data={"name": ["A"], "value": [4]})], axis=0, join="outer", ignore_index=True ) query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [{"col": "name", "action": "!=", "value": ""}], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 4 query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [{"col": "name", "action": "==", "value": ""}], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 0 query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [{"col": "name", "action": "==", "value": "A"}], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 2 query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [{"col": "name", "action": "==", "value": "A"}, {"col": "value", "action": "==", "value": 2}], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 0 query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [{"col": "name", "action": "!=", "value": "A"}, {"col": "value", "action": "==", "value": 2}], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 1 assert value["value"]["data"][0]["_tp_index"] == 1 def test_filter_by_date(gui: Gui, helpers, small_dataframe): accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) pd["a date"] = [ datetime.fromisocalendar(2022, 28, 1), datetime.fromisocalendar(2022, 28, 2), datetime.fromisocalendar(2022, 28, 3), ] query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [{"col": "a date", "action": ">", "value": datetime.fromisocalendar(2022, 28, 3).isoformat() + "Z"}], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 0 query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [{"col": "a date", "action": ">", "value": datetime.fromisocalendar(2022, 28, 2).isoformat() + "Z"}], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 1 query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [{"col": "a date", "action": "<", "value": datetime.fromisocalendar(2022, 28, 3).isoformat() + "Z"}], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 2 query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [ {"col": "a date", "action": "<", "value": datetime.fromisocalendar(2022, 28, 2).isoformat() + "Z"}, {"col": "a date", "action": ">", "value": datetime.fromisocalendar(2022, 28, 2).isoformat() + "Z"}, ], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 0 query = { "columns": ["name", "value"], "start": 0, "end": -1, "filters": [ {"col": "a date", "action": "<", "value": datetime.fromisocalendar(2022, 28, 3).isoformat() + "Z"}, {"col": "a date", "action": ">", "value": datetime.fromisocalendar(2022, 28, 1).isoformat() + "Z"}, ], } value = accessor.get_data(gui, "x", pd, query, _DataFormat.JSON) assert len(value["value"]["data"]) == 1 def test_decimator(gui: Gui, helpers, small_dataframe): a_decimator = ScatterDecimator() accessor = _PandasDataAccessor() pd = pandas.DataFrame(data=small_dataframe) # set gui frame gui._set_frame(inspect.currentframe()) gui.add_page("test", "<|Hello {a_decimator}|button|id={btn_id}|>") gui.run(run_server=False) flask_client = gui._server.test_client() cid = helpers.create_scope_and_get_sid(gui) # Get the jsx once so that the page will be evaluated -> variable will be registered flask_client.get(f"/taipy-jsx/test?client_id={cid}") with gui.get_flask_app().test_request_context(f"/taipy-jsx/test/?client_id={cid}", data={"client_id": cid}): g.client_id = cid ret_data = accessor.get_data( gui, "x", pd, { "start": 0, "end": -1, "alldata": True, "decimatorPayload": { "decimators": [{"decimator": "a_decimator", "chartMode": "markers"}], "width": 100, }, }, _DataFormat.JSON, ) assert ret_data value = ret_data["value"] assert value data = value["data"] assert len(data) == 2 |
from importlib import util from taipy.gui import Gui from taipy.gui.data.array_dict_data_accessor import _ArrayDictDataAccessor from taipy.gui.data.data_format import _DataFormat from taipy.gui.utils import _MapDict an_array = [1, 2, 3] def test_simple_data(gui: Gui, helpers): accessor = _ArrayDictDataAccessor() ret_data = accessor.get_data(gui, "x", an_array, {"start": 0, "end": -1}, _DataFormat.JSON) assert ret_data value = ret_data["value"] assert value assert value["rowcount"] == 3 data = value["data"] assert len(data) == 3 def test_simple_data_with_arrow(gui: Gui, helpers): if util.find_spec("pyarrow"): accessor = _ArrayDictDataAccessor() ret_data = accessor.get_data(gui, "x", an_array, {"start": 0, "end": -1}, _DataFormat.APACHE_ARROW) assert ret_data value = ret_data["value"] assert value assert value["rowcount"] == 3 data = value["data"] assert isinstance(data, bytes) def test_slice(gui: Gui, helpers): accessor = _ArrayDictDataAccessor() value = accessor.get_data(gui, "x", an_array, {"start": 0, "end": 1}, _DataFormat.JSON)["value"] assert value["rowcount"] == 3 data = value["data"] assert len(data) == 2 value = accessor.get_data(gui, "x", an_array, {"start": "0", "end": "1"}, _DataFormat.JSON)["value"] data = value["data"] assert len(data) == 2 def test_sort(gui: Gui, helpers): accessor = _ArrayDictDataAccessor() a_dict = {"name": ["A", "B", "C"], "value": [3, 2, 1]} query = {"columns": ["name", "value"], "start": 0, "end": -1, "orderby": "name", "sort": "desc"} data = accessor.get_data(gui, "x", a_dict, query, _DataFormat.JSON)["value"]["data"] assert data[0]["name"] == "C" def test_aggregate(gui: Gui, helpers, small_dataframe): accessor = _ArrayDictDataAccessor() a_dict = {"name": ["A", "B", "C", "A"], "value": [3, 2, 1, 2]} query = {"columns": ["name", "value"], "start": 0, "end": -1, "aggregates": ["name"], "applies": {"value": "sum"}} value = accessor.get_data(gui, "x", a_dict, query, _DataFormat.JSON)["value"] assert value["rowcount"] == 3 data = value["data"] agregValue = next(v.get("value") for v in data if v.get("name") == "A") assert agregValue == 5 def test_array_of_array(gui: Gui, helpers, small_dataframe): accessor = _ArrayDictDataAccessor() an_array = [[1, 2, 3], [2, 4, 6]] ret_data = accessor.get_data(gui, "x", an_array, {"start": 0, "end": -1}, _DataFormat.JSON) assert ret_data value = ret_data["value"] assert value assert value["rowcount"] == 2 data = value["data"] assert len(data) == 2 assert len(data[0]) == 4 # including _tp_index def test_empty_array(gui: Gui, helpers, small_dataframe): accessor = _ArrayDictDataAccessor() an_array: list[str] = [] ret_data = accessor.get_data(gui, "x", an_array, {"start": 0, "end": -1}, _DataFormat.JSON) assert ret_data value = ret_data["value"] assert value assert value["rowcount"] == 0 data = value["data"] assert len(data) == 0 def test_array_of_diff_array(gui: Gui, helpers, small_dataframe): accessor = _ArrayDictDataAccessor() an_array = [[1, 2, 3], [2, 4]] ret_data = accessor.get_data(gui, "x", an_array, {"start": 0, "end": -1, "alldata": True}, _DataFormat.JSON) assert ret_data value = ret_data["value"] assert value assert value["multi"] is True data = value["data"] assert len(data) == 2 assert len(data[0]["0/0"]) == 3 assert len(data[1]["1/0"]) == 2 def test_array_of_dicts(gui: Gui, helpers, small_dataframe): accessor = _ArrayDictDataAccessor() an_array_of_dicts = [ { "temperatures": [ [17.2, 27.4, 28.6, 21.5], [5.6, 15.1, 20.2, 8.1], [26.6, 22.8, 21.8, 24.0], [22.3, 15.5, 13.4, 19.6], [3.9, 18.9, 25.7, 9.8], ], "cities": ["Hanoi", "Paris", "Rio de Janeiro", "Sydney", "Washington"], }, {"seasons": ["Winter", "Summer", "Spring", "Autumn"]}, ] ret_data = accessor.get_data( gui, "x", an_array_of_dicts, {"start": 0, "end": -1, "alldata": True}, _DataFormat.JSON ) assert ret_data value = ret_data["value"] assert value assert value["multi"] is True data = value["data"] assert len(data) == 2 assert len(data[0]["temperatures"]) == 5 assert len(data[1]["seasons"]) == 4 def test_array_of_Mapdicts(gui: Gui, helpers, small_dataframe): accessor = _ArrayDictDataAccessor() dict1 = _MapDict( { "temperatures": [ [17.2, 27.4, 28.6, 21.5], [5.6, 15.1, 20.2, 8.1], [26.6, 22.8, 21.8, 24.0], [22.3, 15.5, 13.4, 19.6], [3.9, 18.9, 25.7, 9.8], ], "cities": ["Hanoi", "Paris", "Rio de Janeiro", "Sydney", "Washington"], } ) dict2 = _MapDict({"seasons": ["Winter", "Summer", "Spring", "Autumn"]}) ret_data = accessor.get_data(gui, "x", [dict1, dict2], {"start": 0, "end": -1, "alldata": True}, _DataFormat.JSON) assert ret_data value = ret_data["value"] assert value assert value["multi"] is True data = value["data"] assert len(data) == 2 assert len(data[0]["temperatures"]) == 5 assert len(data[1]["seasons"]) == 4 |
import inspect import taipy.gui.builder as tgb from taipy.gui import Gui def test_slider_builder(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) with tgb.Page(frame=None) as page: tgb.slider(value="{x}") expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0', "defaultValue={10}", "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_slider_with_min_max_builder(gui: Gui, test_client, helpers): gui._bind_var_val("x", 0) with tgb.Page(frame=None) as page: tgb.slider(value="{x}", min=-10, max=10) expected_list = ["<Slider", "min={-10.0}", "max={10.0}", "defaultValue={0}"] helpers.test_control_builder(gui, page, expected_list) def test_slider_with_dict_labels_builder(gui: Gui, helpers): sel = "Item 1" # noqa: F841 labels = {"Item 1": "Label Start", "Item 3": "Label End"} # noqa: F841 gui._set_frame(inspect.currentframe()) with tgb.Page(frame=None) as page: tgb.slider(value="{sel}", lov="Item 1;Item 2;Item 3", labels=labels) expected_list = [ "<Slider", 'labels="{"Item 1": "Label Start", "Item 3": "Label End"}"', ] helpers.test_control_builder(gui, page, expected_list) def test_slider_with_boolean_labels_builder(gui: Gui, helpers): sel = "Item 1" # noqa: F841 gui._set_frame(inspect.currentframe()) with tgb.Page(frame=None) as page: tgb.slider(value="{sel}", lov="Item 1;Item 2;Item 3", labels=True) expected_list = ["<Slider", "labels={true}"] helpers.test_control_builder(gui, page, expected_list) def test_slider_items_builder(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") with tgb.Page(frame=None) as page: tgb.slider(value="{x}", lov="Item 1;Item 2;Item 3", text_anchor="left") expected_list = [ "<Slider", 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"', "value={_TpLv_tpec_TpExPr_x_TPMDL_0}", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'textAnchor="left"', ] helpers.test_control_builder(gui, page, expected_list) def test_slider_text_anchor_builder(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") with tgb.Page(frame=None) as page: tgb.slider(value="{x}", text_anchor=None) expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", 'textAnchor="none"', ] helpers.test_control_builder(gui, page, expected_list) def test_slider_text_anchor_default_builder(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") with tgb.Page(frame=None) as page: tgb.slider(value="{x}", items="Item 1") expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", 'textAnchor="bottom"', ] helpers.test_control_builder(gui, page, expected_list) |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. import taipy.gui.builder as tgb from taipy.gui import Gui def test_button_builder_1(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") with tgb.Page(frame=None) as page: tgb.button(label="Hello {name}", id="{btn_id}") expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_selector_builder_1(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", ["l1", "l2"]) gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True}) with tgb.Page(frame=None) as page: tgb.selector(value="{selected_val}", properties="{selector_properties}", multiple=True) expected_list = [ "<Selector", 'defaultLov="[["l1", "v1"], ["l2", "v2"], ["l3", "v3"]]"', 'defaultValue="["l1", "l2"]"', "filter={true}", "multiple={true}", 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_selector_builder_2(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", "Item 2") with tgb.Page(frame=None) as page: tgb.selector(value="{selected_val}", lov="Item 1;Item 2; This is a another value") expected_list = [ "<Selector", 'defaultLov="["Item 1", "Item 2", " This is a another value"]"', 'defaultValue="["Item 2"]"', 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_selector_builder_3(gui: Gui, test_client, helpers): gui._bind_var_val("elt", None) gui._bind_var_val( "scenario_list", [{"id": "1", "name": "scenario 1"}, {"id": "3", "name": "scenario 3"}, {"id": "2", "name": "scenario 2"}], ) gui._bind_var_val("selected_obj", {"id": "1", "name": "scenario 1"}) with tgb.Page(frame=None) as page: tgb.selector( value="{selected_obj}", lov="{scenario_list}", adapter="{lambda elt: (elt['id'], elt['name'])}", propagate=False, ) expected_list = [ "<Selector", 'defaultLov="[["1", "scenario 1"], ["3", "scenario 3"], ["2", "scenario 2"]]"', 'defaultValue="["1"]"', "lov={_TpL_tpec_TpExPr_scenario_list_TPMDL_0}", "propagate={false}", 'updateVars="lov=_TpL_tpec_TpExPr_scenario_list_TPMDL_0"', 'updateVarName="_TpLv_tpec_TpExPr_selected_obj_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_obj_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) |
import inspect import taipy.gui.builder as tgb from taipy.gui import Gui def test_input_builder(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) with tgb.Page(frame=None) as page: tgb.input(value="{x}") expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="text"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_password_builder(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) with tgb.Page(frame=None) as page: tgb.input(value="{x}", password=True) expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="password"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_tree_builder(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") with tgb.Page(frame=None) as page: tgb.tree(value="{value}", lov="Item 1;Item 2;Item 3") expected_list = [ "<TreeView", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_tree_expanded_builder_1(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") with tgb.Page(frame=None) as page: tgb.tree(value="{value}", lov="Item 1;Item 2;Item 3", expanded=False) expected_list = [ "<TreeView", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", "expanded={false}", ] helpers.test_control_builder(gui, page, expected_list) def test_tree_expanded_builder_2(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") gui._bind_var_val("expa", ["Item1"]) with tgb.Page(frame=None) as page: tgb.tree(value="{value}", lov="Item 1;Item 2;Item 3", expanded="{expa}") expected_list = [ "<TreeView", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", 'defaultExpanded="["Item1"]"', "expanded={tpec_TpExPr_expa_TPMDL_0}", 'updateVars="expanded=tpec_TpExPr_expa_TPMDL_0', ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_expandable_builder_1(gui: Gui, helpers): with tgb.expandable(title="Expandable section", expanded=False) as content: tgb.text(value="This is an expandable section") expected_list = [ "<Expandable", "expanded={false}", 'title="Expandable section"', "This is an expandable section", ] helpers.test_control_builder(gui, tgb.Page(content, frame=None), expected_list) |
import inspect import taipy.gui.builder as tgb from taipy.gui import Gui def test_table_builder_1(gui: Gui, helpers, csvdata): with tgb.Page(frame=None) as page: tgb.table( data="{csvdata}", page_size=10, page_size_options=[10, 30, 100], columns=["Day", "Entity", "Code", "Daily hospital occupancy"], date_format="eee dd MMM yyyy", ) expected_list = [ "<Table", 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "type": "int", "dfid": "Daily hospital occupancy"}, "Day_str": {"index": 0, "type": "datetime", "dfid": "Day", "format": "eee dd MMM yyyy"}}"', 'height="80vh"', 'width="100%"', 'pageSizeOptions="[10, 30, 100]"', "pageSize={10.0}", "selected={[]}", 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_builder(gui, page, expected_list) def test_table_reset_builder(gui: Gui, helpers, csvdata): with tgb.Page(frame=None) as page: tgb.table( data="{csvdata}", rebuild=True, page_size=10, page_size_options="10;30;100", columns="Day;Entity;Code;Daily hospital occupancy", date_format="eee dd MMM yyyy", ) expected_list = [ "<Table", 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "type": "int", "dfid": "Daily hospital occupancy"}, "Day_str": {"index": 0, "type": "datetime", "dfid": "Day", "format": "eee dd MMM yyyy"}}"', 'height="80vh"', 'width="100%"', 'pageSizeOptions="[10, 30, 100]"', "pageSize={10.0}", "selected={[]}", 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", "columns={tp_TpExPr_gui_tbl_cols_True_None_7B_22columns_22_3A_20_22Day_3BEntity_3BCode_3BDaily_20hospital_20occupancy_22_2C_20_22date_format_22_3A_20_22eee_20dd_20MMM_20yyyy_22_7D_7B_22data_22_3A_20_22tpec_TpExPr_csvdata_TPMDL_0_22_7D_tpec_TpExPr_csvdata_TPMDL_0_csvdata_TPMDL_0_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_builder(gui, page, expected_list) def test_table_builder_2(gui: Gui, helpers, csvdata): table_properties = { # noqa: F841 "page_size": 10, "page_size_options": [10, 50, 100, 500], "allow_all_rows": True, "columns": { "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"}, "Entity": {"index": 1}, "Code": {"index": 2}, "Daily hospital occupancy": {"index": 3}, }, "date_format": "eee dd MMM yyyy", "number_format": "%.3f", "width": "60vw", "height": "60vh", } with tgb.Page(frame=None) as page: tgb.table(data="{csvdata}", properties="table_properties", auto_loading=True, editable=False) expected_list = [ "<Table", "allowAllRows={true}", "autoLoading={true}", "editable={false}", 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "type": "int", "dfid": "Daily hospital occupancy", "format": "%.3f"}, "Day_str": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure", "type": "datetime", "dfid": "Day"}}"', 'height="60vh"', 'width="60vw"', 'pageSizeOptions="[10, 50, 100, 500]"', "pageSize={10}", "selected={[]}", 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_builder(gui, page, expected_list) |
import os import pathlib from importlib import util import taipy.gui.builder as tgb from taipy.gui import Gui def test_image_url_builder(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") with tgb.Page(frame=None) as page: tgb.image(content="{content}") expected_list = [ "<Image", "content={_TpCi_tpec_TpExPr_content_TPMDL_0}", 'defaultContent="some_url"', ] helpers.test_control_builder(gui, page, expected_list) def test_image_file_builder(gui: Gui, test_client, helpers): with open((pathlib.Path(__file__).parent.parent.parent / "resources" / "fred.png").resolve(), "rb") as content: gui._bind_var_val("content", content.read()) with tgb.Page(frame=None) as page: tgb.image(content="{content}") expected_list = [ "<Image", 'defaultContent="data:image/png;base64,', ] if not util.find_spec("magic"): expected_list = ["<Image", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_builder(gui, page, expected_list) def test_image_path_builder(gui: Gui, test_client, helpers): gui._bind_var_val( "content", str((pathlib.Path(__file__).parent.parent.parent / "resources" / "fred.png").resolve()) ) with tgb.Page(frame=None) as page: tgb.image(content="{content}") expected_list = [ "<Image", 'defaultContent="/taipy-content/taipyStatic0/fred.png', ] helpers.test_control_builder(gui, page, expected_list) def test_image_bad_file_builder(gui: Gui, test_client, helpers): with open(os.path.abspath(__file__), "rb") as content: gui._bind_var_val("content", content.read()) with tgb.Page(frame=None) as page: tgb.image(content="{content}") expected_list = [ "<Image", 'defaultContent="Invalid content: text/x', ] if not util.find_spec("magic"): expected_list = ["<Image", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_builder(gui, page, expected_list) |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. import taipy.gui.builder as tgb from taipy.gui import Gui def test_html_builder(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") with tgb.Page(frame=None) as page: tgb.html("h1", "This is a header", style="color:Tomato;") with tgb.html("p", "This is a paragraph.", style="color:green;"): tgb.html("a", "a text", href="https://www.w3schools.com", target="_blank") tgb.html("br") tgb.html("b", "This is bold text inside the paragrah.") expected_list = [ '<h1 style="color:Tomato;">This is a header', '<p style="color:green;">This is a paragraph.', '<a href="https://www.w3schools.com" target="_blank">a text', "<br>", "<b>This is bold text inside the paragrah.", ] helpers.test_control_builder(gui, page, expected_list) |
import inspect import taipy.gui.builder as tgb from taipy.gui import Gui def test_status_builder(gui: Gui, helpers): status = [{"status": "info", "message": "Info Message"}] # noqa: F841 with tgb.Page(frame=None) as page: tgb.status(value="{status}") expected_list = [ "<Status", 'defaultValue="[{"status": "info", "message": "Info Message"}]"', "value={tpec_TpExPr_status_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_toggle_builder(gui: Gui, helpers): with tgb.Page(frame=None) as page: tgb.toggle(theme=True) expected_list = ["<Toggle", 'kind="theme"', 'unselectedValue=""'] helpers.test_control_builder(gui, page, expected_list) def test_toggle_allow_unselected_builder(gui: Gui, helpers): with tgb.Page(frame=None) as page: tgb.toggle(allow_unselect=True, lov="1;2") expected_list = ["<Toggle", 'unselectedValue=""', "allowUnselect={true}"] helpers.test_control_builder(gui, page, expected_list) def test_toggle_lov_builder(gui: Gui, test_client, helpers): gui._bind_var_val("x", "l1") gui._bind_var_val("lov", [("l1", "v1"), ("l2", "v2")]) with tgb.Page(frame=None) as page: tgb.toggle(lov="{lov}", value="{x}", label="Label") expected_list = [ "<Toggle", 'defaultLov="[["l1", "v1"], ["l2", "v2"]]"', 'defaultValue="l1"', 'label="Label"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"', 'unselectedValue=""', "value={_TpLv_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_pane_builder(gui: Gui, test_client, helpers): gui._bind_var_val("show_pane", False) with tgb.Page(frame=None) as page: with tgb.pane(open="{show_pane}"): tgb.text(value="This is a Pane") expected_list = [ "<Pane", 'anchor="left"', 'updateVarName="_TpB_tpec_TpExPr_show_pane_TPMDL_0"', "open={_TpB_tpec_TpExPr_show_pane_TPMDL_0}", "This is a Pane", ] helpers.test_control_builder(gui, page, expected_list) def test_pane_persistent_builder(gui: Gui, test_client, helpers): gui._bind_var_val("show_pane", False) with tgb.Page(frame=None) as page: with tgb.pane(open="{show_pane}", persistent=True): tgb.text(value="This is a Pane") expected_list = [ "<Pane", 'anchor="left"', "persistent={true}", 'updateVarName="_TpB_tpec_TpExPr_show_pane_TPMDL_0"', "open={_TpB_tpec_TpExPr_show_pane_TPMDL_0}", "This is a Pane", ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_text_builder_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) with tgb.Page(frame=None) as page: tgb.text(value="{x}") expected_list = ["<Field", 'dataType="int"', 'defaultValue="10"', "value={tpec_TpExPr_x_TPMDL_0}"] helpers.test_control_builder(gui, page, expected_list) def test_text_builder_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) with tgb.Page(frame=None) as page: tgb.text("{x}") expected_list = ["<Field", 'dataType="int"', 'defaultValue="10"', "value={tpec_TpExPr_x_TPMDL_0}"] helpers.test_control_builder(gui, page, expected_list) |
import os import pathlib from importlib import util import taipy.gui.builder as tgb from taipy.gui import Gui def test_file_download_url_builder(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") with tgb.Page(frame=None) as page: tgb.file_download(content="{content}") expected_list = [ "<FileDownload", "content={_TpC_tpec_TpExPr_content_TPMDL_0}", 'defaultContent="some_url"', ] helpers.test_control_builder(gui, page, expected_list) def test_file_download_file_builder(gui: Gui, test_client, helpers): with open((pathlib.Path(__file__).parent.parent.parent / "resources" / "fred.png").resolve(), "rb") as content: gui._bind_var_val("content", content.read()) with tgb.Page(frame=None) as page: tgb.file_download(content="{content}") expected_list = [ "<FileDownload", 'defaultContent="data:image/png;base64,', ] if not util.find_spec("magic"): expected_list = ["<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_builder(gui, page, expected_list) def test_file_download_path_builder(gui: Gui, test_client, helpers): gui._bind_var_val( "content", str((pathlib.Path(__file__).parent.parent.parent / "resources" / "fred.png").resolve()) ) with tgb.Page(frame=None) as page: tgb.file_download(content="{content}") expected_list = [ "<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/fred.png', ] helpers.test_control_builder(gui, page, expected_list) def test_file_download_any_file_builder(gui: Gui, test_client, helpers): with open(os.path.abspath(__file__), "rb") as content: gui._bind_var_val("content", content.read()) with tgb.Page(frame=None) as page: tgb.file_download(content="{content}") expected_list = [ "<FileDownload", 'defaultContent="data:text/x', "python;base64,", ] if not util.find_spec("magic"): expected_list = ["<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_file_selector_builder(gui: Gui, test_client, helpers): gui._bind_var_val("content", None) with tgb.Page(frame=None) as page: tgb.file_selector(content="{content}", label="label", on_action="action") expected_list = [ "<FileSelector", 'updateVarName="tpec_TpExPr_content_TPMDL_0"', 'label="label"', 'onAction="action"', ] helpers.test_control_builder(gui, page, expected_list) |
import inspect import taipy.gui.builder as tgb from taipy.gui import Gui, Markdown def test_dialog_builder_1(gui: Gui, helpers): dialog_open = False # noqa: F841 gui._set_frame(inspect.currentframe()) with tgb.Page(frame=None) as page: tgb.dialog(title="This is a Dialog", open="{dialog_open}", page="page_test", on_action="validate_action") expected_list = [ "<Dialog", 'onAction="validate_action"', 'page="page_test"', 'title="This is a Dialog"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_dialog_builder_2(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) partial = gui.add_partial(Markdown("# A partial")) # noqa: F841 dialog_open = False # noqa: F841 with tgb.Page(frame=None) as page: tgb.dialog( title="Another Dialog", open="{dialog_open}", partial="{partial}", on_action="validate_action", ) expected_list = [ "<Dialog", 'page="TaiPy_partials', 'title="Another Dialog"', 'onAction="validate_action"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_dialog_labels_builder(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) dialog_open = False # noqa: F841 with tgb.Page(frame=None) as page: tgb.dialog( title="Another Dialog", open="{dialog_open}", page="page_test", labels=["Cancel", "Validate"], close_label="MYClose", ) expected_list = [ "<Dialog", 'page="page_test"', 'title="Another Dialog"', 'labels="["Cancel", "Validate"]"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', 'closeLabel="MYClose"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_menu_builder(gui: Gui, test_client, helpers): gui._bind_var_val("lov", ["Item 1", "Item 2", "Item 3", "Item 4"]) with tgb.Page(frame=None) as page: tgb.menu(lov="{lov}", on_action="on_menu_action") expected_list = [ "<MenuCtl", 'libClassName="taipy-menu"', 'defaultLov="["Item 1", "Item 2", "Item 3", "Item 4"]"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'onAction="on_menu_action"', 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_layout_builder_1(gui: Gui, helpers): with tgb.Page(frame=None) as page: with tgb.layout(columns="1 1", gap="1rem"): tgb.text(value="This is a layout section") expected_list = ["<Layout", 'columns="1 1', 'gap="1rem"', "This is a layout section"] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_number_builder_1(gui: Gui, helpers): with tgb.Page(frame=None) as page: tgb.number(value="10") expected_list = ["<Input", 'value="10"', 'type="number"'] helpers.test_control_builder(gui, page, expected_list) def test_number_builder_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", "10") with tgb.Page(frame=None) as page: tgb.number(value="{x}") expected_list = [ "<Input", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', 'defaultValue="10"', 'type="number"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) |
from datetime import datetime import taipy.gui.builder as tgb from taipy.gui import Gui def test_date_builder_1(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) with tgb.Page(frame=None) as page: tgb.date(id="date", date="{date}") expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) def test_date_builder_2(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) with tgb.Page(frame=None) as page: tgb.date(id="date", date="{date}", with_time=True) expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", "withTime={true}", ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_indicator_builder(gui: Gui, test_client, helpers): gui._bind_var_val("val", 15) with tgb.Page(frame=None) as page: tgb.indicator(display=12, value="{val}", min=1, max=20, format="%.2f") expected_list = [ "<Indicator", 'libClassName="taipy-indicator"', "defaultValue={15}", "display={12.0}", 'format="%.2f"', "max={20.0}", "min={1.0}", "value={_TpN_tpec_TpExPr_val_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_navbar_builder(gui: Gui, test_client, helpers): gui._bind_var_val( "navlov", [ ("/page1", "Page 1"), ("/page2", "Page 2"), ("/page3", "Page 3"), ("/page4", "Page 4"), ], ) with tgb.Page(frame=None) as page: tgb.navbar(lov="{navlov}") expected_list = [ "<NavBar", 'defaultLov="[["/page1", "Page 1"], ["/page2", "Page 2"], ["/page3", "Page 3"], ["/page4", "Page 4"]]"', "lov={_TpL_tpec_TpExPr_navlov_TPMDL_0}", ] helpers.test_control_builder(gui, page, expected_list) |
import datetime import inspect import random import typing as t import taipy.gui.builder as tgb from taipy.gui import Gui def test_chart_builder_1(gui: Gui, helpers, csvdata): selected_indices = [14258] # noqa: F841 subplot_layout = { # noqa: F841 "grid": {"rows": 1, "columns": 2, "subplots": [["xy", "x2y"]], "roworder": "bottom to top"} } y = ["Daily hospital occupancy", "Daily hospital occupancy"] # noqa: F841 label = ["Entity", "Code"] # noqa: F841 mode = [None, "markers"] # noqa: F841 color = [None, "red"] # noqa: F841 chart_type = [None, "scatter"] # noqa: F841 xaxis = [None, "x2"] # noqa: F841 with tgb.Page(frame=None) as page: tgb.chart( data="{csvdata}", x="Day", selected_color="green", y="{y}", label="{label}", mode="{mode}", color="{color}", type="{chart_type}", xaxis="{xaxis}", layout="{subplot_layout}", on_range_change="range_change", width="100%", height="100%", selected="{selected_indices}", ) expected_list = [ "<Chart", "selected0={tpec_TpExPr_selected_indices_TPMDL_0}", "selected1={tpec_TpExPr_selected_indices_TPMDL_0}", 'height="100%"', 'defaultLayout="{"grid": {"rows": 1, "columns": 2, "subplots": [["xy", "x2y"]], "roworder": "bottom to top"}}"', 'onRangeChange="range_change"', 'updateVars="layout=_TpDi_tpec_TpExPr_subplot_layout_TPMDL_0;selected0=tpec_TpExPr_selected_indices_TPMDL_0;selected1=tpec_TpExPr_selected_indices_TPMDL_0"', 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", 'width="100%"', ] gui._set_frame(inspect.currentframe()) helpers.test_control_builder(gui, page, expected_list) def test_chart_builder_2(gui: Gui, helpers, csvdata): selected_indices = [14258] # noqa: F841 with tgb.Page(frame=None) as page: tgb.chart( data="{csvdata}", x="Day", selected_color="green", y=["Daily hospital occupancy", "Daily hospital occupancy"], label=["Entity", "Code"], mode=[None, "markers"], color=[None, "red"], type=(None, "scatter"), xaxis=(None, "x2"), layout={"grid": {"rows": 1, "columns": 2, "subplots": [["xy", "x2y"]], "roworder": "bottom to top"}}, on_range_change="range_change", width="100%", height="100%", selected="{selected_indices}", ) expected_list = [ "<Chart", "selected0={tpec_TpExPr_selected_indices_TPMDL_0}", "selected1={tpec_TpExPr_selected_indices_TPMDL_0}", 'height="100%"', 'defaultLayout="{"grid": {"rows": 1, "columns": 2, "subplots": [["xy", "x2y"]], "roworder": "bottom to top"}}"', 'onRangeChange="range_change"', 'updateVars="selected0=tpec_TpExPr_selected_indices_TPMDL_0;selected1=tpec_TpExPr_selected_indices_TPMDL_0"', 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", 'width="100%"', ] gui._set_frame(inspect.currentframe()) helpers.test_control_builder(gui, page, expected_list) def test_map_builder(gui: Gui, helpers): mapData = { # noqa: F841 "Lat": [ 48.4113, 18.0057, 48.6163, 48.5379, 48.5843, 48.612, 48.6286, 48.6068, 48.4489, 48.6548, 18.5721, 48.3734, 17.6398, 48.5765, 48.4407, 48.2286, ], "Lon": [ -112.8352, -65.804, -113.4784, -114.0702, -111.0188, -110.7939, -109.4629, -114.9123, -112.9705, -113.965, -66.5401, -111.5245, -64.7246, -112.1932, -113.3159, -104.5863, ], "Globvalue": [ 0.0875, 0.0892, 0.0908, 0.0933, 0.0942, 0.095, 0.095, 0.095, 0.0958, 0.0958, 0.0958, 0.0958, 0.0958, 0.0975, 0.0983, 0.0992, ], } marker = {"color": "fuchsia", "size": 4} # noqa: F841 layout = { # noqa: F841 "dragmode": "zoom", "mapbox": {"style": "open-street-map", "center": {"lat": 38, "lon": -90}, "zoom": 3}, "margin": {"r": 0, "t": 0, "b": 0, "l": 0}, } with tgb.Page(frame=None) as page: tgb.chart( data="{mapData}", type="scattermapbox", marker="{marker}", layout="{layout}", lat="Lat", lon="Lon", text="Globvalue", mode="markers", ) gui._set_frame(inspect.currentframe()) expected_list = [ "<Chart", ""Lat": {"index":", ""Lon": {"index":", "data={_TpD_tpec_TpExPr_mapData_TPMDL_0}", 'defaultLayout="{"dragmode": "zoom", "mapbox": {"style": "open-street-map", "center": {"lat": 38, "lon": -90}, "zoom": 3}, "margin": {"r": 0, "t": 0, "b": 0, "l": 0}}"', 'updateVarName="_TpD_tpec_TpExPr_mapData_TPMDL_0"', ] helpers.test_control_builder(gui, page, expected_list) def test_chart_indexed_properties_builder(gui: Gui, helpers): data: t.Dict[str, t.Any] = {} data["Date"] = [datetime.datetime(2021, 12, i) for i in range(1, 31)] data["La Rochelle"] = [10 + 6 * random.random() for _ in range(1, 31)] data["Montpellier"] = [16 + 6 * random.random() for _ in range(1, 31)] data["Paris"] = [6 + 6 * random.random() for _ in range(1, 31)] data["La Rochelle 1"] = [x * (1 + (random.random() / 10)) for x in data["La Rochelle"]] data["La Rochelle 2"] = [x * (1 - (random.random() / 10)) for x in data["La Rochelle"]] data["Montpellier 1"] = [x * (1 + (random.random() / 10)) for x in data["Montpellier"]] data["Montpellier 2"] = [x * (1 - (random.random() / 10)) for x in data["Montpellier"]] with tgb.Page(frame=None) as page: tgb.chart( data="{data}", x="Date", mode="lines", y=["La Rochelle", "La Rochelle 1", "La Rochelle 2", "Montpellier", "Montpellier 1", "Montpellier 2"], line=[None, "dashdot", "dash", None, "dashdot", "dash"], color=[None, "blue", "blue", None, "red", "red"], ) gui._set_frame(inspect.currentframe()) expected_list = [ "<Chart", ""traces": [["Date_str", "La Rochelle"], ["Date_str", "La Rochelle 1"], ["Date_str", "La Rochelle 2"], ["Date_str", "Montpellier"], ["Date_str", "Montpellier 1"], ["Date_str", "Montpellier 2"]]", ""lines": [null, {"dash": "dashdot"}, {"dash": "dash"}, null, {"dash": "dashdot"}, {"dash": "dash"}]", ] helpers.test_control_builder(gui, page, expected_list) def test_chart_indexed_properties_with_arrays_builder(gui: Gui, helpers): data: t.Dict[str, t.Any] = {} data["Date"] = [datetime.datetime(2021, 12, i) for i in range(1, 31)] data["La Rochelle"] = [10 + 6 * random.random() for _ in range(1, 31)] data["Montpellier"] = [16 + 6 * random.random() for _ in range(1, 31)] data["Paris"] = [6 + 6 * random.random() for _ in range(1, 31)] data["La Rochelle 1"] = [x * (1 + (random.random() / 10)) for x in data["La Rochelle"]] data["La Rochelle 2"] = [x * (1 - (random.random() / 10)) for x in data["La Rochelle"]] data["Montpellier 1"] = [x * (1 + (random.random() / 10)) for x in data["Montpellier"]] data["Montpellier 2"] = [x * (1 - (random.random() / 10)) for x in data["Montpellier"]] ys = [ # noqa: F841 "La Rochelle", "La Rochelle 1", "La Rochelle 2", "Montpellier", "Montpellier 1", "Montpellier 2", ] lines = [None, "dashdot", "dash", None, "dashdot", "dash"] # noqa: F841 colors = [None, "blue", "blue", None, "red", "red"] # noqa: F841 with tgb.Page(frame=None) as page: tgb.chart( data="{data}", x="Date", mode="lines", y="{ys}", line="{lines}", color="{colors}", ) gui._set_frame(inspect.currentframe()) expected_list = [ "<Chart", ""traces": [["Date_str", "La Rochelle"], ["Date_str", "La Rochelle 1"], ["Date_str", "La Rochelle 2"], ["Date_str", "Montpellier"], ["Date_str", "Montpellier 1"], ["Date_str", "Montpellier 2"]]", ""lines": [null, {"dash": "dashdot"}, {"dash": "dash"}, null, {"dash": "dashdot"}, {"dash": "dash"}]", ] helpers.test_control_builder(gui, page, expected_list) |
import taipy.gui.builder as tgb from taipy.gui import Gui def test_part_builder_1(gui: Gui, helpers): with tgb.Page(frame=None) as page: with tgb.part(class_name="class1"): tgb.text(value="This is a part") expected_list = ["<Part", "This is a part"] helpers.test_control_builder(gui, page, expected_list) |
import inspect from taipy.gui import Gui def test_slider_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) md_string = "<|{x}|slider|>" expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0', "defaultValue={10}", "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_with_min_max(gui: Gui, test_client, helpers): gui._bind_var_val("x", 0) md_string = "<|{x}|slider|min=-10|max=10|>" expected_list = ["<Slider", "min={-10.0}", "max={10.0}", "defaultValue={0}"] helpers.test_control_md(gui, md_string, expected_list) def test_slider_with_dict_labels_md(gui: Gui, helpers): sel = "Item 1" # noqa: F841 labels = {"Item 1": "Label Start", "Item 3": "Label End"} # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|{sel}|slider|lov=Item 1;Item 2;Item 3|labels={labels}|>" expected_list = [ "<Slider", 'labels="{"Item 1": "Label Start", "Item 3": "Label End"}"', ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_with_boolean_labels_md(gui: Gui, helpers): sel = "Item 1" # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|{sel}|slider|lov=Item 1;Item 2;Item 3|labels|>" expected_list = ["<Slider", "labels={true}"] helpers.test_control_md(gui, md_string, expected_list) def test_slider_items_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") md_string = "<|{x}|slider|lov=Item 1;Item 2;Item 3|text_anchor=left|>" expected_list = [ "<Slider", 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"', "value={_TpLv_tpec_TpExPr_x_TPMDL_0}", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'textAnchor="left"', ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_text_anchor_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") md_string = "<|{x}|slider|text_anchor=NoNe|>" expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", 'textAnchor="none"', ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_text_anchor_default_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", "Item 1") md_string = "<|{x}|slider|items=Item 1|>" expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", 'textAnchor="bottom"', ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_array_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", [10, 20]) md_string = "<|{x}|slider|>" expected_list = [ "<Slider", 'updateVarName="_TpLn_tpec_TpExPr_x_TPMDL_0"', "value={_TpLn_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_slider_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = '<taipy:slider value="{x}" />' expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "defaultValue={10}", "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_slider_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = "<taipy:slider>{x}</taipy:slider>" expected_list = [ "<Slider", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', "defaultValue={10}", "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. from taipy.gui import Gui def test_button_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") md_string = "<|Hello {name}|button|id={btn_id}|>" expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_md(gui, md_string, expected_list) def test_button_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") md_string = "<|button|label=Hello {name}|id={btn_id}|>" expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_md(gui, md_string, expected_list) def test_button_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") html_string = '<taipy:button label="Hello {name}" id="{btn_id}" />' expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_html(gui, html_string, expected_list) def test_button_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("name", "World!") gui._bind_var_val("btn_id", "button1") html_string = '<taipy:button id="{btn_id}">Hello {name}</taipy:button>' expected_list = ["<Button", 'defaultLabel="Hello World!"', "label={tp_TpExPr_Hello_name_TPMDL_0_0"] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_selector_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", ["l1", "l2"]) gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True}) md_string = "<|{selected_val}|selector|properties=selector_properties|multiple|>" expected_list = [ "<Selector", 'defaultLov="[["l1", "v1"], ["l2", "v2"], ["l3", "v3"]]"', 'defaultValue="["l1", "l2"]"', "filter={true}", "multiple={true}", 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_selector_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", "Item 2") md_string = "<|{selected_val}|selector|lov=Item 1;Item 2; This is a another value|>" expected_list = [ "<Selector", 'defaultLov="["Item 1", "Item 2", " This is a another value"]"', 'defaultValue="["Item 2"]"', 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_selector_md_3(gui: Gui, test_client, helpers): gui._bind_var_val("elt", None) gui._bind_var_val( "scenario_list", [{"id": "1", "name": "scenario 1"}, {"id": "3", "name": "scenario 3"}, {"id": "2", "name": "scenario 2"}], ) gui._bind_var_val("selected_obj", {"id": "1", "name": "scenario 1"}) md_string = '<|{selected_obj}|selector|lov={scenario_list}|type=Scenario|adapter={lambda elt: (elt["id"], elt["name"])}|not propagate|>' expected_list = [ "<Selector", 'defaultLov="[["1", "scenario 1"], ["3", "scenario 3"], ["2", "scenario 2"]]"', 'defaultValue="["1"]"', "lov={_TpL_tpec_TpExPr_scenario_list_TPMDL_0}", "propagate={false}", 'updateVars="lov=_TpL_tpec_TpExPr_scenario_list_TPMDL_0"', 'updateVarName="_TpLv_tpec_TpExPr_selected_obj_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_obj_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_selector_html_1_1(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", ["l1", "l2"]) gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True}) html_string = '<taipy:selector value="{selected_val}" properties="selector_properties" multiple="True"/>' expected_list = [ "<Selector", 'defaultLov="[["l1", "v1"], ["l2", "v2"], ["l3", "v3"]]"', 'defaultValue="["l1", "l2"]"', "filter={true}", "multiple={true}", 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_selector_html_1_2(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", ["l1", "l2"]) gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True}) html_string = '<taipy:selector properties="selector_properties" multiple="True">{selected_val}</taipy:selector>' expected_list = [ "<Selector", 'defaultLov="[["l1", "v1"], ["l2", "v2"], ["l3", "v3"]]"', 'defaultValue="["l1", "l2"]"', "filter={true}", "multiple={true}", 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_selector_html_2_1(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", "Item 2") html_string = '<taipy:selector value="{selected_val}" lov="Item 1;Item 2; This is a another value" />' expected_list = [ "<Selector", 'defaultLov="["Item 1", "Item 2", " This is a another value"]"', 'defaultValue="["Item 2"]"', 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_selector_html_2_2(gui: Gui, test_client, helpers): gui._bind_var_val("selected_val", "Item 2") html_string = '<taipy:selector lov="Item 1;Item 2; This is a another value">{selected_val}</taipy:selector>' expected_list = [ "<Selector", 'defaultLov="["Item 1", "Item 2", " This is a another value"]"', 'defaultValue="["Item 2"]"', 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"', "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
import inspect from taipy.gui import Gui def test_input_md(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|{x}|input|>" expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="text"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_password_md(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|{x}|input|password|>" expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="password"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_input_html_1(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) html_string = '<taipy:input value="{x}" />' expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="text"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_password_html(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) html_string = '<taipy:input value="{x}" password="True" />' expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="password"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_input_html_2(gui: Gui, helpers): x = "Hello World!" # noqa: F841 gui._set_frame(inspect.currentframe()) html_string = "<taipy:input>{x}</taipy:input>" expected_list = [ "<Input", 'updateVarName="tpec_TpExPr_x_TPMDL_0"', 'defaultValue="Hello World!"', 'type="text"', "value={tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_tree_md(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|>" expected_list = [ "<TreeView", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_tree_expanded_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|not expanded|>" expected_list = [ "<TreeView", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", "expanded={false}", ] helpers.test_control_md(gui, md_string, expected_list) def test_tree_expanded_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") gui._bind_var_val("expa", ["Item1"]) md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|expanded={expa}|>" expected_list = [ "<TreeView", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", 'defaultExpanded="["Item1"]"', "expanded={tpec_TpExPr_expa_TPMDL_0}", 'updateVars="expanded=tpec_TpExPr_expa_TPMDL_0', ] helpers.test_control_md(gui, md_string, expected_list) def test_tree_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") html_string = '<taipy:tree lov="Item 1;Item 2;Item 3">{value}</taipy:tree>' expected_list = [ "<TreeView", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_tree_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("value", "Item 1") html_string = '<taipy:tree lov="Item 1;Item 2;Item 3" value="{value}" />' expected_list = [ "<TreeView", 'defaultLov="["Item 1", "Item 2", "Item 3"]"', 'defaultValue="["Item 1"]"', 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"', "value={_TpLv_tpec_TpExPr_value_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_expandable_md_1(gui: Gui, helpers): md_string = """ <|Expandable section|expandable|not expanded| # This is an expandable section |> """ expected_list = [ "<Expandable", "expanded={false}", 'title="Expandable section"', "<h1", "This is an expandable section", ] helpers.test_control_md(gui, md_string, expected_list) def test_expandable_md_2(gui: Gui, helpers): md_string = """ <|expandable.start|title=Expandable section|not expanded|> # This is an expandable section <|expandable.end|> """ expected_list = [ "<Expandable", "expanded={false}", 'title="Expandable section"', "<h1", "This is an expandable section", ] helpers.test_control_md(gui, md_string, expected_list) def test_expandable_html(gui: Gui, helpers): html_string = '<taipy:expandable title="Expandable section" expanded="false"><h1>This is an expandable section</h1></taipy:expandable >' expected_list = [ "<Expandable", "expanded={false}", 'title="Expandable section"', "<h1", "This is an expandable section", ] helpers.test_control_html(gui, html_string, expected_list) |
import inspect from taipy.gui import Gui def test_table_md_1(gui: Gui, helpers, csvdata): md_string = "<|{csvdata}|table|page_size=10|page_size_options=10;30;100|columns=Day;Entity;Code;Daily hospital occupancy|date_format=eee dd MMM yyyy|>" expected_list = [ "<Table", 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "type": "int", "dfid": "Daily hospital occupancy"}, "Day_str": {"index": 0, "type": "datetime", "dfid": "Day", "format": "eee dd MMM yyyy"}}"', 'height="80vh"', 'width="100%"', 'pageSizeOptions="[10, 30, 100]"', "pageSize={10.0}", "selected={[]}", 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_md(gui, md_string, expected_list) def test_table_reset_md(gui: Gui, helpers, csvdata): md_string = "<|{csvdata}|table|rebuild|page_size=10|page_size_options=10;30;100|columns=Day;Entity;Code;Daily hospital occupancy|date_format=eee dd MMM yyyy|>" expected_list = [ "<Table", 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "type": "int", "dfid": "Daily hospital occupancy"}, "Day_str": {"index": 0, "type": "datetime", "dfid": "Day", "format": "eee dd MMM yyyy"}}"', 'height="80vh"', 'width="100%"', 'pageSizeOptions="[10, 30, 100]"', "pageSize={10.0}", "selected={[]}", 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", "columns={tp_TpExPr_gui_tbl_cols_True_None_7B_22columns_22_3A_20_22Day_3BEntity_3BCode_3BDaily_20hospital_20occupancy_22_2C_20_22date_format_22_3A_20_22eee_20dd_20MMM_20yyyy_22_7D_7B_22data_22_3A_20_22tpec_TpExPr_csvdata_TPMDL_0_22_7D_tpec_TpExPr_csvdata_TPMDL_0_csvdata_TPMDL_0_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_md(gui, md_string, expected_list) def test_table_md_2(gui: Gui, helpers, csvdata): table_properties = { # noqa: F841 "page_size": 10, "page_size_options": [10, 50, 100, 500], "allow_all_rows": True, "columns": { "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"}, "Entity": {"index": 1}, "Code": {"index": 2}, "Daily hospital occupancy": {"index": 3}, }, "date_format": "eee dd MMM yyyy", "number_format": "%.3f", "width": "60vw", "height": "60vh", } md_string = "<|{csvdata}|table|properties=table_properties|auto_loading|not editable|>" expected_list = [ "<Table", "allowAllRows={true}", "autoLoading={true}", "editable={false}", 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "type": "int", "dfid": "Daily hospital occupancy", "format": "%.3f"}, "Day_str": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure", "type": "datetime", "dfid": "Day"}}"', 'height="60vh"', 'width="60vw"', 'pageSizeOptions="[10, 50, 100, 500]"', "pageSize={10}", "selected={[]}", 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_md(gui, md_string, expected_list) def test_table_html_1(gui: Gui, helpers, csvdata): html_string = '<taipy:table data="{csvdata}" page_size="10" page_size_options="10;30;100" columns="Day;Entity;Code;Daily hospital occupancy" date_format="eee dd MMM yyyy" />' expected_list = [ "<Table", 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "type": "int", "dfid": "Daily hospital occupancy"}, "Day_str": {"index": 0, "type": "datetime", "dfid": "Day", "format": "eee dd MMM yyyy"}}"', 'height="80vh"', 'width="100%"', 'pageSizeOptions="[10, 30, 100]"', "pageSize={10.0}", "selected={[]}", 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_html(gui, html_string, expected_list) def test_table_html_2(gui: Gui, helpers, csvdata): table_properties = { # noqa: F841 "page_size": 10, "page_size_options": [10, 50, 100, 500], "allow_all_rows": True, "columns": { "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"}, "Entity": {"index": 1}, "Code": {"index": 2}, "Daily hospital occupancy": {"index": 3}, }, "date_format": "eee dd MMM yyyy", "number_format": "%.3f", "width": "60vw", "height": "60vh", } html_string = '<taipy:table data="{csvdata}" properties="table_properties" auto_loading="Yes" show_all="Sure" />' expected_list = [ "<Table", "allowAllRows={true}", "autoLoading={true}", "showAll={true}", 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "type": "int", "dfid": "Daily hospital occupancy", "format": "%.3f"}, "Day_str": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure", "type": "datetime", "dfid": "Day"}}"', 'height="60vh"', 'width="60vw"', 'pageSizeOptions="[10, 50, 100, 500]"', "pageSize={10}", "selected={[]}", 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"', "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_html(gui, html_string, expected_list) |
from datetime import datetime from taipy.gui import Gui def test_date_range_md_1(gui: Gui, test_client, helpers): gui._bind_var_val( "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")] ) md_string = "<|{dates}|date_range|>" expected_list = [ "<DateRange", 'defaultDates="["2020-12-', 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"', "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_date_range_md_2(gui: Gui, test_client, helpers): gui._bind_var_val( "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")] ) md_string = "<|{dates}|date_range|with_time|label_start=start|label_end=end|>" expected_list = [ "<DateRange", 'defaultDates="["2020-12-', 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"', "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}", "withTime={true}", 'labelStart="start"', 'labelEnd="end"', ] helpers.test_control_md(gui, md_string, expected_list) def test_date_range_html_1(gui: Gui, test_client, helpers): gui._bind_var_val( "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")] ) html_string = '<taipy:date_range dates="{dates}" />' expected_list = [ "<DateRange", 'defaultDates="["2020-12-', 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"', "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_date_range_html_2(gui: Gui, test_client, helpers): gui._bind_var_val( "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")] ) html_string = "<taipy:date_range>{dates}</taipy:date_range>" expected_list = [ "<DateRange", 'defaultDates="["2020-12-', 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"', "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
import os import pathlib from importlib import util from taipy.gui import Gui def test_image_url_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") md_string = "<|{content}|image|>" expected_list = [ "<Image", "content={_TpCi_tpec_TpExPr_content_TPMDL_0}", 'defaultContent="some_url"', ] helpers.test_control_md(gui, md_string, expected_list) def test_image_file_md(gui: Gui, test_client, helpers): with open((pathlib.Path(__file__).parent.parent / "resources" / "fred.png").resolve(), "rb") as content: gui._bind_var_val("content", content.read()) md_string = "<|{content}|image|>" expected_list = [ "<Image", 'defaultContent="data:image/png;base64,', ] if not util.find_spec("magic"): expected_list = ["<Image", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_md(gui, md_string, expected_list) def test_image_path_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", str((pathlib.Path(__file__).parent.parent / "resources" / "fred.png").resolve())) md_string = "<|{content}|image|>" expected_list = [ "<Image", 'defaultContent="/taipy-content/taipyStatic0/fred.png', ] helpers.test_control_md(gui, md_string, expected_list) def test_image_bad_file_md(gui: Gui, test_client, helpers): with open(os.path.abspath(__file__), "rb") as content: gui._bind_var_val("content", content.read()) md_string = "<|{content}|image|>" expected_list = [ "<Image", 'defaultContent="Invalid content: text/x', ] if not util.find_spec("magic"): expected_list = ["<Image", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_md(gui, md_string, expected_list) def test_image_url_html(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") html_string = '<taipy:image content="{content}" on_action="action" />' expected_list = [ "<Image", 'defaultContent="some_url"', 'onAction="action"', ] helpers.test_control_html(gui, html_string, expected_list) |
# # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. |
import inspect from taipy.gui import Gui def test_status_md(gui: Gui, helpers): status = [{"status": "info", "message": "Info Message"}] # noqa: F841 md_string = "<|{status}|status|>" expected_list = [ "<Status", 'defaultValue="[{"status": "info", "message": "Info Message"}]"', "value={tpec_TpExPr_status_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_md(gui, md_string, expected_list) def test_status_html(gui: Gui, helpers): status = [{"status": "info", "message": "Info Message"}] # noqa: F841 html_string = '<taipy:status value="{status}" />' expected_list = [ "<Status", 'defaultValue="[{"status": "info", "message": "Info Message"}]"', "value={tpec_TpExPr_status_TPMDL_0}", ] gui._set_frame(inspect.currentframe()) helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_toggle_md(gui: Gui, helpers): md_string = "<|toggle|theme|>" expected_list = ["<Toggle", 'kind="theme"', 'unselectedValue=""'] helpers.test_control_md(gui, md_string, expected_list) def test_toggle_allow_unselected_md(gui: Gui, helpers): md_string = "<|toggle|lov=1;2|allow_unselect|>" expected_list = ["<Toggle", 'unselectedValue=""', "allowUnselect={true}"] helpers.test_control_md(gui, md_string, expected_list) def test_toggle_lov_md(gui: Gui, test_client, helpers): gui._bind_var_val("x", "l1") gui._bind_var_val("lov", [("l1", "v1"), ("l2", "v2")]) md_string = "<|{x}|toggle|lov={lov}|label=Label|>" expected_list = [ "<Toggle", 'defaultLov="[["l1", "v1"], ["l2", "v2"]]"', 'defaultValue="l1"', 'label="Label"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"', 'unselectedValue=""', "value={_TpLv_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_toggle_html_1(gui: Gui, helpers): html_string = '<taipy:toggle theme="True" />' expected_list = ["<Toggle", 'kind="theme"', 'unselectedValue=""'] helpers.test_control_html(gui, html_string, expected_list) def test_toggle_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", "l1") gui._bind_var_val("lov", [("l1", "v1"), ("l2", "v2")]) html_string = '<taipy:toggle lov="{lov}" label="Label">{x}</taipy:toggle>' expected_list = [ "<Toggle", 'defaultLov="[["l1", "v1"], ["l2", "v2"]]"', 'defaultValue="l1"', 'label="Label"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"', 'unselectedValue=""', "value={_TpLv_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_pane_md(gui: Gui, test_client, helpers): gui._bind_var_val("show_pane", False) md_string = """ <|{show_pane}|pane|not persistent| # This is a Pane |> """ expected_list = [ "<Pane", 'anchor="left"', 'updateVarName="_TpB_tpec_TpExPr_show_pane_TPMDL_0"', "open={_TpB_tpec_TpExPr_show_pane_TPMDL_0}", "<h1", "This is a Pane</h1></Pane>", ] helpers.test_control_md(gui, md_string, expected_list) def test_pane_persistent_md(gui: Gui, test_client, helpers): gui._bind_var_val("show_pane", False) md_string = """ <|{show_pane}|pane|persistent| # This is a Pane |> """ expected_list = [ "<Pane", 'anchor="left"', "persistent={true}", 'updateVarName="_TpB_tpec_TpExPr_show_pane_TPMDL_0"', "open={_TpB_tpec_TpExPr_show_pane_TPMDL_0}", "<h1", "This is a Pane</h1></Pane>", ] helpers.test_control_md(gui, md_string, expected_list) def test_pane_html(gui: Gui, test_client, helpers): gui._bind_var_val("show_pane", False) html_string = '<taipy:pane open="{show_pane}" persistent="false"><h1>This is a Pane</h1></taipy:pane>' expected_list = [ "<Pane", 'anchor="left"', 'updateVarName="_TpB_tpec_TpExPr_show_pane_TPMDL_0"', "open={_TpB_tpec_TpExPr_show_pane_TPMDL_0}", "<h1", "This is a Pane</h1></Pane>", ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_text_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) md_string = "<|{x}|>" expected_list = ["<Field", 'dataType="int"', 'defaultValue="10"', "value={tpec_TpExPr_x_TPMDL_0}"] helpers.test_control_md(gui, md_string, expected_list) def test_text_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = '<taipy:text value="{x}" />' expected_list = ["<Field", 'dataType="int"', 'defaultValue="10"', "value={tpec_TpExPr_x_TPMDL_0}"] helpers.test_control_html(gui, html_string, expected_list) def test_text_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = "<taipy:text>{x}</taipy:text>" expected_list = ["<Field", 'dataType="int"', 'defaultValue="10"', "value={tpec_TpExPr_x_TPMDL_0}"] helpers.test_control_html(gui, html_string, expected_list) |
import os import pathlib from importlib import util from taipy.gui import Gui def test_file_download_url_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") md_string = "<|{content}|file_download|>" expected_list = [ "<FileDownload", "content={_TpC_tpec_TpExPr_content_TPMDL_0}", 'defaultContent="some_url"', ] helpers.test_control_md(gui, md_string, expected_list) def test_file_download_file_md(gui: Gui, test_client, helpers): with open((pathlib.Path(__file__).parent.parent / "resources" / "fred.png").resolve(), "rb") as content: gui._bind_var_val("content", content.read()) md_string = "<|{content}|file_download|>" expected_list = [ "<FileDownload", 'defaultContent="data:image/png;base64,', ] if not util.find_spec("magic"): expected_list = ["<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_md(gui, md_string, expected_list) def test_file_download_path_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", str((pathlib.Path(__file__).parent.parent / "resources" / "fred.png").resolve())) md_string = "<|{content}|file_download|>" expected_list = [ "<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/fred.png', ] helpers.test_control_md(gui, md_string, expected_list) def test_file_download_any_file_md(gui: Gui, test_client, helpers): with open(os.path.abspath(__file__), "rb") as content: gui._bind_var_val("content", content.read()) md_string = "<|{content}|file_download|>" expected_list = [ "<FileDownload", 'defaultContent="data:text/x', "python;base64,", ] if not util.find_spec("magic"): expected_list = ["<FileDownload", 'defaultContent="/taipy-content/taipyStatic0/TaiPyContent.', ".bin"] helpers.test_control_md(gui, md_string, expected_list) def test_file_download_url_html(gui: Gui, test_client, helpers): gui._bind_var_val("content", "some_url") html_string = '<taipy:file_download content="{content}" />' expected_list = [ "<FileDownload", 'defaultContent="some_url"', ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_file_selector_md(gui: Gui, test_client, helpers): gui._bind_var_val("content", None) md_string = "<|{content}|file_selector|label=label|on_action=action|>" expected_list = [ "<FileSelector", 'updateVarName="tpec_TpExPr_content_TPMDL_0"', 'label="label"', 'onAction="action"', ] helpers.test_control_md(gui, md_string, expected_list) def test_file_selector_html(gui: Gui, test_client, helpers): gui._bind_var_val("content", None) html_string = '<taipy:file_selector content="{content}" label="label" on_action="action" />' expected_list = [ "<FileSelector", 'updateVarName="tpec_TpExPr_content_TPMDL_0"', 'label="label"', 'onAction="action"', ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_content_md(gui: Gui, helpers): md_string = "<|content|>" expected_list = ["<PageContent"] helpers.test_control_md(gui, md_string, expected_list) def test_content_html(gui: Gui, helpers): html_string = "<taipy:content />" expected_list = ["<PageContent"] helpers.test_control_html(gui, html_string, expected_list) |
import inspect from taipy.gui import Gui, Markdown def test_dialog_md_1(gui: Gui, helpers): dialog_open = False # noqa: F841 gui._set_frame(inspect.currentframe()) md_string = "<|dialog|title=This is a Dialog|open={dialog_open}|page=page_test|on_action=validate_action|>" expected_list = [ "<Dialog", 'onAction="validate_action"', 'page="page_test"', 'title="This is a Dialog"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_dialog_md_2(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) partial = gui.add_partial(Markdown("# A partial")) # noqa: F841 dialog_open = False # noqa: F841 md_string = "<|dialog|title=Another Dialog|open={dialog_open}|partial={partial}|on_action=validate_action|>" expected_list = [ "<Dialog", 'page="TaiPy_partials', 'title="Another Dialog"', 'onAction="validate_action"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_dialog_labels_md(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) dialog_open = False # noqa: F841 md_string = ( "<|dialog|title=Another Dialog|open={dialog_open}|page=page_test|labels=Cancel;Validate|close_label=MYClose|>" ) expected_list = [ "<Dialog", 'page="page_test"', 'title="Another Dialog"', 'labels="["Cancel", "Validate"]"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', 'closeLabel="MYClose"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_dialog_html_1(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) dialog_open = False # noqa: F841 html_string = ( '<taipy:dialog title="This is a Dialog" open="{dialog_open}" page="page1" on_action="validate_action" />' ) expected_list = [ "<Dialog", 'page="page1"', 'title="This is a Dialog"', 'onAction="validate_action"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_dialog_html_2(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) partial = gui.add_partial(Markdown("# A partial")) # noqa: F841 dialog_open = False # noqa: F841 html_string = ( '<taipy:dialog title="Another Dialog" open="{dialog_open}" partial="{partial}" on_action="validate_action" />' ) expected_list = [ "<Dialog", 'page="TaiPy_partials', 'title="Another Dialog"', 'onAction="validate_action"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_dialog_labels_html(gui: Gui, helpers): gui._set_frame(inspect.currentframe()) dialog_open = False # noqa: F841 html_string = ( '<taipy:dialog title="Another Dialog" open="{dialog_open}" page="page_test" labels="Cancel;Validate" />' ) expected_list = [ "<Dialog", 'page="page_test"', 'title="Another Dialog"', 'labels="["Cancel", "Validate"]"', 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"', "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_menu_md(gui: Gui, test_client, helpers): gui._bind_var_val("lov", ["Item 1", "Item 2", "Item 3", "Item 4"]) md_string = "<|menu|lov={lov}|on_action=on_menu_action|>" expected_list = [ "<MenuCtl", 'libClassName="taipy-menu"', 'defaultLov="["Item 1", "Item 2", "Item 3", "Item 4"]"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'onAction="on_menu_action"', 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', ] helpers.test_control_md(gui, md_string, expected_list) def test_menu_html(gui: Gui, test_client, helpers): gui._bind_var_val("lov", ["Item 1", "Item 2", "Item 3", "Item 4"]) html_string = '<taipy:menu lov="{lov}" />' expected_list = [ "<MenuCtl", 'libClassName="taipy-menu"', 'defaultLov="["Item 1", "Item 2", "Item 3", "Item 4"]"', "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}", 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"', ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_layout_md_1(gui: Gui, helpers): md_string = """ <|layout|columns=1 1|gap=1rem| # This is a layout section |> """ expected_list = ["<Layout", 'columns="1 1', 'gap="1rem"', "<h1", "This is a layout section"] helpers.test_control_md(gui, md_string, expected_list) def test_layout_md_2(gui: Gui, helpers): md_string = """ <|layout.start|columns=1 1|gap=1rem|> # This is a layout section <|layout.end|> """ expected_list = ["<Layout", 'columns="1 1', 'gap="1rem"', "<h1", "This is a layout section"] helpers.test_control_md(gui, md_string, expected_list) def test_layout_html(gui: Gui, helpers): html_string = '<taipy:layout columns="1 1" gap="1rem"><h1>This is a layout section</h1></taipy:layout>' expected_list = ["<Layout", 'columns="1 1', 'gap="1rem"', "<h1", "This is a layout section"] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_number_md_1(gui: Gui, helpers): md_string = "<|10|number|>" expected_list = ["<Input", 'value="10"', 'type="number"'] helpers.test_control_md(gui, md_string, expected_list) def test_number_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", "10") md_string = "<|{x}|number|>" expected_list = [ "<Input", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', 'defaultValue="10"', 'type="number"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_number_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = '<taipy:number value="{x}" />' expected_list = [ "<Input", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', 'defaultValue="10"', 'type="number"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_number_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("x", 10) html_string = "<taipy:number>{x}</taipy:number>" expected_list = [ "<Input", 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"', 'defaultValue="10"', 'type="number"', "value={_TpN_tpec_TpExPr_x_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
from datetime import datetime from taipy.gui import Gui def test_date_md_1(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) md_string = "<|{date}|date|>" expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_date_md_2(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) md_string = "<|{date}|date|with_time|label=a label|>" expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", "withTime={true}", 'label="a label"', ] helpers.test_control_md(gui, md_string, expected_list) def test_date_html_1(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) html_string = '<taipy:date date="{date}" />' expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) def test_date_html_2(gui: Gui, test_client, helpers): gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y")) html_string = "<taipy:date>{date}</taipy:date>" expected_list = [ "<DateSelector", 'defaultDate="2020-12-', 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"', "date={_TpDt_tpec_TpExPr_date_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
from taipy.gui import Gui def test_indicator_md(gui: Gui, test_client, helpers): gui._bind_var_val("val", 15) md_string = "<|12|indicator|value={val}|min=1|max=20|format=%.2f|>" expected_list = [ "<Indicator", 'libClassName="taipy-indicator"', "defaultValue={15}", "display={12.0}", 'format="%.2f"', "max={20.0}", "min={1.0}", "value={_TpN_tpec_TpExPr_val_TPMDL_0}", ] helpers.test_control_md(gui, md_string, expected_list) def test_menu_html(gui: Gui, test_client, helpers): gui._bind_var_val("val", 15) html_string = '<taipy:indicator value="{val}" min="1" max="20" format="%.2f" >12</taipy:indicator>' expected_list = [ "<Indicator", 'libClassName="taipy-indicator"', "defaultValue={15}", "display={12.0}", 'format="%.2f"', "max={20.0}", "min={1.0}", "value={_TpN_tpec_TpExPr_val_TPMDL_0}", ] helpers.test_control_html(gui, html_string, expected_list) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.