# Path: tests/conftest.py
# def run_cmd(app, cmd):
#     """Clear out and err StdSim buffers, run the command, and return out and err"""
#     saved_sysout = sys.stdout
#     sys.stdout = app.stdout
# 
#     # This will be used to capture app.stdout and sys.stdout
#     copy_cmd_stdout = StdSim(app.stdout)
# 
#     # This will be used to capture sys.stderr
#     copy_stderr = StdSim(sys.stderr)
# 
#     try:
#         app.stdout = copy_cmd_stdout
#         with redirect_stdout(copy_cmd_stdout):
#             with redirect_stderr(copy_stderr):
#                 app.onecmd_plus_hooks(cmd)
#     finally:
#         app.stdout = copy_cmd_stdout.inner_stream
#         sys.stdout = saved_sysout
# 
#     out = copy_cmd_stdout.getvalue()
#     err = copy_stderr.getvalue()
#     return normalize(out), normalize(err)


import argparse
import pytest
import cmd2
from typing import (
    Optional,
)
from .conftest import (
    run_cmd,
)
    from unittest import (
        mock,
    )
    from cmd2 import (
        CommandSetRegistrationError,
    )
    from cmd2 import (
        CommandSetRegistrationError,
    )
    out, err = run_cmd(subcommand_app, 'help base')
    assert out[0].startswith('Usage: base')
    assert out[1] == ''
    assert out[2] == 'Base command help'


def test_subcommand_help(subcommand_app):
    # foo has no aliases
    out, err = run_cmd(subcommand_app, 'help base foo')
    assert out[0].startswith('Usage: base foo')
    assert out[1] == ''
    assert out[2] == 'positional arguments:'

    # bar has aliases (usage should never show alias name)
    out, err = run_cmd(subcommand_app, 'help base bar')
    assert out[0].startswith('Usage: base bar')
    assert out[1] == ''
    assert out[2] == 'positional arguments:'

    out, err = run_cmd(subcommand_app, 'help base bar_1')
    assert out[0].startswith('Usage: base bar')
    assert out[1] == ''
    assert out[2] == 'positional arguments:'

    out, err = run_cmd(subcommand_app, 'help base bar_2')
    assert out[0].startswith('Usage: base bar')
    assert out[1] == ''
    assert out[2] == 'positional arguments:'

    # helpless has aliases and no help text (usage should never show alias name)

# Path: tests/conftest.py
# def run_cmd(app, cmd):
#     """Clear out and err StdSim buffers, run the command, and return out and err"""
#     saved_sysout = sys.stdout
#     sys.stdout = app.stdout
# 
#     # This will be used to capture app.stdout and sys.stdout
#     copy_cmd_stdout = StdSim(app.stdout)
# 
#     # This will be used to capture sys.stderr
#     copy_stderr = StdSim(sys.stderr)
# 
#     try:
#         app.stdout = copy_cmd_stdout
#         with redirect_stdout(copy_cmd_stdout):
#             with redirect_stderr(copy_stderr):
#                 app.onecmd_plus_hooks(cmd)
#     finally:
#         app.stdout = copy_cmd_stdout.inner_stream
#         sys.stdout = saved_sysout
# 
#     out = copy_cmd_stdout.getvalue()
#     err = copy_stderr.getvalue()
#     return normalize(out), normalize(err)


# Path: tests/test_argparse.py
import argparse
import pytest
import cmd2
from typing import (
    Optional,
)
from .conftest import (
    run_cmd,
)
    from unittest import (
        mock,
    )
    from cmd2 import (
        CommandSetRegistrationError,
    )
    from cmd2 import (
        CommandSetRegistrationError,
    )

    out, err = run_cmd(subcommand_app, 'help base')
    assert out[0].startswith('Usage: base')
    assert out[1] == ''
    assert out[2] == 'Base command help'


def test_subcommand_help(subcommand_app):
    # foo has no aliases
    out, err = run_cmd(subcommand_app, 'help base foo')
    assert out[0].startswith('Usage: base foo')
    assert out[1] == ''
    assert out[2] == 'positional arguments:'

    # bar has aliases (usage should never show alias name)
    out, err = run_cmd(subcommand_app, 'help base bar')
    assert out[0].startswith('Usage: base bar')
    assert out[1] == ''
    assert out[2] == 'positional arguments:'

    out, err = run_cmd(subcommand_app, 'help base bar_1')
    assert out[0].startswith('Usage: base bar')
    assert out[1] == ''
    assert out[2] == 'positional arguments:'

    out, err = run_cmd(subcommand_app, 'help base bar_2')
    assert out[0].startswith('Usage: base bar')
    assert out[1] == ''
    assert out[2] == 'positional arguments:'

    # helpless has aliases and no help text (usage should never show alias name)

    out, err = run_cmd(subcommand_app, 'help base helpless')