Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
declearn2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Magnet
DecLearn
declearn2
Commits
b5121d0f
Verified
Commit
b5121d0f
authored
1 year ago
by
ANDREY Paul
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for 'aggregate_clients_data_info'.
parent
6c9b983d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!57
Improve tests coverage and fix test-digged bugs
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/main/test_data_info.py
+95
-0
95 additions, 0 deletions
test/main/test_data_info.py
with
95 additions
and
0 deletions
test/main/test_data_info.py
0 → 100644
+
95
−
0
View file @
b5121d0f
# coding: utf-8
# Copyright 2023 Inria (Institut National de Recherche en Informatique
# et Automatique)
#
# 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.
"""
Unit tests for
'
declearn.main.utils.aggregate_clients_data_info
'
.
"""
from
unittest
import
mock
import
pytest
from
declearn.main.utils
import
AggregationError
,
aggregate_clients_data_info
class
TestAggregateClientsDataInfo
:
"""
Unit tests for
'
declearn.main.utils.aggregate_clients_data_info
'
.
"""
def
test_with_valid_inputs
(
self
)
->
None
:
"""
Test
'
aggregate_clients_data_info
'
with valid inputs.
"""
clients_data_info
=
{
"
client_a
"
:
{
"
n_samples
"
:
10
},
"
client_b
"
:
{
"
n_samples
"
:
32
},
}
results
=
aggregate_clients_data_info
(
clients_data_info
,
{
"
n_samples
"
})
assert
results
==
{
"
n_samples
"
:
42
}
def
test_with_missing_fields
(
self
)
->
None
:
"""
Test
'
aggregate_clients_data_info
'
with some missing fields.
"""
clients_data_info
=
{
"
client_a
"
:
{
"
n_samples
"
:
10
},
"
client_b
"
:
{
"
n_samples
"
:
32
},
}
with
pytest
.
raises
(
AggregationError
):
aggregate_clients_data_info
(
clients_data_info
,
required_fields
=
{
"
n_samples
"
,
"
features_shape
"
},
)
def
test_with_invalid_values
(
self
)
->
None
:
"""
Test
'
aggregate_clients_data_info
'
with some invalid values.
"""
clients_data_info
=
{
"
client_a
"
:
{
"
n_samples
"
:
10
},
"
client_b
"
:
{
"
n_samples
"
:
-
1
},
}
with
pytest
.
raises
(
AggregationError
):
aggregate_clients_data_info
(
clients_data_info
,
required_fields
=
{
"
n_samples
"
}
)
def
test_with_incompatible_values
(
self
)
->
None
:
"""
Test
'
aggregate_clients_data_info
'
with some incompatible values.
"""
clients_data_info
=
{
"
client_a
"
:
{
"
features_shape
"
:
(
100
,)},
"
client_b
"
:
{
"
features_shape
"
:
(
128
,)},
}
with
pytest
.
raises
(
AggregationError
):
aggregate_clients_data_info
(
clients_data_info
,
required_fields
=
{
"
features_shape
"
}
)
def
test_with_unexpected_keyerror
(
self
)
->
None
:
"""
Test
'
aggregate_clients_data_info
'
with an unforeseen KeyError.
"""
with
mock
.
patch
(
"
declearn.main.utils._data_info.aggregate_data_info
"
)
as
patch_agg
:
patch_agg
.
side_effect
=
KeyError
(
"
Forced KeyError
"
)
with
pytest
.
raises
(
AggregationError
):
aggregate_clients_data_info
(
clients_data_info
=
{
"
client_a
"
:
{},
"
client_b
"
:
{}},
required_fields
=
set
(),
)
def
test_with_unexpected_exception
(
self
)
->
None
:
"""
Test
'
aggregate_clients_data_info
'
with an unforeseen Exception.
"""
with
mock
.
patch
(
"
declearn.main.utils._data_info.aggregate_data_info
"
)
as
patch_agg
:
patch_agg
.
side_effect
=
Exception
(
"
Forced Exception
"
)
with
pytest
.
raises
(
AggregationError
):
aggregate_clients_data_info
(
clients_data_info
=
{
"
client_a
"
:
{},
"
client_b
"
:
{}},
required_fields
=
set
(),
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment