Skip to content

Commit c13fd16

Browse files
committed
WIP: this platforms.wrapper code is confusing...
1 parent 1841cc3 commit c13fd16

File tree

4 files changed

+115
-21
lines changed

4 files changed

+115
-21
lines changed

autosubmit/platforms/wrappers/wrapper_builder.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
#!/usr/bin/env python3
2-
3-
# Copyright 2015-2020 Earth Sciences Department, BSC-CNS
4-
1+
# Copyright 2015-2025 Earth Sciences Department, BSC-CNS
2+
#
53
# This file is part of Autosubmit.
6-
4+
#
75
# Autosubmit is free software: you can redistribute it and/or modify
86
# it under the terms of the GNU General Public License as published by
97
# the Free Software Foundation, either version 3 of the License, or
108
# (at your option) any later version.
11-
9+
#
1210
# Autosubmit is distributed in the hope that it will be useful,
1311
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1412
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1513
# GNU General Public License for more details.
16-
14+
#
1715
# You should have received a copy of the GNU General Public License
1816
# along with Autosubmit. If not, see <http://www.gnu.org/licenses/>.
1917

@@ -30,22 +28,26 @@ class WrapperDirector:
3028
"""
3129
def __init__(self):
3230
self._builder = None
31+
3332
def construct(self, builder):
3433
self._builder = builder
3534

3635
header = self._builder.build_header()
3736
job_thread = self._builder.build_job_thread()
38-
#if "bash" not in header[0:15]:
37+
# if "bash" not in header[0:15]:
3938

4039
main = self._builder.build_main()
41-
#else:
40+
# else:
4241
# nodes,main = self._builder.build_main() #What to do with nodes?
4342
# change to WrapperScript object
4443
wrapper_script = header + job_thread + main
4544
wrapper_script = wrapper_script.replace("_NEWLINE_", '\\n')
4645

4746
return wrapper_script
47+
48+
4849
class WrapperBuilder(object):
50+
4951
def __init__(self, **kwargs):
5052
if "retrials" in list(kwargs.keys()):
5153
self.retrials = kwargs['retrials']
@@ -66,7 +68,7 @@ def __init__(self, **kwargs):
6668
def build_header(self):
6769
return textwrap.dedent(self.header_directive) + self.build_imports()
6870

69-
def build_imports(self):
71+
def build_imports(self) -> str:
7072
pass # pragma: no cover
7173

7274
def build_job_thread(self):

autosubmit/platforms/wrappers/wrapper_factory.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
#!/usr/bin/env python3
2-
3-
# Copyright 2015-2020 Earth Sciences Department, BSC-CNS
4-
1+
# Copyright 2015-2025 Earth Sciences Department, BSC-CNS
2+
#
53
# This file is part of Autosubmit.
6-
4+
#
75
# Autosubmit is free software: you can redistribute it and/or modify
86
# it under the terms of the GNU General Public License as published by
97
# the Free Software Foundation, either version 3 of the License, or
108
# (at your option) any later version.
11-
9+
#
1210
# Autosubmit is distributed in the hope that it will be useful,
1311
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1412
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1513
# GNU General Public License for more details.
16-
14+
#
1715
# You should have received a copy of the GNU General Public License
1816
# along with Autosubmit. If not, see <http://www.gnu.org/licenses/>.
1917

2018
import re
2119

22-
from autosubmit.platforms.wrappers.wrapper_builder import WrapperDirector, PythonVerticalWrapperBuilder, \
23-
PythonHorizontalWrapperBuilder, PythonHorizontalVerticalWrapperBuilder, PythonVerticalHorizontalWrapperBuilder, \
24-
BashHorizontalWrapperBuilder, BashVerticalWrapperBuilder, SrunHorizontalWrapperBuilder, \
25-
SrunVerticalHorizontalWrapperBuilder
20+
from autosubmit.platforms.wrappers.wrapper_builder import (
21+
WrapperDirector, PythonVerticalWrapperBuilder, PythonHorizontalWrapperBuilder,
22+
PythonHorizontalVerticalWrapperBuilder, PythonVerticalHorizontalWrapperBuilder, BashHorizontalWrapperBuilder,
23+
BashVerticalWrapperBuilder, SrunHorizontalWrapperBuilder, SrunVerticalHorizontalWrapperBuilder
24+
)
2625

2726

2827
class WrapperFactory(object):
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2015-2025 Earth Sciences Department, BSC-CNS
2+
#
3+
# This file is part of Autosubmit.
4+
#
5+
# Autosubmit is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# Autosubmit is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Autosubmit. If not, see <http://www.gnu.org/licenses/>.
17+
18+
"""Unit tests for code related to wrappers in platforms."""
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2015-2025 Earth Sciences Department, BSC-CNS
2+
#
3+
# This file is part of Autosubmit.
4+
#
5+
# Autosubmit is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# Autosubmit is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Autosubmit. If not, see <http://www.gnu.org/licenses/>.
17+
18+
"""Unit tests for the wrapper_factory module."""
19+
import pytest
20+
21+
from autosubmit.platforms.wrappers.wrapper_factory import SlurmWrapperFactory
22+
from autosubmit.platforms.wrappers.wrapper_builder import BashVerticalWrapperBuilder
23+
from autosubmit.platforms.slurmplatform import SlurmPlatform
24+
25+
26+
_EXPID = 't000'
27+
28+
29+
@pytest.fixture
30+
def slurm_platform(tmp_path):
31+
return SlurmPlatform(_EXPID, 'slurm-platform', {
32+
'LOCAL_ROOT_DIR': str(tmp_path),
33+
'LOCAL_ASLOG_DIR': str(tmp_path / 'ASLOG')
34+
}, None)
35+
36+
37+
@pytest.fixture
38+
def wrapper_builder_kwargs() -> dict:
39+
return {
40+
'retrials': 1,
41+
'header_directive': '',
42+
'jobs_scripts': '',
43+
'threads': 1,
44+
'num_processors': 1,
45+
'num_processors_value': 1,
46+
'expid': _EXPID,
47+
'jobs_resources': '',
48+
'allocated_nodes': '',
49+
'wallclock_by_level': '',
50+
'name': 'WRAPPER_V'
51+
}
52+
53+
54+
def test_constructor(slurm_platform):
55+
wrapper_factory = SlurmWrapperFactory(slurm_platform)
56+
57+
assert wrapper_factory.as_conf is None
58+
assert wrapper_factory.platform is slurm_platform
59+
assert wrapper_factory.wrapper_director
60+
assert 'this platform' in wrapper_factory.exception
61+
62+
63+
def test_get_wrapper(slurm_platform: SlurmPlatform, wrapper_builder_kwargs: dict, mocker):
64+
wrapper_factory = SlurmWrapperFactory(slurm_platform)
65+
66+
wrapper_data = mocker.MagicMock()
67+
wrapper_data.het = {
68+
'HETSIZE': 2
69+
}
70+
wallclock = '00:30'
71+
72+
wrapper_builder_kwargs['wrapper_data'] = wrapper_data
73+
wrapper_builder_kwargs['wallclock'] = wallclock
74+
75+
wrapper_factory.get_wrapper(BashVerticalWrapperBuilder, **wrapper_builder_kwargs)

0 commit comments

Comments
 (0)