From 706f9a027713d7dafb97fee4cb1cb4a605bf54ff Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 27 Sep 2024 13:45:26 -0300 Subject: [PATCH] refactor: update flaky tests in test_schema.py (#3933) * Fix flaky tests in `test_schema.py` by using sets for type comparisons - Updated `post_process_type` function assertions to use sets for more reliable type comparisons. - Adjusted imports for better code organization. * Fix import order in test_database.py * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/backend/tests/unit/test_database.py | 2 +- src/backend/tests/unit/test_schema.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/backend/tests/unit/test_database.py b/src/backend/tests/unit/test_database.py index 9695268a9a7..60b617545b7 100644 --- a/src/backend/tests/unit/test_database.py +++ b/src/backend/tests/unit/test_database.py @@ -2,7 +2,6 @@ from collections import namedtuple from uuid import UUID, uuid4 -from langflow.services.database.models.folder.model import FolderCreate import orjson import pytest from fastapi.testclient import TestClient @@ -13,6 +12,7 @@ from langflow.initial_setup.setup import load_flows_from_directory, load_starter_projects from langflow.services.database.models.base import orjson_dumps from langflow.services.database.models.flow import Flow, FlowCreate, FlowUpdate +from langflow.services.database.models.folder.model import FolderCreate from langflow.services.database.utils import session_getter from langflow.services.deps import get_db_service diff --git a/src/backend/tests/unit/test_schema.py b/src/backend/tests/unit/test_schema.py index 378d451b06c..b101ce60813 100644 --- a/src/backend/tests/unit/test_schema.py +++ b/src/backend/tests/unit/test_schema.py @@ -1,5 +1,5 @@ -from typing import Union from collections.abc import Sequence +from typing import Union import pytest from pydantic import ValidationError @@ -40,11 +40,11 @@ def test_validate_type_class(self): assert input_obj.field_type == "int" def test_post_process_type_function(self): - assert post_process_type(int) == [int] - assert post_process_type(list[int]) == [int] - assert post_process_type(Union[int, str]) == [int, str] - assert post_process_type(Union[int, Sequence[str]]) == [int, str] - assert post_process_type(Union[int, Sequence[int]]) == [int] + assert set(post_process_type(int)) == {int} + assert set(post_process_type(list[int])) == {int} + assert set(post_process_type(Union[int, str])) == {int, str} + assert set(post_process_type(Union[int, Sequence[str]])) == {int, str} + assert set(post_process_type(Union[int, Sequence[int]])) == {int} def test_input_to_dict(self): input_obj = Input(field_type="str") @@ -110,7 +110,7 @@ def test_list_int_type(self): assert post_process_type(list[int]) == [int] def test_union_type(self): - assert post_process_type(Union[int, str]) == [int, str] + assert set(post_process_type(Union[int, str])) == {int, str} def test_custom_type(self): class CustomType: