From 7472b4f0f8d82f6bcc1bb4b6b0b8aa969d588de6 Mon Sep 17 00:00:00 2001 From: Daizu Date: Tue, 4 Nov 2025 19:00:56 +0900 Subject: [PATCH 1/3] fix: Correct script entry point for ixbrlparse --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c31e617..ecc206f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ Issues = "https://github.com/kanedata/ixbrl-parse/issues" Source = "https://github.com/kanedata/ixbrl-parse" [project.scripts] -ixbrlparse = "ixbrlparse.cli:ixbrlparse" +ixbrlparse = "ixbrlparse.cli:ixbrlparse_cli" [tool.hatch.version] path = "src/ixbrlparse/__about__.py" From 498bd35c98d987d1889b4fae065a90c5845c6e3c Mon Sep 17 00:00:00 2001 From: David Kane Date: Tue, 4 Nov 2025 10:43:42 +0000 Subject: [PATCH 2/3] add tests to confirm cli is in the right place --- pyproject.toml | 4 +- tests/test_cli.py | 126 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ecc206f..c3e5887 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -170,5 +170,5 @@ tests = ["tests", "*/ixbrlparse/tests"] [tool.coverage.report] exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"] -[tool.hatch.build.targets.sdist] -include = ["/ixbrlparse"] +[tool.hatch.build] +packages = ["src/ixbrlparse"] diff --git a/tests/test_cli.py b/tests/test_cli.py index 13778a1..c2c3767 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,5 +1,7 @@ import io import json +import subprocess +import sys from click.testing import CliRunner @@ -12,17 +14,46 @@ def test_cli(): buffer = io.StringIO() runner = CliRunner() - result = runner.invoke(ixbrlparse_cli, ["--outfile", buffer, "tests/test_accounts/account_1.html"]) # type: ignore + result = runner.invoke( + ixbrlparse_cli, + ["--outfile", buffer, "tests/test_accounts/account_1.html"], + ) # type: ignore assert result.exit_code == 0 assert ",CurrentAssets,2909.0," in buffer.getvalue() +def test_cli_raw(tmp_path): + f = tmp_path / "output.csv" + result = subprocess.run( # noqa: S603 + [ + sys.executable, + "-m", + "ixbrlparse", + "--outfile", + str(f), + "tests/test_accounts/account_1.html", + ], + check=False, + capture_output=True, + text=True, + ) # type: ignore + assert result.returncode == 0 + with open(f) as file: + assert ",CurrentAssets,2909.0," in file.read() + + def test_cli_json(): buffer = io.StringIO() runner = CliRunner() result = runner.invoke( ixbrlparse_cli, # type: ignore - ["--outfile", buffer, "--format", "json", "tests/test_accounts/account_1.html"], # type: ignore + [ + "--outfile", + buffer, + "--format", + "json", + "tests/test_accounts/account_1.html", + ], # type: ignore ) assert result.exit_code == 0 data = json.loads(buffer.getvalue()) @@ -30,24 +61,81 @@ def test_cli_json(): assert data["numeric"][2]["value"] == 2909.0 +def test_cli_json_raw(tmp_path): + f = tmp_path / "output.json" + result = subprocess.run( # noqa: S603 + [ + sys.executable, + "-m", + "ixbrlparse", + "--outfile", + str(f), + "--format", + "json", + "tests/test_accounts/account_1.html", + ], + check=False, + capture_output=True, + text=True, + ) # type: ignore + assert result.returncode == 0 + with open(f) as file: + data = json.load(file) + assert data["numeric"][2]["name"] == "CurrentAssets" + assert data["numeric"][2]["value"] == 2909.0 + + def test_cli_unknown_format(): buffer = io.StringIO() runner = CliRunner() result = runner.invoke( ixbrlparse_cli, # type: ignore - ["--outfile", buffer, "--format", "flurg", "tests/test_accounts/account_1.html"], # type: ignore + [ + "--outfile", + buffer, + "--format", + "flurg", + "tests/test_accounts/account_1.html", + ], # type: ignore ) assert result.exit_code != 0 data = buffer.getvalue() assert not data +def test_cli_unknown_format_raw(tmp_path): + f = tmp_path / "output.txt" + result = subprocess.run( # noqa: S603 + [ + sys.executable, + "-m", + "ixbrlparse", + "--outfile", + str(f), + "--format", + "flurg", + "tests/test_accounts/account_1.html", + ], + check=False, + capture_output=True, + text=True, + ) # type: ignore + assert result.returncode != 0 + assert not f.exists() + + def test_cli_jsonl(): buffer = io.StringIO() runner = CliRunner() result = runner.invoke( ixbrlparse_cli, # type: ignore - ["--outfile", buffer, "--format", "jsonl", "tests/test_accounts/account_1.html"], # type: ignore + [ + "--outfile", + buffer, + "--format", + "jsonl", + "tests/test_accounts/account_1.html", + ], # type: ignore ) assert result.exit_code == 0 lines = buffer.getvalue().splitlines() @@ -59,3 +147,33 @@ def test_cli_jsonl(): else: msg = "CurrentAssets not found" raise AssertionError(msg) + + +def test_cli_jsonl_raw(tmp_path): + f = tmp_path / "output.jsonl" + result = subprocess.run( # noqa: S603 + [ + sys.executable, + "-m", + "ixbrlparse", + "--outfile", + str(f), + "--format", + "jsonl", + "tests/test_accounts/account_1.html", + ], + check=False, + capture_output=True, + text=True, + ) # type: ignore + assert result.returncode == 0 + with open(f) as file: + lines = file.readlines() + for line in lines: + data = json.loads(line) + if data["name"] == "CurrentAssets": + assert data["value"] == 2909.0 + break + else: + msg = "CurrentAssets not found" + raise AssertionError(msg) From a5eeefb17e1bd296afbcfc4563b9e590909210f4 Mon Sep 17 00:00:00 2001 From: David Kane Date: Tue, 4 Nov 2025 10:51:30 +0000 Subject: [PATCH 3/3] two versions of checking the command line --- tests/test_cli.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index c2c3767..7c736e0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3,6 +3,7 @@ import subprocess import sys +import pytest from click.testing import CliRunner import ixbrlparse.__main__ as ixmain @@ -10,6 +11,11 @@ _ = ixmain +cli_options = [ + [sys.executable, "-m", "ixbrlparse"], + ["ixbrlparse"], +] + def test_cli(): buffer = io.StringIO() @@ -22,13 +28,12 @@ def test_cli(): assert ",CurrentAssets,2909.0," in buffer.getvalue() -def test_cli_raw(tmp_path): +@pytest.mark.parametrize("cli_command", cli_options) +def test_cli_raw(tmp_path, cli_command): f = tmp_path / "output.csv" result = subprocess.run( # noqa: S603 [ - sys.executable, - "-m", - "ixbrlparse", + *cli_command, "--outfile", str(f), "tests/test_accounts/account_1.html", @@ -61,13 +66,12 @@ def test_cli_json(): assert data["numeric"][2]["value"] == 2909.0 -def test_cli_json_raw(tmp_path): +@pytest.mark.parametrize("cli_command", cli_options) +def test_cli_json_raw(tmp_path, cli_command): f = tmp_path / "output.json" result = subprocess.run( # noqa: S603 [ - sys.executable, - "-m", - "ixbrlparse", + *cli_command, "--outfile", str(f), "--format", @@ -103,13 +107,12 @@ def test_cli_unknown_format(): assert not data -def test_cli_unknown_format_raw(tmp_path): +@pytest.mark.parametrize("cli_command", cli_options) +def test_cli_unknown_format_raw(tmp_path, cli_command): f = tmp_path / "output.txt" result = subprocess.run( # noqa: S603 [ - sys.executable, - "-m", - "ixbrlparse", + *cli_command, "--outfile", str(f), "--format", @@ -149,13 +152,12 @@ def test_cli_jsonl(): raise AssertionError(msg) -def test_cli_jsonl_raw(tmp_path): +@pytest.mark.parametrize("cli_command", cli_options) +def test_cli_jsonl_raw(tmp_path, cli_command): f = tmp_path / "output.jsonl" result = subprocess.run( # noqa: S603 [ - sys.executable, - "-m", - "ixbrlparse", + *cli_command, "--outfile", str(f), "--format",