Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
esde
machine-learning
MLAir
Commits
5d3248f1
Commit
5d3248f1
authored
5 years ago
by
Felix Kleinert
Browse files
Options
Downloads
Patches
Plain Diff
update helpers and test_helpers
parent
b38c6ae9
No related branches found
No related tags found
3 merge requests
!125
Release v0.10.0
,
!124
Update Master to new version v0.10.0
,
!97
Felix issue106 hpc modules for juwels
Pipeline
#33832
failed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers.py
+3
-6
3 additions, 6 deletions
src/helpers.py
test/test_helpers.py
+26
-20
26 additions, 20 deletions
test/test_helpers.py
with
29 additions
and
26 deletions
src/helpers.py
+
3
−
6
View file @
5d3248f1
...
...
@@ -103,12 +103,9 @@ def get_host():
def
prepare_host
(
create_new
=
True
,
sampling
=
"
daily
"
):
hostname
=
socket
.
gethostname
()
try
:
# user = os.getlogin()
user
=
getpass
.
getuser
()
except
OSError
:
user
=
"
default
"
hostname
=
get_host
()
user
=
getpass
.
getuser
()
if
hostname
==
"
ZAM144
"
:
path
=
f
"
/home/
{
user
}
/Data/toar_
{
sampling
}
/
"
elif
hostname
==
"
zam347
"
:
...
...
This diff is collapsed.
Click to expand it.
test/test_helpers.py
+
26
−
20
View file @
5d3248f1
...
...
@@ -126,13 +126,18 @@ class TestTimeTracking:
assert
t
.
end
is
None
expression
=
PyTestRegex
(
r
"
my job finished after \d+:\d+:\d+ \(hh:mm:ss\)
"
)
assert
caplog
.
record_tuples
[
-
1
]
==
(
'
root
'
,
20
,
expression
)
class
TestGetHost
:
def
test_get_host
()
assert
prepare_host
()
==
'
root
'
class
TestPrepareHost
:
@mock.patch
(
"
socket.gethostname
"
,
side_effect
=
[
"
linux-aa9b
"
,
"
ZAM144
"
,
"
zam347
"
,
"
jrtest
"
,
"
jwtest
"
,
"
runner-6HmDp9Qd-project-2411-concurrent
"
])
@mock.patch
(
"
os.getlogin
"
,
return_value
=
"
testUser
"
)
@mock.patch
(
"
getpass.getuser
"
,
return_value
=
"
testUser
"
)
@mock.patch
(
"
os.path.exists
"
,
return_value
=
True
)
def
test_prepare_host
(
self
,
mock_host
,
mock_user
,
mock_path
):
assert
prepare_host
()
==
"
/home/testUser/machinelearningtools/data/toar_daily/
"
...
...
@@ -149,7 +154,8 @@ class TestPrepareHost:
prepare_host
()
assert
"
unknown host
'
NotExistingHostName
'"
in
e
.
value
.
args
[
0
]
@mock.patch
(
"
os.getlogin
"
,
return_value
=
"
zombie21
"
)
#@mock.patch("os.getlogin", return_value="zombie21")
@mock.patch
(
"
getpass.getuser
"
,
return_value
=
"
zombie21
"
)
@mock.patch
(
"
src.helpers.check_path_and_create
"
,
side_effect
=
PermissionError
)
def
test_error_handling
(
self
,
mock_cpath
,
mock_user
):
# if "runner-6HmDp9Qd-project-2411-concurrent" not in platform.node():
...
...
@@ -162,26 +168,26 @@ class TestPrepareHost:
# assert "does not exist for host 'linux-aa9b'" in e.value.args[0]
assert
PyTestRegex
(
r
"
path
'
.*
'
does not exist for host
'
.*
'
\.
"
)
==
e
.
value
.
args
[
0
]
@mock.patch
(
"
socket.gethostname
"
,
side_effect
=
[
"
linux-aa9b
"
,
"
ZAM144
"
,
"
zam347
"
,
"
jrtest
"
,
"
jwtest
"
,
"
runner-6HmDp9Qd-project-2411-concurrent
"
])
@mock.patch
(
"
os.getlogin
"
,
side_effect
=
OSError
)
@mock.patch
(
"
os.path.exists
"
,
return_value
=
True
)
def
test_os_error
(
self
,
mock_path
,
mock_user
,
mock_host
):
path
=
prepare_host
()
assert
path
==
"
/home/default/machinelearningtools/data/toar_daily/
"
path
=
prepare_host
()
assert
path
==
"
/home/default/Data/toar_daily/
"
path
=
prepare_host
()
assert
path
==
"
/home/default/Data/toar_daily/
"
path
=
prepare_host
()
assert
path
==
"
/p/project/cjjsc42/default/DATA/toar_daily/
"
path
=
prepare_host
()
assert
path
==
"
/p/home/jusers/default/juwels/intelliaq/DATA/toar_daily/
"
path
=
prepare_host
()
assert
path
==
'
/home/default/machinelearningtools/data/toar_daily/
'
#
@mock.patch("socket.gethostname", side_effect=["linux-aa9b", "ZAM144", "zam347", "jrtest", "jwtest",
#
"runner-6HmDp9Qd-project-2411-concurrent"])
#
@mock.patch("os.getlogin", side_effect=OSError)
#
@mock.patch("os.path.exists", return_value=True)
#
def test_os_error(self, mock_path, mock_user, mock_host):
#
path = prepare_host()
#
assert path == "/home/default/machinelearningtools/data/toar_daily/"
#
path = prepare_host()
#
assert path == "/home/default/Data/toar_daily/"
#
path = prepare_host()
#
assert path == "/home/default/Data/toar_daily/"
#
path = prepare_host()
#
assert path == "/p/project/cjjsc42/default/DATA/toar_daily/"
#
path = prepare_host()
#
assert path == "/p/home/jusers/default/juwels/intelliaq/DATA/toar_daily/"
#
path = prepare_host()
#
assert path == '/home/default/machinelearningtools/data/toar_daily/'
@mock.patch
(
"
socket.gethostname
"
,
side_effect
=
[
"
linux-aa9b
"
])
@mock.patch
(
"
os.getlogin
"
,
return_value
=
"
testUser
"
)
@mock.patch
(
"
getpass.getuser
"
,
return_value
=
"
testUser
"
)
@mock.patch
(
"
os.path.exists
"
,
return_value
=
False
)
@mock.patch
(
"
os.makedirs
"
,
side_effect
=
None
)
def
test_os_path_exists
(
self
,
mock_host
,
mock_user
,
mock_path
,
mock_check
):
...
...
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