Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ doc/_build

.lint.json
.lint.txt

/.serena
/.codex
2 changes: 0 additions & 2 deletions doc/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ Test Dependencies
Dependency Purpose License
===================== ========================== ========
`Pytest`_ Testing framework MIT
`Prysk`_ Testing framework GPL
===================== ========================== ========

.. _Python 3: https://docs.python.org/3
.. _Pytest: https://docs.pytest.org/en/stable/
.. _Prysk: https://www.prysk.net
21 changes: 1 addition & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ec = "exasol.error._cli:main"
[dependency-groups]
dev = [
"pytest>=7.1.2,<10",
"prysk[pytest-plugin]>=0.15.1",
"exasol-toolbox>=8.1.1, <9",
]

Expand Down
112 changes: 112 additions & 0 deletions test/integration/cli_integration_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import json
import os
import shutil
import subprocess
import sys
from pathlib import Path

import pytest

REPO_ROOT = Path(__file__).resolve().parents[2]
PYMODULE_CONTENT = """from exasol import error
from exasol.error import Parameter
error1 = error.ExaError(
"E-TEST-1",
"this is an error",
["no mitigation available"],
{"param": Parameter("value", "some description")},
)
error2 = error.ExaError(
"E-TEST-2", "this is an error", ["no mitigation available"], {"param": "value"}
)
"""
EXPECTED_ERRORS = [
{
"identifier": "E-TEST-1",
"message": "this is an error",
"messagePlaceholders": [
{"placeholder": "param", "description": "some description"}
],
"description": None,
"internalDescription": None,
"potentialCauses": None,
"mitigations": ["no mitigation available"],
"sourceFile": "pymodule.py",
"sourceLine": 3,
"contextHash": None,
},
{
"identifier": "E-TEST-2",
"message": "this is an error",
"messagePlaceholders": [{"placeholder": "param", "description": ""}],
"description": None,
"internalDescription": None,
"potentialCauses": None,
"mitigations": ["no mitigation available"],
"sourceFile": "pymodule.py",
"sourceLine": 9,
"contextHash": None,
},
]


def _env():
env = os.environ.copy()
pythonpath = env.get("PYTHONPATH")
env["PYTHONPATH"] = (
f"{REPO_ROOT}{os.pathsep}{pythonpath}" if pythonpath else str(REPO_ROOT)
)
return env


def _run(command: list[str], *args: str, cwd: Path) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[*command, "--debug", *args],
cwd=cwd,
env=_env(),
check=True,
capture_output=True,
text=True,
)


def _commands():
yield pytest.param([sys.executable, "-m", "exasol.error"], id="module-entrypoint")
ec_path = shutil.which("ec")
if ec_path:
yield pytest.param([ec_path], id="console-script")
else:
yield pytest.param(
[sys.executable, "-c", "from exasol.error._cli import main; main()"],
id="cli-module-fallback",
)


@pytest.fixture
def sample_module(tmp_path: Path) -> Path:
module = tmp_path / "pymodule.py"
module.write_text(PYMODULE_CONTENT, encoding="utf-8")
return module


@pytest.mark.parametrize("command", _commands())
def test_parse_subcommand(command: list[str], sample_module: Path):
result = _run(command, "parse", sample_module.name, cwd=sample_module.parent)

assert result.stderr == ""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can --debug cause any stderr output?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find any reference to CLI option --debug except in _cli.py.
Hence, I don't assume CLI option --debug to cause any specific output.
However, with or without CLI option --debug I think, output to stderr is possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the --debug in _run(...). But maybe I am lacking the context, so feel free to ignore it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current guess is, that the CLI option --debug is used to prevent subprocess.run() to raise errors during integration tests.

Actually I think this is not optimal and could be avoided by using click.CliRunner().

I also see some more questionable things, e.g. ec_path = shutil.which("ec").

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are not perfect, but better then prysk. For that reason, I suggest we merge them for the moment and we create a ticket to refactor the cli and make it easier testable.

Copy link
Copy Markdown
Contributor Author

@ckunki ckunki Jun 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert [json.loads(line) for line in result.stdout.splitlines()] == EXPECTED_ERRORS


@pytest.mark.parametrize("command", _commands())
def test_generate_subcommand(command: list[str], sample_module: Path):
result = _run(
command, "generate", "modulename", "1.2.0", ".", cwd=sample_module.parent
)

assert result.stderr == ""
assert json.loads(result.stdout) == {
"$schema": "https://schemas.exasol.com/error_code_report-1.0.0.json",
"projectName": "modulename",
"projectVersion": "1.2.0",
"errorCodes": EXPECTED_ERRORS,
}
115 changes: 0 additions & 115 deletions test/integration/generate-subcommand.t

This file was deleted.

101 changes: 0 additions & 101 deletions test/integration/parse-subcommand.t

This file was deleted.