conftest.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import os
  12. from pathlib import Path
  13. from unittest.mock import patch
  14. import pandas as pd # type: ignore
  15. import pytest
  16. from flask import Flask, g
  17. csv = pd.read_csv(
  18. f"{Path(Path(__file__).parent.resolve())}{os.path.sep}current-covid-patients-hospital.csv", parse_dates=["Day"]
  19. )
  20. small_dataframe_data = {"name": ["A", "B", "C"], "value": [1, 2, 3]}
  21. @pytest.fixture(scope="function")
  22. def csvdata():
  23. yield csv
  24. @pytest.fixture(scope="function")
  25. def small_dataframe():
  26. yield small_dataframe_data
  27. @pytest.fixture(scope="function")
  28. def gui(helpers):
  29. from taipy.gui import Gui
  30. gui = Gui()
  31. yield gui
  32. # Delete Gui instance and state of some classes after each test
  33. gui.stop()
  34. helpers.test_cleanup()
  35. @pytest.fixture
  36. def helpers():
  37. from .helpers import Helpers
  38. return Helpers
  39. @pytest.fixture
  40. def test_client():
  41. flask_app = Flask("Test App")
  42. # Create a test client using the Flask application configured for testing
  43. with flask_app.test_client() as testing_client:
  44. # Establish an application context
  45. with flask_app.app_context():
  46. g.client_id = "test client id"
  47. yield testing_client # this is where the testing happens!
  48. @pytest.fixture(scope="function", autouse=True)
  49. def patch_cli_args():
  50. with patch("sys.argv", ["prog"]):
  51. yield