This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow optional lov_value property (for taipy) (#970)
* allow optional lov_value property (for taipy) * black * increase coverage * black * warning --------- Co-authored-by: Fred Lefévère-Laoide <[email protected]>
- Loading branch information
1 parent
6f94aa9
commit 442001a
Showing
6 changed files
with
155 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
omit = | ||
proxy.py | ||
_gui_cli.py | ||
*tests* | ||
[report] | ||
exclude_lines = | ||
pragma: no cover | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Copyright 2023 Avaiga Private Limited | ||
# | ||
# 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 pytest | ||
from taipy.gui import Gui | ||
from taipy.gui.utils import _TaipyContent | ||
import pandas as pd | ||
import json | ||
|
||
|
||
def test__get_real_var_name(gui: Gui): | ||
res = gui._get_real_var_name("") | ||
assert isinstance(res, tuple) | ||
assert res[0] == "" | ||
assert res[1] == "" | ||
|
||
gui.run(run_server=False) | ||
with gui.get_flask_app().app_context(): | ||
with pytest.raises(NameError): | ||
res = gui._get_real_var_name(f"{_TaipyContent.get_hash()}_var") | ||
|
||
|
||
def test__get_user_instance(gui: Gui): | ||
gui.run(run_server=False) | ||
with gui.get_flask_app().app_context(): | ||
with pytest.warns(UserWarning): | ||
gui._get_user_instance("", type(None)) | ||
|
||
|
||
def test__call_broadcast_callback(gui: Gui): | ||
gui.run(run_server=False) | ||
with gui.get_flask_app().app_context(): | ||
res = gui._call_broadcast_callback(lambda s, t: t, ["Hello World"], "mine") | ||
assert res == "Hello World" | ||
|
||
with gui.get_flask_app().app_context(): | ||
with pytest.warns(UserWarning): | ||
res = gui._call_broadcast_callback(print, ["Hello World"], "mine") | ||
assert res is None | ||
|
||
|
||
def test__refresh_expr(gui: Gui): | ||
gui.run(run_server=False) | ||
with gui.get_flask_app().app_context(): | ||
res = gui._refresh_expr("var", None) | ||
assert res is None | ||
|
||
|
||
def test__tbl_cols(gui: Gui): | ||
data = pd.DataFrame({"col1": [0, 1, 2], "col2": [True, True, False]}) | ||
gui.run(run_server=False) | ||
with gui.get_flask_app().app_context(): | ||
res = gui._tbl_cols(True, None, json.dumps({}), json.dumps({"data": "data"}), data=data) | ||
d = json.loads(res) | ||
assert isinstance(d, dict) | ||
assert d["col1"]["type"] == "int" | ||
|
||
res = gui._tbl_cols(False, None, "", "") | ||
assert repr(res) == "Taipy: Do not update" | ||
|
||
|
||
def test__chart_conf(gui: Gui): | ||
data = pd.DataFrame({"col1": [0, 1, 2], "col2": [True, True, False]}) | ||
gui.run(run_server=False) | ||
with gui.get_flask_app().app_context(): | ||
res = gui._chart_conf(True, None, json.dumps({}), json.dumps({"data": "data"}), data=data) | ||
d = json.loads(res) | ||
assert isinstance(d, dict) | ||
assert d["columns"]["col1"]["type"] == "int" | ||
|
||
res = gui._chart_conf(False, None, "", "") | ||
assert repr(res) == "Taipy: Do not update" | ||
|
||
with pytest.warns(UserWarning): | ||
res = gui._chart_conf(True, None, "", "") | ||
assert repr(res) == "Taipy: Do not update" | ||
|
||
|
||
def test__get_valid_adapter_result(gui: Gui): | ||
gui.run(run_server=False) | ||
with gui.get_flask_app().app_context(): | ||
res = gui._get_valid_adapter_result(("id", "label")) | ||
assert isinstance(res, tuple) | ||
assert res[0] == "id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2023 Avaiga Private Limited | ||
# | ||
# 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 pytest | ||
from taipy.gui import Gui | ||
|
||
|
||
def test_add_shared_variables(gui: Gui): | ||
Gui.add_shared_variable("var1", "var2") | ||
assert isinstance(gui._Gui__shared_variables, list) | ||
assert len(gui._Gui__shared_variables) == 2 | ||
|
||
Gui.add_shared_variables("var1", "var2") | ||
assert len(gui._Gui__shared_variables) == 2 |