forked from MetOffice/fab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
############################################################################## | ||
# (c) Crown copyright Met Office. All rights reserved. | ||
# For further details please refer to the file COPYRIGHT | ||
# which you should have received as part of this distribution | ||
############################################################################## | ||
|
||
"""This file the tool class for PSyclone. | ||
""" | ||
|
||
from pathlib import Path | ||
from typing import List, Optional, Union | ||
|
||
from fab.newtools.categories import Categories | ||
from fab.newtools.tool import Tool | ||
|
||
|
||
class Psyclone(Tool): | ||
'''This is the base class for `PSyclone`. | ||
''' | ||
|
||
def __init__(self): | ||
super().__init__("psyclone", "psyclone", Categories.PSYCLONE) | ||
|
||
def check_available(self): | ||
'''Checks if psyclone is available. We do this by requesting the | ||
psyclone version. | ||
''' | ||
try: | ||
self.run("--version") | ||
except (RuntimeError, FileNotFoundError): | ||
return False | ||
return True | ||
|
||
def process(self, api: str, | ||
x90_file: Union[Path, str], | ||
psy_file: Union[Path, str], | ||
alg_file: Union[Path, str], | ||
transformation_script: Optional[Union[Path, str]] = None, | ||
additional_parameters: Optional[List[str]] = None, | ||
kernel_roots: Optional[List[str]] = None, | ||
): | ||
'''Create the archive with the specified name, containing the | ||
listed members. | ||
:param output_fpath: the output path. | ||
:param members: the list of objects to be added to the archive. | ||
''' | ||
parameters = ["-api", api, "-l", "all", | ||
"-opsy", str(psy_file), | ||
"-oalg", str(alg_file)] | ||
if transformation_script: | ||
parameters.extend(["-s", str(transformation_script)]) | ||
if additional_parameters: | ||
parameters.extend(additional_parameters) | ||
if kernel_roots: | ||
roots_with_dash_d = sum([['-d', str(k)] for k in kernel_roots], []) | ||
parameters.extend(roots_with_dash_d) | ||
parameters.append(str(x90_file)) | ||
print("XX", parameters) | ||
return self.run(additional_parameters=parameters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
############################################################################## | ||
# (c) Crown copyright Met Office. All rights reserved. | ||
# For further details please refer to the file COPYRIGHT | ||
# which you should have received as part of this distribution | ||
############################################################################## | ||
|
||
'''Tests the PSyclone implementation. | ||
''' | ||
|
||
from unittest import mock | ||
|
||
from fab.newtools import (Categories, Psyclone) | ||
|
||
|
||
def test_psyclone_constructor(): | ||
'''Test the psyclone constructor.''' | ||
psyclone = Psyclone() | ||
assert psyclone.category == Categories.PSYCLONE | ||
assert psyclone.name == "psyclone" | ||
assert psyclone.exec_name == "psyclone" | ||
assert psyclone.flags == [] | ||
|
||
|
||
def test_psyclone_check_available(): | ||
'''Tests the is_available functionality.''' | ||
psyclone = Psyclone() | ||
with mock.patch("fab.newtools.tool.Tool.run") as tool_run: | ||
assert psyclone.check_available() | ||
tool_run.assert_called_once_with("--version") | ||
|
||
# Test behaviour if a runtime error happens: | ||
with mock.patch("fab.newtools.tool.Tool.run", | ||
side_effect=RuntimeError("")) as tool_run: | ||
assert not psyclone.check_available() | ||
|
||
|
||
def test_psyclone_process(): | ||
'''Test running PSyclone.''' | ||
psyclone = Psyclone() | ||
with mock.patch("fab.newtools.tool.Tool.run") as tool_run: | ||
psyclone.process(api="dynamo0.3", | ||
x90_file="x90_file", | ||
psy_file="psy_file", | ||
alg_file="alg_file", | ||
transformation_script="transformation_script", | ||
kernel_roots=["root1", "root2"], | ||
additional_parameters=["-c", "psyclone.cfg"]) | ||
tool_run.assert_called_with( | ||
additional_parameters=['-api', 'dynamo0.3', '-l', 'all', '-opsy', | ||
'psy_file', '-oalg', 'alg_file', '-s', | ||
'transformation_script', '-c', 'psyclone.cfg', | ||
'-d', 'root1', '-d', 'root2', 'x90_file']) |