From 146e05d9422ffd5faaf97855e9389bebe490ac27 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 16 Jun 2021 13:47:53 +0100 Subject: [PATCH] Small clean-up (#417) * Remove duplicated file * Move serve tests * Fix * Update tests/conftest.py Co-authored-by: Jirka Borovec Co-authored-by: Jirka Borovec --- tests/conftest.py | 6 +-- tests/{ => core}/serve/__init__.py | 0 tests/{ => core}/serve/data/cat.jpg | Bin tests/{ => core}/serve/data/fish.jpg | Bin .../{ => core}/serve/data/imagenet_labels.txt | 0 tests/{ => core}/serve/data/number5.png | Bin tests/{ => core}/serve/models.py | 0 .../{ => core}/serve/test_compat/__init__.py | 0 .../serve/test_compat/test_cached_property.py | 0 tests/{ => core}/serve/test_components.py | 2 +- tests/{ => core}/serve/test_composition.py | 18 ++++---- tests/{ => core}/serve/test_dag/NOTICE | 0 tests/{ => core}/serve/test_dag/__init__.py | 0 .../serve/test_dag/test_optimization.py | 0 tests/{ => core}/serve/test_dag/test_order.py | 0 .../{ => core}/serve/test_dag/test_rewrite.py | 0 tests/{ => core}/serve/test_dag/test_task.py | 0 tests/{ => core}/serve/test_dag/test_utils.py | 0 .../serve/test_gridbase_validations.py | 2 +- tests/{ => core}/serve/test_integration.py | 14 +++--- tests/{ => core}/serve/test_types/__init__.py | 0 .../{ => core}/serve/test_types/test_bbox.py | 0 .../{ => core}/serve/test_types/test_image.py | 0 .../{ => core}/serve/test_types/test_label.py | 0 .../serve/test_types/test_number.py | 0 .../serve/test_types/test_repeated.py | 0 .../{ => core}/serve/test_types/test_table.py | 0 .../{ => core}/serve/test_types/test_text.py | 0 tests/core/test_integrations.py | 40 ------------------ tests/examples/test_integrations.py | 3 -- 30 files changed, 21 insertions(+), 64 deletions(-) rename tests/{ => core}/serve/__init__.py (100%) rename tests/{ => core}/serve/data/cat.jpg (100%) rename tests/{ => core}/serve/data/fish.jpg (100%) rename tests/{ => core}/serve/data/imagenet_labels.txt (100%) rename tests/{ => core}/serve/data/number5.png (100%) rename tests/{ => core}/serve/models.py (100%) rename tests/{ => core}/serve/test_compat/__init__.py (100%) rename tests/{ => core}/serve/test_compat/test_cached_property.py (100%) rename tests/{ => core}/serve/test_components.py (99%) rename tests/{ => core}/serve/test_composition.py (95%) rename tests/{ => core}/serve/test_dag/NOTICE (100%) rename tests/{ => core}/serve/test_dag/__init__.py (100%) rename tests/{ => core}/serve/test_dag/test_optimization.py (100%) rename tests/{ => core}/serve/test_dag/test_order.py (100%) rename tests/{ => core}/serve/test_dag/test_rewrite.py (100%) rename tests/{ => core}/serve/test_dag/test_task.py (100%) rename tests/{ => core}/serve/test_dag/test_utils.py (100%) rename tests/{ => core}/serve/test_gridbase_validations.py (99%) rename tests/{ => core}/serve/test_integration.py (97%) rename tests/{ => core}/serve/test_types/__init__.py (100%) rename tests/{ => core}/serve/test_types/test_bbox.py (100%) rename tests/{ => core}/serve/test_types/test_image.py (100%) rename tests/{ => core}/serve/test_types/test_label.py (100%) rename tests/{ => core}/serve/test_types/test_number.py (100%) rename tests/{ => core}/serve/test_types/test_repeated.py (100%) rename tests/{ => core}/serve/test_types/test_table.py (100%) rename tests/{ => core}/serve/test_types/test_text.py (100%) delete mode 100644 tests/core/test_integrations.py diff --git a/tests/conftest.py b/tests/conftest.py index dda30d00dc..868cd06df4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,7 +36,7 @@ def _generate_sequential_uuid(): @pytest.fixture(scope="session") def original_global_datadir(): - return pathlib.Path(os.path.realpath(__file__)).parent.joinpath("serve").joinpath("data") + return pathlib.Path(os.path.realpath(__file__)).parent / "core" / "serve" / "data" def prep_global_datadir(tmp_path_factory, original_global_datadir): @@ -69,7 +69,7 @@ def squeezenet1_1_model(): @pytest.fixture(scope="session") def lightning_squeezenet1_1_obj(): - from tests.serve.models import LightningSqueezenet + from tests.core.serve.models import LightningSqueezenet model = LightningSqueezenet() model.eval() @@ -88,7 +88,7 @@ def squeezenet_gridmodel(squeezenet1_1_model, session_global_datadir): @pytest.fixture() def lightning_squeezenet_checkpoint_path(tmp_path): - from tests.serve.models import LightningSqueezenet + from tests.core.serve.models import LightningSqueezenet model = LightningSqueezenet() state_dict = {"state_dict": model.state_dict()} diff --git a/tests/serve/__init__.py b/tests/core/serve/__init__.py similarity index 100% rename from tests/serve/__init__.py rename to tests/core/serve/__init__.py diff --git a/tests/serve/data/cat.jpg b/tests/core/serve/data/cat.jpg similarity index 100% rename from tests/serve/data/cat.jpg rename to tests/core/serve/data/cat.jpg diff --git a/tests/serve/data/fish.jpg b/tests/core/serve/data/fish.jpg similarity index 100% rename from tests/serve/data/fish.jpg rename to tests/core/serve/data/fish.jpg diff --git a/tests/serve/data/imagenet_labels.txt b/tests/core/serve/data/imagenet_labels.txt similarity index 100% rename from tests/serve/data/imagenet_labels.txt rename to tests/core/serve/data/imagenet_labels.txt diff --git a/tests/serve/data/number5.png b/tests/core/serve/data/number5.png similarity index 100% rename from tests/serve/data/number5.png rename to tests/core/serve/data/number5.png diff --git a/tests/serve/models.py b/tests/core/serve/models.py similarity index 100% rename from tests/serve/models.py rename to tests/core/serve/models.py diff --git a/tests/serve/test_compat/__init__.py b/tests/core/serve/test_compat/__init__.py similarity index 100% rename from tests/serve/test_compat/__init__.py rename to tests/core/serve/test_compat/__init__.py diff --git a/tests/serve/test_compat/test_cached_property.py b/tests/core/serve/test_compat/test_cached_property.py similarity index 100% rename from tests/serve/test_compat/test_cached_property.py rename to tests/core/serve/test_compat/test_cached_property.py diff --git a/tests/serve/test_components.py b/tests/core/serve/test_components.py similarity index 99% rename from tests/serve/test_components.py rename to tests/core/serve/test_components.py index 7899af811f..43e166d4e3 100644 --- a/tests/serve/test_components.py +++ b/tests/core/serve/test_components.py @@ -3,7 +3,7 @@ from flash.core.serve.types import Label from flash.core.utilities.imports import _SERVE_AVAILABLE, _TORCHVISION_AVAILABLE -from tests.serve.models import ClassificationInferenceComposable, LightningSqueezenet +from tests.core.serve.models import ClassificationInferenceComposable, LightningSqueezenet @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") diff --git a/tests/serve/test_composition.py b/tests/core/serve/test_composition.py similarity index 95% rename from tests/serve/test_composition.py rename to tests/core/serve/test_composition.py index 48ac9656e6..803448b511 100644 --- a/tests/serve/test_composition.py +++ b/tests/core/serve/test_composition.py @@ -12,7 +12,7 @@ @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_composit_endpoint_data(lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInferenceComposable + from tests.core.serve.models import ClassificationInferenceComposable comp = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) composit = Composition(comp=comp) @@ -64,7 +64,7 @@ def test_composit_endpoint_data(lightning_squeezenet1_1_obj): @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_endpoint_errors_on_wrong_key_name(lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInferenceComposable + from tests.core.serve.models import ClassificationInferenceComposable comp1 = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) @@ -149,7 +149,7 @@ def test_composition_recieve_wrong_arg_type(lightning_squeezenet1_1_obj): _ = Composition(hello="world") # no endpoints multiple components - from tests.serve.models import ClassificationInferenceComposable + from tests.core.serve.models import ClassificationInferenceComposable comp1 = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) comp2 = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) @@ -160,7 +160,7 @@ def test_composition_recieve_wrong_arg_type(lightning_squeezenet1_1_obj): @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_gridmodel_sequence(tmp_path, lightning_squeezenet1_1_obj, squeezenet_gridmodel): - from tests.serve.models import ClassificationInferenceModelSequence + from tests.core.serve.models import ClassificationInferenceModelSequence squeezenet_gm, _ = squeezenet_gridmodel model_seq = [squeezenet_gm, squeezenet_gm] @@ -174,7 +174,7 @@ def test_gridmodel_sequence(tmp_path, lightning_squeezenet1_1_obj, squeezenet_gr @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_gridmodel_mapping(tmp_path, lightning_squeezenet1_1_obj, squeezenet_gridmodel): - from tests.serve.models import ClassificationInferenceModelMapping + from tests.core.serve.models import ClassificationInferenceModelMapping squeezenet_gm, _ = squeezenet_gridmodel model_map = {"model_one": squeezenet_gm, "model_two": squeezenet_gm} @@ -188,7 +188,7 @@ def test_gridmodel_mapping(tmp_path, lightning_squeezenet1_1_obj, squeezenet_gri @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_invalid_gridmodel_composition(tmp_path, lightning_squeezenet1_1_obj, squeezenet_gridmodel): - from tests.serve.models import ClassificationInferenceModelMapping + from tests.core.serve.models import ClassificationInferenceModelMapping squeezenet_gm, _ = squeezenet_gridmodel @@ -202,7 +202,7 @@ def test_invalid_gridmodel_composition(tmp_path, lightning_squeezenet1_1_obj, sq @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_complex_spec_single_endpoint(tmp_path, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInferenceComposable + from tests.core.serve.models import ClassificationInferenceComposable comp1 = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) comp2 = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) @@ -253,7 +253,7 @@ def test_complex_spec_single_endpoint(tmp_path, lightning_squeezenet1_1_obj): @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_complex_spec_multiple_endpoints(tmp_path, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInferenceComposable + from tests.core.serve.models import ClassificationInferenceComposable comp1 = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) comp2 = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) @@ -329,7 +329,7 @@ def test_complex_spec_multiple_endpoints(tmp_path, lightning_squeezenet1_1_obj): @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_start_server_from_composition(tmp_path, squeezenet_gridmodel, session_global_datadir): - from tests.serve.models import ClassificationInferenceComposable + from tests.core.serve.models import ClassificationInferenceComposable squeezenet_gm, _ = squeezenet_gridmodel comp1 = ClassificationInferenceComposable(squeezenet_gm) diff --git a/tests/serve/test_dag/NOTICE b/tests/core/serve/test_dag/NOTICE similarity index 100% rename from tests/serve/test_dag/NOTICE rename to tests/core/serve/test_dag/NOTICE diff --git a/tests/serve/test_dag/__init__.py b/tests/core/serve/test_dag/__init__.py similarity index 100% rename from tests/serve/test_dag/__init__.py rename to tests/core/serve/test_dag/__init__.py diff --git a/tests/serve/test_dag/test_optimization.py b/tests/core/serve/test_dag/test_optimization.py similarity index 100% rename from tests/serve/test_dag/test_optimization.py rename to tests/core/serve/test_dag/test_optimization.py diff --git a/tests/serve/test_dag/test_order.py b/tests/core/serve/test_dag/test_order.py similarity index 100% rename from tests/serve/test_dag/test_order.py rename to tests/core/serve/test_dag/test_order.py diff --git a/tests/serve/test_dag/test_rewrite.py b/tests/core/serve/test_dag/test_rewrite.py similarity index 100% rename from tests/serve/test_dag/test_rewrite.py rename to tests/core/serve/test_dag/test_rewrite.py diff --git a/tests/serve/test_dag/test_task.py b/tests/core/serve/test_dag/test_task.py similarity index 100% rename from tests/serve/test_dag/test_task.py rename to tests/core/serve/test_dag/test_task.py diff --git a/tests/serve/test_dag/test_utils.py b/tests/core/serve/test_dag/test_utils.py similarity index 100% rename from tests/serve/test_dag/test_utils.py rename to tests/core/serve/test_dag/test_utils.py diff --git a/tests/serve/test_gridbase_validations.py b/tests/core/serve/test_gridbase_validations.py similarity index 99% rename from tests/serve/test_gridbase_validations.py rename to tests/core/serve/test_gridbase_validations.py index 758ab67a56..c0601eaf01 100644 --- a/tests/serve/test_gridbase_validations.py +++ b/tests/core/serve/test_gridbase_validations.py @@ -182,7 +182,7 @@ def test_ModelComponent_raises_if_exposed_input_keys_differ_from_decorated_metho This is noted because it differes from some of the other metaclass validations which will raise an exception at class defiition time. """ - from tests.serve.models import ClassificationInference + from tests.core.serve.models import ClassificationInference class FailedExposedDecorator(ModelComponent): diff --git a/tests/serve/test_integration.py b/tests/core/serve/test_integration.py similarity index 97% rename from tests/serve/test_integration.py rename to tests/core/serve/test_integration.py index 7d76600579..c846dd1842 100644 --- a/tests/serve/test_integration.py +++ b/tests/core/serve/test_integration.py @@ -11,7 +11,7 @@ @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_resnet_18_inference_class(session_global_datadir, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInference + from tests.core.serve.models import ClassificationInference comp = ClassificationInference(lightning_squeezenet1_1_obj) composit = Composition(comp=comp, TESTING=True, DEBUG=True) @@ -39,7 +39,7 @@ def test_resnet_18_inference_class(session_global_datadir, lightning_squeezenet1 @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_start_server_with_repeated_exposed(session_global_datadir, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInferenceRepeated + from tests.core.serve.models import ClassificationInferenceRepeated comp = ClassificationInferenceRepeated(lightning_squeezenet1_1_obj) composit = Composition(comp=comp, TESTING=True, DEBUG=True) @@ -65,7 +65,7 @@ def test_start_server_with_repeated_exposed(session_global_datadir, lightning_sq @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_serving_single_component_and_endpoint_no_composition(session_global_datadir, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInference + from tests.core.serve.models import ClassificationInference comp = ClassificationInference(lightning_squeezenet1_1_obj) assert hasattr(comp.inputs, "img") @@ -172,7 +172,7 @@ def test_serving_single_component_and_endpoint_no_composition(session_global_dat @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_serving_composed(session_global_datadir, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInference, SeatClassifier + from tests.core.serve.models import ClassificationInference, SeatClassifier resnet_comp = ClassificationInference(lightning_squeezenet1_1_obj) seat_comp = SeatClassifier(lightning_squeezenet1_1_obj, config={"sport": "football"}) @@ -237,7 +237,7 @@ def test_serving_composed(session_global_datadir, lightning_squeezenet1_1_obj): @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_composed_does_not_eliminate_endpoint_serialization(session_global_datadir, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInference, SeatClassifier + from tests.core.serve.models import ClassificationInference, SeatClassifier resnet_comp = ClassificationInference(lightning_squeezenet1_1_obj) seat_comp = SeatClassifier(lightning_squeezenet1_1_obj, config={"sport": "football"}) @@ -323,7 +323,7 @@ def test_composed_does_not_eliminate_endpoint_serialization(session_global_datad @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_endpoint_overwrite_connection_dag(session_global_datadir, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInference, SeatClassifier + from tests.core.serve.models import ClassificationInference, SeatClassifier resnet_comp = ClassificationInference(lightning_squeezenet1_1_obj) seat_comp = SeatClassifier(lightning_squeezenet1_1_obj, config={"sport": "football"}) @@ -463,7 +463,7 @@ def test_endpoint_overwrite_connection_dag(session_global_datadir, lightning_squ @pytest.mark.skipif(not (_SERVE_AVAILABLE and _TORCHVISION_AVAILABLE), reason="serve libraries aren't installed.") def test_cycle_in_connection_fails(session_global_datadir, lightning_squeezenet1_1_obj): - from tests.serve.models import ClassificationInferenceComposable + from tests.core.serve.models import ClassificationInferenceComposable c1 = ClassificationInferenceComposable(lightning_squeezenet1_1_obj) diff --git a/tests/serve/test_types/__init__.py b/tests/core/serve/test_types/__init__.py similarity index 100% rename from tests/serve/test_types/__init__.py rename to tests/core/serve/test_types/__init__.py diff --git a/tests/serve/test_types/test_bbox.py b/tests/core/serve/test_types/test_bbox.py similarity index 100% rename from tests/serve/test_types/test_bbox.py rename to tests/core/serve/test_types/test_bbox.py diff --git a/tests/serve/test_types/test_image.py b/tests/core/serve/test_types/test_image.py similarity index 100% rename from tests/serve/test_types/test_image.py rename to tests/core/serve/test_types/test_image.py diff --git a/tests/serve/test_types/test_label.py b/tests/core/serve/test_types/test_label.py similarity index 100% rename from tests/serve/test_types/test_label.py rename to tests/core/serve/test_types/test_label.py diff --git a/tests/serve/test_types/test_number.py b/tests/core/serve/test_types/test_number.py similarity index 100% rename from tests/serve/test_types/test_number.py rename to tests/core/serve/test_types/test_number.py diff --git a/tests/serve/test_types/test_repeated.py b/tests/core/serve/test_types/test_repeated.py similarity index 100% rename from tests/serve/test_types/test_repeated.py rename to tests/core/serve/test_types/test_repeated.py diff --git a/tests/serve/test_types/test_table.py b/tests/core/serve/test_types/test_table.py similarity index 100% rename from tests/serve/test_types/test_table.py rename to tests/core/serve/test_types/test_table.py diff --git a/tests/serve/test_types/test_text.py b/tests/core/serve/test_types/test_text.py similarity index 100% rename from tests/serve/test_types/test_text.py rename to tests/core/serve/test_types/test_text.py diff --git a/tests/core/test_integrations.py b/tests/core/test_integrations.py deleted file mode 100644 index 1dea0a9a81..0000000000 --- a/tests/core/test_integrations.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright The PyTorch Lightning team. -# -# 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 -import subprocess -import sys -from pathlib import Path -from typing import List, Optional, Tuple -from unittest import mock - -import pytest - -from flash.core.utilities.imports import _FIFTYONE_AVAILABLE -from tests.examples.utils import run_test - -root = Path(__file__).parent.parent.parent - - -@mock.patch.dict(os.environ, {"FLASH_TESTING": "1"}) -@pytest.mark.parametrize( - "folder, file", [ - pytest.param( - "fiftyone", - "image_classification.py", - marks=pytest.mark.skipif(not _FIFTYONE_AVAILABLE, reason="fiftyone library isn't installed") - ), - ] -) -def test_integrations(tmpdir, folder, file): - run_test(str(root / "flash_examples" / "integrations" / folder / file)) diff --git a/tests/examples/test_integrations.py b/tests/examples/test_integrations.py index 1dea0a9a81..5d74d392f9 100644 --- a/tests/examples/test_integrations.py +++ b/tests/examples/test_integrations.py @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os -import subprocess -import sys from pathlib import Path -from typing import List, Optional, Tuple from unittest import mock import pytest