cmdbox.app.features.cli.test package

Submodules

cmdbox.app.features.cli.test.gen_cli_docs module

コマンドリファレンスRST生成ツール。

gen_cli_spec.py が生成した cli-command-specifications.json を元に、 docs_src/docs/ 配下のコマンドリファレンスRSTファイルを新規生成します。

既存のRSTファイルがある場合は上書きします。

使い方 (Python API):

from cmdbox.app.features.cli.test import gen_cli_docs
result = gen_cli_docs.generate(
    specs_dir=Path("Specifications"),
    docs_dir=Path("docs_src/docs"),
    mode_filter=None,   # None で全モード
    cmd_filter=None,    # None で全コマンド
    dry_run=False,
)
cmdbox.app.features.cli.test.gen_cli_docs.generate(specs_dir: Path, docs_dir: Path, mode_filter: str | None = None, cmd_filter: list[str] | None = None, dry_run: bool = False) → dict[str, Any][source]

詳細設計書の内容からコマンドリファレンスRSTを生成します。

Parameters:
  • specs_dir -- Specificationsディレクトリのパス(cli-command-specifications.json が存在する)

  • docs_dir -- cmd_*.rst を出力するディレクトリのパス

  • mode_filter -- 生成対象をモード名でフィルタ。None で全モード

  • cmd_filter -- 生成対象をコマンド名でフィルタ。None で全コマンド

  • dry_run -- True のとき実際にはファイルを書き込まない(変更内容のみ返す)

Returns:

generated, skipped, errors を含む辞書

cmdbox.app.features.cli.test.gen_cli_spec module

CLIコマンド詳細設計書生成ツール。

cmdboxを拡張して作成したコマンドでも利用できるよう、 フィーチャーパッケージ名や出力先をパラメータとして受け取ります。

使い方 (コマンドライン):

python -m cmdbox.tools.test.generate_cli_specifications \
    --feature-package myapp.app.features.cli \
    --output-dir path/to/Specifications \
    --root-dir path/to/project

使い方 (Python API):

from cmdbox.tools.test.generate_cli_specifications import generate
generate(
    feature_package="myapp.app.features.cli",
    output_dir=Path("path/to/Specifications"),
    root_dir=Path("path/to/project"),
    appcls=MyApp,
    ver=my_version_module,
)
class cmdbox.app.features.cli.test.gen_cli_spec.MethodInfo(name: 'str', defining_class: 'str', docstring: 'str', steps: 'list[str]', result_keys: 'list[str]', statuses: 'list[str]', source_lines: 'str')[source]

Bases: object

defining_class: str
docstring: str
name: str
result_keys: list[str]
source_lines: str
statuses: list[str]
steps: list[str]
cmdbox.app.features.cli.test.gen_cli_spec.build_command_spec(mode: str, cmd: str, feature_obj: Any, option_def: dict[str, Any], docs_dir: Path, root_dir: Path) → dict[str, Any][source]

フィーチャーオブジェクトから完全なコマンド仕様を構築します。

Parameters:
  • mode -- コマンドモード (例: 'app', 'sv')

  • cmd -- コマンド名

  • feature_obj -- フィーチャーオブジェクトのインスタンス

  • option_def -- フィーチャーのオプション定義

  • docs_dir -- マークダウン出力先ディレクトリ

  • root_dir -- プロジェクトルートディレクトリ

Returns:

完全なコマンド仕様を含む辞書

cmdbox.app.features.cli.test.gen_cli_spec.collect_helper_methods(cls: type, source_file: Path) → list[dict[str, Any]][source]

クラス内の補助メソッド情報を収集します。

cmdbox.app.features.cli.test.gen_cli_spec.collect_method_info(cls: type, source_file: Path, method_name: str) → MethodInfo[source]

メソッドの詳細情報を収集します。

cmdbox.app.features.cli.test.gen_cli_spec.collect_result_keys(node: AST) → list[str][source]

returnステートメントと代入からの結果辞書キーを抽出します。

cmdbox.app.features.cli.test.gen_cli_spec.collect_statuses(node: AST) → list[str][source]

ASTからステータスコード (RESP_* 属性と整数定数) を抽出します。

cmdbox.app.features.cli.test.gen_cli_spec.find_class_node(tree: AST, class_name: str) → ClassDef | None[source]

ASTから名前でクラス定義ノードを検索します。

cmdbox.app.features.cli.test.gen_cli_spec.generate(feature_package: str, output_dir: Path, root_dir: Path, prefix: str = 'cmdbox_', appcls: Any = None, ver: Any = None, language: str = 'ja_JP') → list[dict[str, Any]][source]

フィーチャーパッケージからCLIコマンド仕様を生成します。

Parameters:
  • feature_package -- フィーチャーを含むPythonパッケージ名 (例: cmdbox.app.features.cli, myapp.app.features.cli)

  • output_dir -- 仕様書の出力先ディレクトリ

  • root_dir -- プロジェクトルートディレクトリ (ソースファイルの相対パス計算に使用)

  • prefix -- フィーチャーモジュールのファイル名プレフィックス (デフォルト: cmdbox_)

  • appcls -- アプリケーションクラス (省略時はCmdBoxAppを使用)

  • ver -- バージョンモジュール (省略時は``cmdbox.version``を使用)

  • language -- 言語設定 (デフォルト: ja_JP)

Returns:

生成された仕様書の辞書リスト

cmdbox.app.features.cli.test.gen_cli_spec.main() → None[source]

コマンドラインから詳細設計書を生成します。

