Skip to content

Commit

Permalink
fix click entry point, explicitly raise filenotfounderror when the ya…
Browse files Browse the repository at this point in the history
…ml doesnt exist in combine_model functions within combine_yamls classes, add test that would catch a problematic click entrypoint function.
  • Loading branch information
ilaflott committed Nov 22, 2024
1 parent 1c06ab3 commit b980f03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions fre/pp/frepp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import click
from .checkoutScript import checkoutTemplate
from .configure_script_yaml import yamlInfo
from .configure_script_yaml import _yamlInfo
from .configure_script_xml import convert
from .validate import validate_subtool
from .install import install_subtool
Expand Down Expand Up @@ -100,7 +100,7 @@ def install(context, experiment, platform, target):
def configure_yaml(context,yamlfile,experiment,platform,target):
# pylint: disable=unused-argument
""" - Execute fre pp configure """
context.forward(yamlInfo)
context.forward(_yamlInfo)

@pp_cli.command()
@click.option("-e", "--experiment", type=str,
Expand Down
12 changes: 12 additions & 0 deletions fre/tests/test_fre_pp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ def test_cli_fre_pp_configure_yaml_opt_dne():
result = runner.invoke(fre.fre, args=["pp", "configure-yaml", "optionDNE"])
assert result.exit_code == 2

def test_cli_fre_pp_configure_yaml_fail1():
''' fre pp configure-yaml '''
result = runner.invoke(fre.fre, args = [ "pp", "configure-yaml",
"-e", "FOO",
"-p", "BAR",
"-t", "BAZ",
"-y", "BOO" ] )
assert all( [ result.exit_code == 1,
isinstance(result.exception, FileNotFoundError )
] )


#-- fre pp install
def test_cli_fre_pp_install():
''' fre pp install '''
Expand Down
20 changes: 12 additions & 8 deletions fre/yamltools/combine_yamls.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ def combine_model(self):
f1.write(f'name: &name "{self.name}"\n')
f1.write(f'platform: &platform "{self.platform}"\n')
f1.write(f'target: &target "{self.target}"\n\n')
with open(self.yml,'r',encoding='UTF-8') as f2:
f1.write("### MODEL YAML SETTINGS ###\n")
shutil.copyfileobj(f2,f1)

try:
with open(self.yml,'r',encoding='UTF-8') as f2:
f1.write("### MODEL YAML SETTINGS ###\n")
shutil.copyfileobj(f2,f1)
except Exception as exc:
raise FileNotFoundError(f'{self.yml} not found') from exc
print(f" model yaml: {self.yml}")

def combine_compile(self):
Expand Down Expand Up @@ -231,10 +233,12 @@ def combine_model(self):
f1.write(f'name: &name "{self.name}"\n')
f1.write(f'platform: &platform "{self.platform}"\n')
f1.write(f'target: &target "{self.target}"\n\n')
with open(self.yml,'r',encoding='UTF-8') as f2:
f1.write("### MODEL YAML SETTINGS ###\n")
shutil.copyfileobj(f2,f1)

try:
with open(self.yml,'r',encoding='UTF-8') as f2:
f1.write("### MODEL YAML SETTINGS ###\n")
shutil.copyfileobj(f2,f1)
except Exception as exc:
raise FileNotFoundError(f'{self.yml} not found') from exc
print(f" model yaml: {self.yml}")

def combine_experiment(self):
Expand Down

0 comments on commit b980f03

Please sign in to comment.