Skip to content

Commit 7aa74e0

Browse files
author
Andrei Neagu
committed
added legacy-escape command
1 parent 7c68dc8 commit 7aa74e0

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

packages/service-integration/src/service_integration/cli/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .._meta import __version__
99
from ..settings import AppSettings
10-
from . import _compose_spec, _metadata, _run_creator, _test
10+
from . import _compose_spec, _escaping, _metadata, _run_creator, _test
1111
from ._config import config_app
1212

1313
app = typer.Typer()
@@ -76,3 +76,4 @@ def main(
7676
app.command("bump-version")(_metadata.bump_version)
7777
app.command("get-version")(_metadata.get_version)
7878
app.command("run-creator")(_run_creator.run_creator)
79+
app.command("legacy-escape")(_escaping.legacy_escape)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pathlib import Path
2+
from typing import Annotated
3+
4+
import typer
5+
6+
from ..osparc_config import OSPARC_CONFIG_DIRNAME
7+
8+
9+
def legacy_escape(
10+
osparc_config_dirname: Annotated[
11+
Path,
12+
typer.Option(
13+
"--osparc-config-dirname",
14+
help="Path to where the .osparc configuration directory is located",
15+
),
16+
] = Path(OSPARC_CONFIG_DIRNAME),
17+
):
18+
"""Escapes the `$${` with `$$$${` in all .y*ml files in the osparc config directory."""
19+
for file in osparc_config_dirname.glob("*.y*ml"):
20+
read_text = file.read_text()
21+
replaced_text = read_text.replace("$${", "$$$${")
22+
if read_text != replaced_text:
23+
print(f"Escaped sequnce in {file}")
24+
file.write_text(replaced_text)
Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,54 @@
1+
import os
2+
import shutil
3+
import traceback
14
from collections.abc import Callable
5+
from pathlib import Path
26

7+
import pytest
8+
from click.testing import Result
39
from service_integration import __version__
410

511

12+
def _format_cli_error(result: Result) -> str:
13+
assert result.exception
14+
tb_message = "\n".join(traceback.format_tb(result.exception.__traceback__))
15+
return f"Below exception was raised by the cli:\n{tb_message}"
16+
17+
618
def test_cli_help(run_program_with_args: Callable):
719
result = run_program_with_args(
820
"--help",
921
)
10-
assert result.exit_code == 0
22+
assert result.exit_code == os.EX_OK, _format_cli_error(result)
1123

1224

1325
def test_cli_version(run_program_with_args: Callable):
1426
result = run_program_with_args(
1527
"--version",
1628
)
17-
assert result.exit_code == 0
29+
assert result.exit_code == os.EX_OK, _format_cli_error(result)
1830
assert __version__ == result.output.strip()
31+
32+
33+
@pytest.fixture
34+
def copy_tests_data_dir(tests_data_dir: Path, tmp_path: Path) -> Path:
35+
new_dir_path = tmp_path / "copy_tests_data_dir"
36+
new_dir_path.mkdir(exist_ok=True, parents=True)
37+
38+
for item in tests_data_dir.glob("*"):
39+
print(f"Copying {item} to {new_dir_path / item.name}")
40+
shutil.copy2(item, new_dir_path / item.name)
41+
42+
return new_dir_path
43+
44+
45+
def test_cli_legacy_escape(copy_tests_data_dir: Path, run_program_with_args: Callable):
46+
result = run_program_with_args(
47+
"legacy-escape", "--osparc-config-dirname", copy_tests_data_dir
48+
)
49+
assert result.exit_code == os.EX_OK, _format_cli_error(result)
50+
# NOTE only 1 file will have a sequnce that will be escaped
51+
assert (
52+
result.output.strip()
53+
== f"Escaped sequnce in {copy_tests_data_dir}/docker-compose-meta.yml"
54+
)

0 commit comments

Comments
 (0)