# Path: scripnix/pybin/describe_scripnix.py
# COMMAND_NAME = "describe-scripnix"
# 
# @common_command_and_options(command_name=COMMAND_NAME)
# def main():
#     """ Generate descriptions of all of the Scripnix commands in Markdown format, suitable for appending to the Scripnix project's README.md
#         file.
# 
#         The describe-scripnix command is part of Scripnix.
#     """
#     pybin_path = os.path.abspath(os.path.dirname(__file__))
#     shbin_path = os.path.abspath(os.path.join(pybin_path, "../shbin"))
#     paths_exclusions = ((pybin_path, scripnix.NON_COMMANDS['pybin']), (shbin_path, scripnix.NON_COMMANDS['shbin']))
#     click.echo(format_commands(paths_exclusions))
# 
# Path: tests/command.py
# def common_help_option(command_entry, command_name):
#     """ Test help message for both standard option switches."""
#     def version_option_switch(option_switch):
#         runner = CliRunner()
#         result = runner.invoke(command_entry, [option_switch])
#         assert result.exit_code == 0
#         match = HELP_OPTION_REGEX.match(result.output.replace("\n", ""))
#         assert match.group(1) == command_name
# 
#     version_option_switch("-h")
#     version_option_switch("--help")
# 
# def common_version_option(command_entry, command_name):
#     """ Test version message for both standard option switches."""
#     def version_option_switch(option_switch):
#         runner = CliRunner()
#         result = runner.invoke(command_entry, [option_switch])
#         assert result.exit_code == 0
#         match = VERSION_OPTION_REGEX.match(result.output.replace("\n", ""))
#         assert match.group(1) == command_name
#         assert match.group(2) == __version__
# 
#     version_option_switch("-V")
#     version_option_switch("--version")


import os
import re
import scripnix
from click.testing import CliRunner
from scripnix.pybin.describe_scripnix import COMMAND_NAME, main
from .command import common_help_option, common_version_option
"""

# This file is part of Scripnix. Copyright 2016 Dave Rogers <info@yukondude.com>. Licensed under the GNU General Public License, version 3.
# Refer to the attached LICENSE file or see <http://www.gnu.org/licenses/> for details.






def test_help_option():
    common_help_option(command_entry=main, command_name=COMMAND_NAME)


def test_main():
    result = CliRunner().invoke(main)
    help_text = result.output
    assert len(help_text) > 0

    here = os.path.abspath(os.path.dirname(__file__))
    path = os.path.abspath(os.path.join(here, "../scripnix/pybin"))
    command_files = [f for f in os.listdir(path) if f not in scripnix.NON_COMMANDS['pybin'] and os.path.isfile(os.path.join(path, f))]
    commands = [os.path.splitext(f)[0].replace('_', '-') for f in command_files]

    for command in commands:
        assert re.search("^### `{}`$".format(command), help_text, re.MULTILINE) is not None
        assert re.search("^Usage: {}".format(command), help_text, re.MULTILINE) is not None


def test_version_option():

# Path: scripnix/pybin/describe_scripnix.py
# COMMAND_NAME = "describe-scripnix"
# 
# @common_command_and_options(command_name=COMMAND_NAME)
# def main():
#     """ Generate descriptions of all of the Scripnix commands in Markdown format, suitable for appending to the Scripnix project's README.md
#         file.
# 
#         The describe-scripnix command is part of Scripnix.
#     """
#     pybin_path = os.path.abspath(os.path.dirname(__file__))
#     shbin_path = os.path.abspath(os.path.join(pybin_path, "../shbin"))
#     paths_exclusions = ((pybin_path, scripnix.NON_COMMANDS['pybin']), (shbin_path, scripnix.NON_COMMANDS['shbin']))
#     click.echo(format_commands(paths_exclusions))
# 
# Path: tests/command.py
# def common_help_option(command_entry, command_name):
#     """ Test help message for both standard option switches."""
#     def version_option_switch(option_switch):
#         runner = CliRunner()
#         result = runner.invoke(command_entry, [option_switch])
#         assert result.exit_code == 0
#         match = HELP_OPTION_REGEX.match(result.output.replace("\n", ""))
#         assert match.group(1) == command_name
# 
#     version_option_switch("-h")
#     version_option_switch("--help")
# 
# def common_version_option(command_entry, command_name):
#     """ Test version message for both standard option switches."""
#     def version_option_switch(option_switch):
#         runner = CliRunner()
#         result = runner.invoke(command_entry, [option_switch])
#         assert result.exit_code == 0
#         match = VERSION_OPTION_REGEX.match(result.output.replace("\n", ""))
#         assert match.group(1) == command_name
#         assert match.group(2) == __version__
# 
#     version_option_switch("-V")
#     version_option_switch("--version")


# Path: tests/test_describe_scripnix.py
import os
import re
import scripnix
from click.testing import CliRunner
from scripnix.pybin.describe_scripnix import COMMAND_NAME, main
from .command import common_help_option, common_version_option

"""

# This file is part of Scripnix. Copyright 2016 Dave Rogers <info@yukondude.com>. Licensed under the GNU General Public License, version 3.
# Refer to the attached LICENSE file or see <http://www.gnu.org/licenses/> for details.






def test_help_option():
    common_help_option(command_entry=main, command_name=COMMAND_NAME)


def test_main():
    result = CliRunner().invoke(main)
    help_text = result.output
    assert len(help_text) > 0

    here = os.path.abspath(os.path.dirname(__file__))
    path = os.path.abspath(os.path.join(here, "../scripnix/pybin"))
    command_files = [f for f in os.listdir(path) if f not in scripnix.NON_COMMANDS['pybin'] and os.path.isfile(os.path.join(path, f))]
    commands = [os.path.splitext(f)[0].replace('_', '-') for f in command_files]

    for command in commands:
        assert re.search("^### `{}`$".format(command), help_text, re.MULTILINE) is not None
        assert re.search("^Usage: {}".format(command), help_text, re.MULTILINE) is not None


def test_version_option():

    common_version_option(command_entry=main, command_name=COMMAND_NAME)