Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CADET-RDM
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IBG-1
ModSim
CADET
CADET-RDM
Commits
32e3bdde
Commit
32e3bdde
authored
1 year ago
by
Ronald Jäpel
Browse files
Options
Downloads
Patches
Plain Diff
Add test for output function
parent
3c95c348
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cadetrdm/repositories.py
+13
-13
13 additions, 13 deletions
cadetrdm/repositories.py
docs/source/user_guide/getting-started.md
+1
-0
1 addition, 0 deletions
docs/source/user_guide/getting-started.md
tests/test_git_adapter.py
+12
-4
12 additions, 4 deletions
tests/test_git_adapter.py
with
26 additions
and
17 deletions
cadetrdm/repositories.py
+
13
−
13
View file @
32e3bdde
...
@@ -600,7 +600,7 @@ class ProjectRepo(BaseRepo):
...
@@ -600,7 +600,7 @@ class ProjectRepo(BaseRepo):
print
(
"
Deprecation Warning. Setting the outputfolder manually during repo instantiation is deprecated
"
print
(
"
Deprecation Warning. Setting the outputfolder manually during repo instantiation is deprecated
"
"
and will be removed in a future update.
"
)
"
and will be removed in a future update.
"
)
self
.
output_folder
=
output_remotes
[
"
output_folder_name
"
]
self
.
_
output_folder
=
output_remotes
[
"
output_folder_name
"
]
with
open
(
repository_path
/
"
.cadet-rdm-data.json
"
,
"
r
"
)
as
handle
:
with
open
(
repository_path
/
"
.cadet-rdm-data.json
"
,
"
r
"
)
as
handle
:
metadata
=
json
.
load
(
handle
)
metadata
=
json
.
load
(
handle
)
...
@@ -609,7 +609,7 @@ class ProjectRepo(BaseRepo):
...
@@ -609,7 +609,7 @@ class ProjectRepo(BaseRepo):
print
(
f
"
Repo version
{
repo_version
}
is outdated. Current CADET-RDM version is
{
cadetrdm_version
}
\n
"
print
(
f
"
Repo version
{
repo_version
}
is outdated. Current CADET-RDM version is
{
cadetrdm_version
}
\n
"
"
Updating the repository now.
"
)
"
Updating the repository now.
"
)
self
.
_output_repo
=
OutputRepo
(
self
.
working_dir
/
self
.
output_folder
)
self
.
_output_repo
=
OutputRepo
(
self
.
working_dir
/
self
.
_
output_folder
)
self
.
_on_context_enter_commit_hash
=
None
self
.
_on_context_enter_commit_hash
=
None
self
.
_is_in_context_manager
=
False
self
.
_is_in_context_manager
=
False
...
@@ -669,7 +669,7 @@ class ProjectRepo(BaseRepo):
...
@@ -669,7 +669,7 @@ class ProjectRepo(BaseRepo):
"""
"""
project_repo_hash
=
str
(
self
.
head
.
commit
)
project_repo_hash
=
str
(
self
.
head
.
commit
)
timestamp
=
datetime
.
now
().
strftime
(
"
%Y-%m-%d_%H-%M-%S
"
)
timestamp
=
datetime
.
now
().
strftime
(
"
%Y-%m-%d_%H-%M-%S
"
)
branch_name
=
"
_
"
.
join
([
timestamp
,
self
.
output_folder
,
"
from
"
,
str
(
self
.
active_branch
),
project_repo_hash
[:
7
]])
branch_name
=
"
_
"
.
join
([
timestamp
,
self
.
_
output_folder
,
"
from
"
,
str
(
self
.
active_branch
),
project_repo_hash
[:
7
]])
return
branch_name
return
branch_name
def
check_results_master
(
self
):
def
check_results_master
(
self
):
...
@@ -694,7 +694,7 @@ class ProjectRepo(BaseRepo):
...
@@ -694,7 +694,7 @@ class ProjectRepo(BaseRepo):
self
.
output_repo
.
checkout
(
"
master
"
)
self
.
output_repo
.
checkout
(
"
master
"
)
tsv_filepath
=
self
.
working_dir
/
self
.
output_folder
/
"
log.tsv
"
tsv_filepath
=
self
.
working_dir
/
self
.
_
output_folder
/
"
log.tsv
"
df
=
pd
.
read_csv
(
tsv_filepath
,
sep
=
"
\t
"
,
header
=
0
)
df
=
pd
.
read_csv
(
tsv_filepath
,
sep
=
"
\t
"
,
header
=
0
)
# Clean up the headers
# Clean up the headers
...
@@ -752,11 +752,11 @@ class ProjectRepo(BaseRepo):
...
@@ -752,11 +752,11 @@ class ProjectRepo(BaseRepo):
:return:
:return:
"""
"""
tsv_filepath
=
self
.
working_dir
/
self
.
output_folder
/
"
log.tsv
"
tsv_filepath
=
self
.
working_dir
/
self
.
_
output_folder
/
"
log.tsv
"
if
tsv_filepath
.
exists
():
if
tsv_filepath
.
exists
():
return
return
csv_filepath
=
self
.
working_dir
/
self
.
output_folder
/
"
log.csv
"
csv_filepath
=
self
.
working_dir
/
self
.
_
output_folder
/
"
log.csv
"
if
not
csv_filepath
.
exists
():
if
not
csv_filepath
.
exists
():
# We have just initialized the repo and neither tsv nor csv exist.
# We have just initialized the repo and neither tsv nor csv exist.
return
return
...
@@ -787,7 +787,7 @@ class ProjectRepo(BaseRepo):
...
@@ -787,7 +787,7 @@ class ProjectRepo(BaseRepo):
self
.
_output_repo
.
_git
.
checkout
(
"
master
"
)
self
.
_output_repo
.
_git
.
checkout
(
"
master
"
)
logs_folderpath
=
self
.
working_dir
/
self
.
output_folder
/
"
run_history
"
/
output_branch_name
logs_folderpath
=
self
.
working_dir
/
self
.
_
output_folder
/
"
run_history
"
/
output_branch_name
if
not
logs_folderpath
.
exists
():
if
not
logs_folderpath
.
exists
():
os
.
makedirs
(
logs_folderpath
)
os
.
makedirs
(
logs_folderpath
)
...
@@ -876,7 +876,7 @@ class ProjectRepo(BaseRepo):
...
@@ -876,7 +876,7 @@ class ProjectRepo(BaseRepo):
output_json_filepath
=
self
.
working_dir
/
"
output_remotes.json
"
output_json_filepath
=
self
.
working_dir
/
"
output_remotes.json
"
with
open
(
output_json_filepath
,
"
w
"
)
as
file_handle
:
with
open
(
output_json_filepath
,
"
w
"
)
as
file_handle
:
remotes_dict
=
{
remote
.
name
:
str
(
remote
.
url
)
for
remote
in
self
.
output_repo
.
remotes
}
remotes_dict
=
{
remote
.
name
:
str
(
remote
.
url
)
for
remote
in
self
.
output_repo
.
remotes
}
json_dict
=
{
"
output_folder_name
"
:
self
.
output_folder
,
"
output_remotes
"
:
remotes_dict
}
json_dict
=
{
"
output_folder_name
"
:
self
.
_
output_folder
,
"
output_remotes
"
:
remotes_dict
}
json
.
dump
(
json_dict
,
file_handle
,
indent
=
2
)
json
.
dump
(
json_dict
,
file_handle
,
indent
=
2
)
def
download_file
(
self
,
url
,
file_path
):
def
download_file
(
self
,
url
,
file_path
):
...
@@ -927,7 +927,7 @@ class ProjectRepo(BaseRepo):
...
@@ -927,7 +927,7 @@ class ProjectRepo(BaseRepo):
source_filepath
=
self
.
output_repo
.
working_dir
/
file_path
source_filepath
=
self
.
output_repo
.
working_dir
/
file_path
target_folder
=
self
.
working_dir
/
(
self
.
output_folder
+
"
_cached
"
)
/
branch_name
target_folder
=
self
.
working_dir
/
(
self
.
_
output_folder
+
"
_cached
"
)
/
branch_name
os
.
makedirs
(
target_folder
,
exist_ok
=
True
)
os
.
makedirs
(
target_folder
,
exist_ok
=
True
)
target_filepath
=
target_folder
/
file_path
target_filepath
=
target_folder
/
file_path
...
@@ -957,14 +957,14 @@ class ProjectRepo(BaseRepo):
...
@@ -957,14 +957,14 @@ class ProjectRepo(BaseRepo):
if
sub_path
is
None
:
if
sub_path
is
None
:
return
self
.
working_dir
/
self
.
output_repo
.
working_dir
return
self
.
working_dir
/
self
.
output_repo
.
working_dir
else
:
else
:
return
self
.
working_dir
/
self
.
output_repo
.
working_dir
,
sub_path
return
self
.
working_dir
/
self
.
output_repo
.
working_dir
/
sub_path
def
remove_cached_files
(
self
):
def
remove_cached_files
(
self
):
"""
"""
Delete all previously cached results.
Delete all previously cached results.
"""
"""
if
(
self
.
working_dir
/
(
self
.
output_folder
+
"
_cached
"
)).
exists
():
if
(
self
.
working_dir
/
(
self
.
_
output_folder
+
"
_cached
"
)).
exists
():
delete_path
(
self
.
working_dir
/
(
self
.
output_folder
+
"
_cached
"
))
delete_path
(
self
.
working_dir
/
(
self
.
_
output_folder
+
"
_cached
"
))
def
test_for_correct_repo_setup
(
self
):
def
test_for_correct_repo_setup
(
self
):
"""
"""
...
@@ -1024,7 +1024,7 @@ class ProjectRepo(BaseRepo):
...
@@ -1024,7 +1024,7 @@ class ProjectRepo(BaseRepo):
previous_branch
=
self
.
output_repo
.
active_branch
.
name
previous_branch
=
self
.
output_repo
.
active_branch
.
name
self
.
output_repo
.
checkout
(
branch_name
)
self
.
output_repo
.
checkout
(
branch_name
)
target_folder
=
self
.
working_dir
/
(
self
.
output_folder
+
"
_cached
"
)
/
branch_name
target_folder
=
self
.
working_dir
/
(
self
.
_
output_folder
+
"
_cached
"
)
/
branch_name
shutil
.
copytree
(
source_filepath
,
target_folder
)
shutil
.
copytree
(
source_filepath
,
target_folder
)
...
...
This diff is collapsed.
Click to expand it.
docs/source/user_guide/getting-started.md
+
1
−
0
View file @
32e3bdde
...
@@ -56,6 +56,7 @@ You can add datatypes you require by running:
...
@@ -56,6 +56,7 @@ You can add datatypes you require by running:
repo
.
output_repo
.
add_filetype_to_lfs
(
"
*.npy
"
)
repo
.
output_repo
.
add_filetype_to_lfs
(
"
*.npy
"
)
````
````
or from within the output folder:
or from within the output folder:
```
bash
```
bash
...
...
This diff is collapsed.
Click to expand it.
tests/test_git_adapter.py
+
12
−
4
View file @
32e3bdde
...
@@ -77,12 +77,20 @@ def try_commit_results_data(path_to_repo):
...
@@ -77,12 +77,20 @@ def try_commit_results_data(path_to_repo):
repo
=
ProjectRepo
(
path_to_repo
)
repo
=
ProjectRepo
(
path_to_repo
)
current_commit_number
=
count_commit_number
(
repo
.
output_repo
)
current_commit_number
=
count_commit_number
(
repo
.
output_repo
)
with
repo
.
track_results
(
results_commit_message
=
"
Add array
"
):
with
repo
.
track_results
(
results_commit_message
=
"
Add array
"
):
example_generate_results_array
(
path_to_repo
,
output_folder
=
repo
.
output_
folder
)
example_generate_results_array
(
path_to_repo
,
output_folder
=
repo
.
output_
path
)
updated_commit_number
=
count_commit_number
(
repo
.
output_repo
)
updated_commit_number
=
count_commit_number
(
repo
.
output_repo
)
assert
current_commit_number
<=
updated_commit_number
assert
current_commit_number
<=
updated_commit_number
return
str
(
repo
.
output_repo
.
active_branch
)
return
str
(
repo
.
output_repo
.
active_branch
)
def
try_output_function
(
path_to_repo
):
repo
=
ProjectRepo
(
path_to_repo
)
filepath
=
repo
.
output_path
/
"
foo
"
/
"
bar
"
assert
isinstance
(
filepath
,
Path
)
filepath
=
repo
.
output_data
(
"
foo/bar
"
)
assert
isinstance
(
filepath
,
Path
)
def
try_print_log
(
path_to_repo
):
def
try_print_log
(
path_to_repo
):
repo
=
ProjectRepo
(
path_to_repo
)
repo
=
ProjectRepo
(
path_to_repo
)
repo
.
print_output_log
()
repo
.
print_output_log
()
...
@@ -93,7 +101,7 @@ def try_commit_results_with_uncommitted_code_changes(path_to_repo):
...
@@ -93,7 +101,7 @@ def try_commit_results_with_uncommitted_code_changes(path_to_repo):
modify_code
(
path_to_repo
)
modify_code
(
path_to_repo
)
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
with
repo
.
track_results
(
results_commit_message
=
"
Add array
"
):
with
repo
.
track_results
(
results_commit_message
=
"
Add array
"
):
example_generate_results_array
(
path_to_repo
,
output_folder
=
repo
.
output_
folder
)
example_generate_results_array
(
path_to_repo
,
output_folder
=
repo
.
output_
path
)
repo
.
commit
(
"
add code to print random number
"
,
add_all
=
True
)
repo
.
commit
(
"
add code to print random number
"
,
add_all
=
True
)
...
@@ -104,7 +112,7 @@ def try_load_previous_output(path_to_repo, branch_name):
...
@@ -104,7 +112,7 @@ def try_load_previous_output(path_to_repo, branch_name):
file_path
=
"
result.csv
"
)
file_path
=
"
result.csv
"
)
previous_array
=
np
.
loadtxt
(
cached_array_path
,
delimiter
=
"
,
"
)
previous_array
=
np
.
loadtxt
(
cached_array_path
,
delimiter
=
"
,
"
)
extended_array
=
np
.
concatenate
([
previous_array
,
previous_array
])
extended_array
=
np
.
concatenate
([
previous_array
,
previous_array
])
extended_array_file_path
=
path_to_repo
/
repo
.
output_
folder
/
"
extended_result.csv
"
extended_array_file_path
=
path_to_repo
/
repo
.
output_
path
/
"
extended_result.csv
"
np
.
savetxt
(
extended_array_file_path
,
np
.
savetxt
(
extended_array_file_path
,
extended_array
,
extended_array
,
delimiter
=
"
,
"
)
delimiter
=
"
,
"
)
...
@@ -201,8 +209,8 @@ def test_cadet_rdm(path_to_repo):
...
@@ -201,8 +209,8 @@ def test_cadet_rdm(path_to_repo):
try_commit_code
(
path_to_repo
)
try_commit_code
(
path_to_repo
)
try_commit_code_without_code_changes
(
path_to_repo
)
try_commit_code_without_code_changes
(
path_to_repo
)
try_commit_results_with_uncommitted_code_changes
(
path_to_repo
)
try_commit_results_with_uncommitted_code_changes
(
path_to_repo
)
try_output_function
(
path_to_repo
)
results_branch_name
=
try_commit_results_data
(
path_to_repo
)
results_branch_name
=
try_commit_results_data
(
path_to_repo
)
results_branch_name
=
try_commit_results_data
(
path_to_repo
)
try_print_log
(
path_to_repo
)
try_print_log
(
path_to_repo
)
...
...
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