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
89c807bb
Verified
Commit
89c807bb
authored
1 year ago
by
ANDREY Paul
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for some quickrun backend utils.
parent
474f5447
No related branches found
No related tags found
1 merge request
!57
Improve tests coverage and fix test-digged bugs
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
declearn/quickrun/_parser.py
+3
-3
3 additions, 3 deletions
declearn/quickrun/_parser.py
declearn/quickrun/_run.py
+22
-9
22 additions, 9 deletions
declearn/quickrun/_run.py
test/quickrun/test_utils.py
+153
-0
153 additions, 0 deletions
test/quickrun/test_utils.py
with
178 additions
and
12 deletions
declearn/quickrun/_parser.py
+
3
−
3
View file @
89c807bb
...
...
@@ -103,8 +103,8 @@ def parse_data_folder(
def
get_data_folder_path
(
data_folder
:
Optional
[
str
],
root_folder
:
Optional
[
str
],
data_folder
:
Optional
[
str
]
=
None
,
root_folder
:
Optional
[
str
]
=
None
,
)
->
Path
:
"""
Return the path to a data folder.
...
...
@@ -158,7 +158,7 @@ def get_data_folder_path(
def
list_client_names
(
data_folder
:
Path
,
client_names
:
Optional
[
List
[
str
]],
client_names
:
Optional
[
List
[
str
]]
=
None
,
)
->
List
[
str
]:
"""
List client-wise subdirectories under a data folder.
...
...
This diff is collapsed.
Click to expand it.
declearn/quickrun/_run.py
+
22
−
9
View file @
89c807bb
...
...
@@ -143,19 +143,32 @@ def run_client(
def
get_toml_folder
(
config
:
str
)
->
Tuple
[
str
,
str
]:
"""
Return the path to an experiment
'
s folder and TOML config file.
Determine if provided config is a file or a directory, and return:
* The path to the TOML config file
* The path to the main folder of the experiment
Parameters
----------
config: str
Path to either a TOML config file (within an experiment folder),
or to the experiment folder containing a
"
config.toml
"
file.
Returns
-------
toml:
The path to the TOML config file.
folder:
The path to the main folder of the experiment.
Raises
------
FileNotFoundError:
If the TOML config file cannot be found based on inputs.
"""
config
=
os
.
path
.
abspath
(
config
)
if
os
.
path
.
isfile
(
config
):
toml
=
config
folder
=
os
.
path
.
dirname
(
config
)
elif
os
.
path
.
isdir
(
config
):
if
os
.
path
.
isdir
(
config
):
folder
=
config
toml
=
f
"
{
folder
}
/
config.toml
"
toml
=
os
.
path
.
join
(
folder
,
"
config.toml
"
)
else
:
toml
=
config
folder
=
os
.
path
.
dirname
(
toml
)
if
not
os
.
path
.
isfile
(
toml
):
raise
FileNotFoundError
(
f
"
Failed to find quickrun config file at
'
{
config
}
'
.
"
)
...
...
This diff is collapsed.
Click to expand it.
test/quickrun/test_utils.py
0 → 100644
+
153
−
0
View file @
89c807bb
# coding: utf-8
"""
Tests for some
'
declearn.quickrun
'
backend utils.
"""
import
os
import
pathlib
import
pytest
from
declearn.quickrun
import
parse_data_folder
from
declearn.quickrun._parser
import
(
get_data_folder_path
,
list_client_names
,
)
from
declearn.quickrun._run
import
get_toml_folder
class
TestGetTomlFolder
:
"""
Tests for
'
declearn.quickrun._run.get_toml_folder
'
.
"""
def
test_get_toml_folder_from_file
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that
'
get_toml_folder
'
works with a TOML file path.
"""
config
=
os
.
path
.
join
(
tmp_path
,
"
config.toml
"
)
with
open
(
config
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
file
:
file
.
write
(
""
)
toml
,
folder
=
get_toml_folder
(
config
)
assert
toml
==
config
assert
folder
==
tmp_path
.
as_posix
()
def
test_get_toml_folder_from_folder
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that
'
get_toml_folder
'
works with a folder path.
"""
config
=
os
.
path
.
join
(
tmp_path
,
"
config.toml
"
)
with
open
(
config
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
file
:
file
.
write
(
""
)
toml
,
folder
=
get_toml_folder
(
tmp_path
.
as_posix
())
assert
toml
==
config
assert
folder
==
tmp_path
.
as_posix
()
def
test_get_toml_folder_from_file_fails
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it fails with a path to a non-existing file.
"""
config
=
os
.
path
.
join
(
tmp_path
,
"
config.toml
"
)
with
pytest
.
raises
(
FileNotFoundError
):
get_toml_folder
(
config
)
def
test_get_toml_folder_from_folder_fails
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it fails with a folder lacking a
'
config.toml
'
file.
"""
with
pytest
.
raises
(
FileNotFoundError
):
get_toml_folder
(
tmp_path
.
as_posix
())
class
TestGetDataFolderPath
:
"""
Tests for
'
declearn.quickrun._parser.get_data_folder_path
'
.
"""
def
test_get_data_folder_path_from_data_folder
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it works with a valid
'
data_folder
'
argument.
"""
path
=
get_data_folder_path
(
data_folder
=
tmp_path
.
as_posix
())
assert
isinstance
(
path
,
pathlib
.
Path
)
assert
path
==
tmp_path
def
test_get_data_folder_path_from_root_folder
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it works with a valid
'
root_folder
'
argument.
"""
data_dir
=
os
.
path
.
join
(
tmp_path
,
"
data
"
)
os
.
makedirs
(
data_dir
)
path
=
get_data_folder_path
(
root_folder
=
tmp_path
.
as_posix
())
assert
isinstance
(
path
,
pathlib
.
Path
)
assert
path
.
as_posix
()
==
data_dir
def
test_get_data_folder_path_fails_no_inputs
(
self
,
)
->
None
:
"""
Test that it fails with no folder specification.
"""
with
pytest
.
raises
(
ValueError
):
get_data_folder_path
(
None
,
None
)
def
test_get_data_folder_path_fails_invalid_data_folder
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it fails with an invalid data_folder.
"""
missing_folder
=
os
.
path
.
join
(
tmp_path
,
"
data
"
)
with
pytest
.
raises
(
ValueError
):
get_data_folder_path
(
data_folder
=
missing_folder
)
def
test_get_data_folder_path_fails_from_root_no_data
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it fails with an invalid root_folder (no data).
"""
with
pytest
.
raises
(
ValueError
):
get_data_folder_path
(
root_folder
=
tmp_path
.
as_posix
())
def
test_get_data_folder_path_fails_from_root_multiple_data
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it fails with multiple data* under root_folder.
"""
os
.
makedirs
(
os
.
path
.
join
(
tmp_path
,
"
data_1
"
))
os
.
makedirs
(
os
.
path
.
join
(
tmp_path
,
"
data_2
"
))
with
pytest
.
raises
(
ValueError
):
get_data_folder_path
(
root_folder
=
tmp_path
.
as_posix
())
class
TestListClientNames
:
"""
Tests for the
'
declearn.quickrun._parser.list_client_names
'
function.
"""
def
test_list_client_names_from_folder
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it works with a data folder.
"""
os
.
makedirs
(
os
.
path
.
join
(
tmp_path
,
"
client_1
"
))
os
.
makedirs
(
os
.
path
.
join
(
tmp_path
,
"
client_2
"
))
names
=
list_client_names
(
tmp_path
)
assert
isinstance
(
names
,
list
)
assert
sorted
(
names
)
==
[
"
client_1
"
,
"
client_2
"
]
def
test_list_client_names_from_names
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it works with pre-specified names.
"""
os
.
makedirs
(
os
.
path
.
join
(
tmp_path
,
"
client_1
"
))
os
.
makedirs
(
os
.
path
.
join
(
tmp_path
,
"
client_2
"
))
names
=
list_client_names
(
tmp_path
,
[
"
client_2
"
])
assert
names
==
[
"
client_2
"
]
def
test_list_client_names_fails_invalid_names
(
self
,
tmp_path
:
pathlib
.
Path
,
)
->
None
:
"""
Test that it works with invalid pre-specified names.
"""
with
pytest
.
raises
(
ValueError
):
list_client_names
(
tmp_path
,
"
invalid-type
"
)
# type: ignore
with
pytest
.
raises
(
ValueError
):
list_client_names
(
tmp_path
,
[
"
client_2
"
])
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