Skip to content

Commit

Permalink
Force default indent of flepimop patch to 4
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyWillard committed Dec 11, 2024
1 parent ba22f0b commit d3f89d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
20 changes: 4 additions & 16 deletions flepimop/gempyor_pkg/src/gempyor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,7 @@


# add some basic commands to the CLI
@cli.command(
params=[config_files_argument]
+ list(config_file_options.values())
+ [
click.Option(
["--indent"],
type=click.IntRange(min=1),
required=False,
default=2,
help="Indentation level for the output YAML.",
)
],
)
@cli.command(params=[config_files_argument] + list(config_file_options.values()))
@click.pass_context
def patch(ctx: click.Context = mock_context, **kwargs) -> None:
"""Merge configuration files
Expand Down Expand Up @@ -64,7 +52,7 @@ def patch(ctx: click.Context = mock_context, **kwargs) -> None:
gamma:
value: 5.6
EOF
$ flepimop patch config1.yml config2.yml --indent 4
$ flepimop patch config1.yml config2.yml
...: UserWarning: Configuration files contain overlapping keys: {'seir'}.
warnings.warn(f"Configuration files contain overlapping keys: {intersect}.")
compartments:
Expand All @@ -89,7 +77,7 @@ def patch(ctx: click.Context = mock_context, **kwargs) -> None:
stoch_traj_flag: false
write_csv: false
write_parquet: true
$ flepimop patch config2.yml config1.yml --indent 4
$ flepimop patch config2.yml config1.yml
...: UserWarning: Configuration files contain overlapping keys: {'seir'}.
warnings.warn(f"Configuration files contain overlapping keys: {intersect}.")
compartments:
Expand All @@ -116,7 +104,7 @@ def patch(ctx: click.Context = mock_context, **kwargs) -> None:
```
"""
parse_config_files(config, ctx, **kwargs)
print(yaml.dump(yaml.safe_load(config.dump()), indent=kwargs["indent"]))
print(yaml.dump(yaml.safe_load(config.dump()), indent=4))


if __name__ == "__main__":
Expand Down
24 changes: 0 additions & 24 deletions flepimop/gempyor_pkg/tests/cli/test_flepimop_patch_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,3 @@ def test_patch_seir_parameters_behavior(
patched_config = yaml.safe_load(result.output)
assert "seir" in patched_config
assert patched_config["seir"]["parameters"] == expected_parameters


@pytest.mark.parametrize("indent", (2, 4, 6))
def test_user_provided_indent_size(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, indent: int
) -> None:
# Setup the test
monkeypatch.chdir(tmp_path)
config = tmp_path / "config.yml"
config.write_text(yaml.dump({"seir": {"parameters": {"beta": {"value": 1.2}}}}))

# Invoke the command
runner = CliRunner()
result = runner.invoke(patch, [config.name, "--indent", str(indent)])
assert result.exit_code == 0

# Check the output indentation, manually since `yaml.load` abstracts spacing away
for line in result.output.split():
stripped_line = line.lstrip()
if stripped_line and not stripped_line.startswith("#"):
indent_size = len(line) - len(stripped_line)
if indent_size > 0:
assert indent_size == indent
break

0 comments on commit d3f89d2

Please sign in to comment.