123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- # Copyright 2021-2025 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 os
- from pathlib import Path
- from unittest.mock import patch
- import pandas as pd # type: ignore
- import pytest
- from flask import Flask
- from taipy.gui.servers import get_request_meta, get_server_type
- csv = pd.read_csv(
- f"{Path(Path(__file__).parent.resolve())}{os.path.sep}current-covid-patients-hospital.csv", parse_dates=["Day"]
- )
- small_dataframe_data = {"name": ["A", "B", "C"], "value": [1, 2, 3]}
- @pytest.fixture(scope="function")
- def csvdata():
- yield csv
- @pytest.fixture(scope="function")
- def small_dataframe():
- yield small_dataframe_data
- @pytest.fixture(scope="function")
- def gui(helpers, gui_server):
- from taipy.gui import Gui
- gui = Gui(server=gui_server)
- yield gui
- # Delete Gui instance and state of some classes after each test
- gui.stop()
- helpers.test_cleanup()
- @pytest.fixture
- def helpers():
- from .helpers import Helpers
- return Helpers
- @pytest.fixture
- def test_client():
- if get_server_type() == "flask":
- flask_app = Flask("Test App")
- # Create a test client using the Flask application configured for testing
- with flask_app.test_client() as testing_client:
- # Establish an application context
- with flask_app.app_context():
- get_request_meta().client_id = "test client id"
- yield testing_client # this is where the testing happens!
- else:
- yield None
- @pytest.fixture(scope="function", autouse=True)
- def patch_cli_args():
- with patch("sys.argv", ["prog"]):
- yield
- @pytest.fixture(autouse=True)
- def skip_if_gui_server_is_not(request, gui_server):
- skip_marker = request.node.get_closest_marker("skip_if_not_server")
- if skip_marker and skip_marker.args[0] != gui_server:
- pytest.skip(f"Skipped because gui_server is not {gui_server}")
|