From b9ab03c98000c66489baacef1c8b3aa2103be841 Mon Sep 17 00:00:00 2001 From: Adam Narozniak Date: Mon, 16 Dec 2024 16:13:40 +0100 Subject: [PATCH 1/4] Move tests to the tests directory --- datasets/tests/__init__.py | 15 +++++++++++++++ datasets/tests/common/__init__.py | 15 +++++++++++++++ .../common/telemetry_test.py | 0 .../federated_dataset_test.py | 6 +++--- datasets/tests/metrics/__init__.py | 15 +++++++++++++++ .../metrics/utils_test.py | 0 .../{flwr_datasets => tests}/mock_utils_test.py | 0 datasets/tests/partitioner/__init__.py | 15 +++++++++++++++ .../partitioner/dirichlet_partitioner_test.py | 0 .../partitioner/distribution_partitioner_test.py | 0 .../grouped_natural_id_partitioner_test.py | 0 .../id_to_size_fnc_partitioner_test.py | 0 .../partitioner/iid_partitioner_test.py | 0 .../inner_dirichlet_partitioner_test.py | 0 .../partitioner/natural_id_partitioner_test.py | 0 .../partitioner/partitioner_test.py | 0 .../partitioner/pathological_partitioner_test.py | 0 .../partitioner/shard_partitioner_test.py | 0 .../partitioner/size_partitioner_test.py | 0 datasets/tests/preprocessor/__init__.py | 15 +++++++++++++++ .../preprocessor/divider_test.py | 0 .../preprocessor/merger_test.py | 0 datasets/{flwr_datasets => tests}/utils_test.py | 0 23 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 datasets/tests/__init__.py create mode 100644 datasets/tests/common/__init__.py rename datasets/{flwr_datasets => tests}/common/telemetry_test.py (100%) rename datasets/{flwr_datasets => tests}/federated_dataset_test.py (99%) create mode 100644 datasets/tests/metrics/__init__.py rename datasets/{flwr_datasets => tests}/metrics/utils_test.py (100%) rename datasets/{flwr_datasets => tests}/mock_utils_test.py (100%) create mode 100644 datasets/tests/partitioner/__init__.py rename datasets/{flwr_datasets => tests}/partitioner/dirichlet_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/distribution_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/grouped_natural_id_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/id_to_size_fnc_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/iid_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/inner_dirichlet_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/natural_id_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/pathological_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/shard_partitioner_test.py (100%) rename datasets/{flwr_datasets => tests}/partitioner/size_partitioner_test.py (100%) create mode 100644 datasets/tests/preprocessor/__init__.py rename datasets/{flwr_datasets => tests}/preprocessor/divider_test.py (100%) rename datasets/{flwr_datasets => tests}/preprocessor/merger_test.py (100%) rename datasets/{flwr_datasets => tests}/utils_test.py (100%) diff --git a/datasets/tests/__init__.py b/datasets/tests/__init__.py new file mode 100644 index 000000000000..d94ad9f4e907 --- /dev/null +++ b/datasets/tests/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Flower Labs GmbH. All Rights Reserved. +# +# 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. +# ============================================================================== +"""Flower Datasets main test module.""" diff --git a/datasets/tests/common/__init__.py b/datasets/tests/common/__init__.py new file mode 100644 index 000000000000..66d6dabcdea8 --- /dev/null +++ b/datasets/tests/common/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Flower Labs GmbH. All Rights Reserved. +# +# 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. +# ============================================================================== +"""Flower Datasets common test module.""" diff --git a/datasets/flwr_datasets/common/telemetry_test.py b/datasets/tests/common/telemetry_test.py similarity index 100% rename from datasets/flwr_datasets/common/telemetry_test.py rename to datasets/tests/common/telemetry_test.py diff --git a/datasets/flwr_datasets/federated_dataset_test.py b/datasets/tests/federated_dataset_test.py similarity index 99% rename from datasets/flwr_datasets/federated_dataset_test.py rename to datasets/tests/federated_dataset_test.py index 6c12ee0e2e1a..743a448aa1b1 100644 --- a/datasets/flwr_datasets/federated_dataset_test.py +++ b/datasets/tests/federated_dataset_test.py @@ -27,12 +27,12 @@ import datasets from datasets import Dataset, DatasetDict, concatenate_datasets from flwr_datasets.federated_dataset import FederatedDataset -from flwr_datasets.mock_utils_test import ( +from flwr_datasets.partitioner import IidPartitioner, NaturalIdPartitioner, Partitioner +from flwr_datasets.preprocessor.divider import Divider +from tests.mock_utils_test import ( _load_mocked_dataset, _load_mocked_dataset_dict_by_partial_download, ) -from flwr_datasets.partitioner import IidPartitioner, NaturalIdPartitioner, Partitioner -from flwr_datasets.preprocessor.divider import Divider mocked_datasets = ["cifar100", "svhn", "sentiment140", "speech_commands"] diff --git a/datasets/tests/metrics/__init__.py b/datasets/tests/metrics/__init__.py new file mode 100644 index 000000000000..8d28b08ffe39 --- /dev/null +++ b/datasets/tests/metrics/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Flower Labs GmbH. All Rights Reserved. +# +# 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. +# ============================================================================== +"""Flower Datasets metrics test module.""" diff --git a/datasets/flwr_datasets/metrics/utils_test.py b/datasets/tests/metrics/utils_test.py similarity index 100% rename from datasets/flwr_datasets/metrics/utils_test.py rename to datasets/tests/metrics/utils_test.py diff --git a/datasets/flwr_datasets/mock_utils_test.py b/datasets/tests/mock_utils_test.py similarity index 100% rename from datasets/flwr_datasets/mock_utils_test.py rename to datasets/tests/mock_utils_test.py diff --git a/datasets/tests/partitioner/__init__.py b/datasets/tests/partitioner/__init__.py new file mode 100644 index 000000000000..bdc9153bb711 --- /dev/null +++ b/datasets/tests/partitioner/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Flower Labs GmbH. All Rights Reserved. +# +# 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. +# ============================================================================== +"""Flower Datasets partitioner test module.""" diff --git a/datasets/flwr_datasets/partitioner/dirichlet_partitioner_test.py b/datasets/tests/partitioner/dirichlet_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/dirichlet_partitioner_test.py rename to datasets/tests/partitioner/dirichlet_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/distribution_partitioner_test.py b/datasets/tests/partitioner/distribution_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/distribution_partitioner_test.py rename to datasets/tests/partitioner/distribution_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/grouped_natural_id_partitioner_test.py b/datasets/tests/partitioner/grouped_natural_id_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/grouped_natural_id_partitioner_test.py rename to datasets/tests/partitioner/grouped_natural_id_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/id_to_size_fnc_partitioner_test.py b/datasets/tests/partitioner/id_to_size_fnc_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/id_to_size_fnc_partitioner_test.py rename to datasets/tests/partitioner/id_to_size_fnc_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/iid_partitioner_test.py b/datasets/tests/partitioner/iid_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/iid_partitioner_test.py rename to datasets/tests/partitioner/iid_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/inner_dirichlet_partitioner_test.py b/datasets/tests/partitioner/inner_dirichlet_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/inner_dirichlet_partitioner_test.py rename to datasets/tests/partitioner/inner_dirichlet_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/natural_id_partitioner_test.py b/datasets/tests/partitioner/natural_id_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/natural_id_partitioner_test.py rename to datasets/tests/partitioner/natural_id_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/partitioner_test.py b/datasets/tests/partitioner/partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/partitioner_test.py rename to datasets/tests/partitioner/partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/pathological_partitioner_test.py b/datasets/tests/partitioner/pathological_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/pathological_partitioner_test.py rename to datasets/tests/partitioner/pathological_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/shard_partitioner_test.py b/datasets/tests/partitioner/shard_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/shard_partitioner_test.py rename to datasets/tests/partitioner/shard_partitioner_test.py diff --git a/datasets/flwr_datasets/partitioner/size_partitioner_test.py b/datasets/tests/partitioner/size_partitioner_test.py similarity index 100% rename from datasets/flwr_datasets/partitioner/size_partitioner_test.py rename to datasets/tests/partitioner/size_partitioner_test.py diff --git a/datasets/tests/preprocessor/__init__.py b/datasets/tests/preprocessor/__init__.py new file mode 100644 index 000000000000..b6cf021a713a --- /dev/null +++ b/datasets/tests/preprocessor/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Flower Labs GmbH. All Rights Reserved. +# +# 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. +# ============================================================================== +"""Flower Datasets processor test module.""" diff --git a/datasets/flwr_datasets/preprocessor/divider_test.py b/datasets/tests/preprocessor/divider_test.py similarity index 100% rename from datasets/flwr_datasets/preprocessor/divider_test.py rename to datasets/tests/preprocessor/divider_test.py diff --git a/datasets/flwr_datasets/preprocessor/merger_test.py b/datasets/tests/preprocessor/merger_test.py similarity index 100% rename from datasets/flwr_datasets/preprocessor/merger_test.py rename to datasets/tests/preprocessor/merger_test.py diff --git a/datasets/flwr_datasets/utils_test.py b/datasets/tests/utils_test.py similarity index 100% rename from datasets/flwr_datasets/utils_test.py rename to datasets/tests/utils_test.py From 2e86bcf2b1a7c9a0b3c1a387eed7b44c5215130c Mon Sep 17 00:00:00 2001 From: Adam Narozniak Date: Mon, 16 Dec 2024 16:13:51 +0100 Subject: [PATCH 2/4] Update scripts --- datasets/dev/format.sh | 12 ++++++------ datasets/dev/test.sh | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/datasets/dev/format.sh b/datasets/dev/format.sh index b7dca9accabf..4b902161446b 100755 --- a/datasets/dev/format.sh +++ b/datasets/dev/format.sh @@ -20,15 +20,15 @@ cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/../ # Python echo "Formatting started: Python" -python -m isort flwr_datasets/ -python -m black -q flwr_datasets/ -python -m docformatter -i -r flwr_datasets/ -python -m ruff check --fix flwr_datasets/ +python -m isort flwr_datasets/ tests/ +python -m black -q flwr_datasets/ tests/ +python -m docformatter -i -r flwr_datasets/ tests/ +python -m ruff check --fix flwr_datasets/ tests/ echo "Formatting done: Python" # Notebooks echo "Formatting started: Notebooks" -python -m black --ipynb -q doc/source/*.ipynb +python -m black --ipynb -q docs/source/*.ipynb KEYS="metadata.celltoolbar metadata.language_info metadata.toc metadata.notify_time metadata.varInspector metadata.accelerator metadata.vscode cell.metadata.id cell.metadata.heading_collapsed cell.metadata.hidden cell.metadata.code_folding cell.metadata.tags cell.metadata.init_cell cell.metadata.vscode cell.metadata.pycharm" -python -m nbstripout --keep-output doc/source/*.ipynb --extra-keys "$KEYS" +python -m nbstripout --keep-output docs/source/*.ipynb --extra-keys "$KEYS" echo "Formatting done: Notebooks" diff --git a/datasets/dev/test.sh b/datasets/dev/test.sh index babb5a3cdd36..78a6f03ffbc0 100755 --- a/datasets/dev/test.sh +++ b/datasets/dev/test.sh @@ -11,39 +11,40 @@ echo "=== test.sh ===" echo "- Start Python checks" echo "- isort: start" -python -m isort --check-only flwr_datasets/ +python -m isort --check-only flwr_datasets/ tests/ echo "- isort: done" echo "- black: start" -python -m black --check flwr_datasets/ +python -m black --check flwr_datasets/ tests/ echo "- black: done" echo "- init_py_check: start" -python -m flwr_tool.init_py_check flwr_datasets/ +python -m flwr_tool.init_py_check flwr_datasets/ tests/ echo "- init_py_check: done" echo "- docformatter: start" -python -m docformatter -c -r flwr_datasets/ +python -m docformatter -c -r flwr_datasets/ tests/ echo "- docformatter: done" echo "- ruff: start" -python -m ruff check flwr_datasets/ +python -m ruff check flwr_datasets/ tests/ echo "- ruff: done" echo "- mypy: start" -python -m mypy flwr_datasets/ +python -m mypy flwr_datasets/ tests/ echo "- mypy: done" echo "- pylint: start" -python -m pylint flwr_datasets/ +python -m pylint flwr_datasets/ tests/ echo "- pylint: done" echo "- flake8: start" -python -m flake8 flwr_datasets/ +python -m flake8 flwr_datasets/ tests/ echo "- flake8: done" echo "- pytest: start" -python -m pytest flwr_datasets/ +cd tests/ +python -m pytest. echo "- pytest: done" echo "- All Python checks passed" From 7a7fd016e2c6909cc5a64bac43ec1b44c0e7d70a Mon Sep 17 00:00:00 2001 From: Adam Narozniak Date: Mon, 16 Dec 2024 16:15:39 +0100 Subject: [PATCH 3/4] Update test references in pyproject.toml --- datasets/pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datasets/pyproject.toml b/datasets/pyproject.toml index 2d699c5e901b..a481e5e6ff65 100644 --- a/datasets/pyproject.toml +++ b/datasets/pyproject.toml @@ -47,7 +47,7 @@ packages = [ { include = "flwr_datasets", from = "./" }, ] exclude = [ - "./**/*_test.py", + "./tests/**", ] [tool.poetry.dependencies] @@ -99,7 +99,7 @@ disable = "duplicate-code,too-few-public-methods,useless-import-alias" minversion = "6.2" addopts = "-qq" testpaths = [ - "./", + "./tests/", ] [tool.mypy] From d2c20e2f3dc254b58ee71c846c88efb3bf71d610 Mon Sep 17 00:00:00 2001 From: Adam Narozniak Date: Tue, 17 Dec 2024 12:37:45 +0100 Subject: [PATCH 4/4] Update pytest starting --- datasets/dev/test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/datasets/dev/test.sh b/datasets/dev/test.sh index 78a6f03ffbc0..f1309313a246 100755 --- a/datasets/dev/test.sh +++ b/datasets/dev/test.sh @@ -43,8 +43,7 @@ python -m flake8 flwr_datasets/ tests/ echo "- flake8: done" echo "- pytest: start" -cd tests/ -python -m pytest. +python -m pytest tests/ echo "- pytest: done" echo "- All Python checks passed"