デフォルトでは cmdbox.app.features.cli を対象にします。 --feature-package オプションで任意のフィーチャーパッケージを指定できます。

cmdbox.app.features.cli.test.gen_test_spec module

ユニットテスト仕様書生成ツール。

cmdboxを拡張して作成したコマンドでも利用できるよう、 入力JSONパスや出力先をパラメータとして受け取ります。

使い方 (コマンドライン):

python -m cmdbox.tools.test.generate_unit_test_specifications \
    --input-json path/to/Specifications/cli-command-specifications.json \
    --output-dir path/to/Specifications_forUnitTest \
    --root-dir path/to/project

使い方 (Python API):

from cmdbox.tools.test.generate_unit_test_specifications import generate
generate(
    input_json=Path("path/to/Specifications/cli-command-specifications.json"),
    output_dir=Path("path/to/Specifications_forUnitTest"),
    root_dir=Path("path/to/project"),
)
class cmdbox.app.features.cli.test.gen_test_spec.TestCase(category: 'str', focus: 'str', input_pattern: 'str', expected_status: 'str', expected_result: 'str', post_checks: 'str', input_values: 'dict[str, Any] | None' = None, from_create_tests: 'bool' = False, create_tests_name: 'str | None' = None)[source]

Bases: object

category: str
create_tests_name: str | None = None
expected_result: str
expected_status: str
focus: str
from_create_tests: bool = False
input_pattern: str
input_values: dict[str, Any] | None = None
post_checks: str
cmdbox.app.features.cli.test.gen_test_spec.build_unit_test_spec(command_spec: dict[str, Any], docs_dir: Path, root_dir: Path, all_specs: list[dict[str, Any]] | None = None, appcls: Any = None, ver: Any = None) → dict[str, Any][source]

コマンドの完全なユニットテスト仕様を構築します。

Parameters:
  • command_spec -- CLI仕様JSONからのコマンド仕様

  • docs_dir -- マークダウン出力先ディレクトリ

  • root_dir -- プロジェクトルートディレクトリ

  • all_specs -- 全コマンド仕様のリスト (pre/post_cmds 推定用)

  • appcls -- UnitTestable.create_tests() 呼び出し用アプリケーションクラス (省略可)

  • ver -- UnitTestable.create_tests() 呼び出し用バージョンモジュール (省略可)

Returns:

完全なユニットテスト仕様の辞書

cmdbox.app.features.cli.test.gen_test_spec.extract_test_cases_from_markdown(spec_file_path: Path) → list[TestCase][source]

マークダウン仕様ファイルからテストパターン表を抽出します。

表の形式: | ID | 分類 | 観点 | 入力パターン | 期待終了コード | 期待結果 | 追加確認 | | TC-001 | 正常系 | ... | ... | ... | ... | ... |

cmdbox.app.features.cli.test.gen_test_spec.generate(input_json: Path, output_dir: Path, root_dir: Path, appcls: Any = None, ver: Any = None) → list[dict[str, Any]][source]

CLIコマンド仕様JSONからユニットテスト仕様を生成します。

Parameters:
  • input_json -- 入力となる cli-command-specifications.json のパス

  • output_dir -- テスト仕様書の出力先ディレクトリ

  • root_dir -- プロジェクトルートディレクトリ (詳細設計書マークダウンの参照に使用)

  • appcls -- UnitTestable.create_tests() 呼び出し用アプリケーションクラス (省略可)

  • ver -- UnitTestable.create_tests() 呼び出し用バージョンモジュール (省略可)

Returns:

生成されたテスト仕様書の辞書リスト

cmdbox.app.features.cli.test.gen_test_spec.main() → None[source]

コマンドラインからユニットテスト仕様書を生成します。

デフォルトでは <root-dir>/Specifications/cli-command-specifications.json を読み込み、 <root-dir>/Specifications_forUnitTest に出力します。

cmdbox.app.features.cli.test.run_spec module

テスト仕様JSONに基づいてテストを実行するライブラリ。

cmdboxを拡張して作成したコマンドでも利用できるよう、 入力JSONパスやフィルタ条件をパラメータとして受け取ります。

使い方 (Python API):

from cmdbox.app.features.cli.test import run_spec
result = run_spec.run(
    input_json=Path("path/to/Specifications_forUnitTest/cli-unit-test-specifications.json"),
    mode_filter="server",
    cmd_filter="list",
    appcls=MyApp,
    ver=my_version_module,
)
cmdbox.app.features.cli.test.run_spec.run(input_json: Path, mode_filter: str | None = None, cmd_filter: list[str] | None = None, appcls: Any = None, ver: Any = None, use_tempdir: bool = True, output_dir: Path | None = None, merge_existing: bool = False) → dict[str, Any][source]

テスト仕様JSONに基づいてテストを実行します。

Parameters:
  • input_json -- 入力となる cli-unit-test-specifications.json のパス

  • mode_filter -- 実行対象をモード名でフィルタ。None で全モード対象

  • cmd_filter -- 実行対象をコマンド名でフィルタ。None で全コマンド対象

  • appcls -- フィーチャーインスタンス生成に使用するアプリクラス

  • ver -- フィーチャーインスタンス生成に使用するバージョンモジュール

  • use_tempdir -- True のとき出力系パラメータを一時ディレクトリに置換する

  • output_dir -- 結果 JSON / MD ファイルの出力先ディレクトリ。None のとき出力しない

  • merge_existing -- True のとき既存の結果ファイルと今回の結果をマージする

Returns:

summary と results を含む辞書

Module contents