# Path: tests/function/utils.py
# def call_zhmc_child(args, env=None):
#     """
#     Invoke the 'zhmc' command as a child process.
# 
#     This requires that the 'zhmc' command is installed in the current Python
#     environment.
# 
#     Parameters:
# 
#       args (iterable of :term:`string`): Command line arguments, without the
#         command name.
#         Each single argument must be its own item in the iterable; combining
#         the arguments into a string that is provided as a single argument is
#         not allowed.
#         The arguments may be binary strings encoded in UTF-8, or unicode
#         strings.
# 
#       env (dict): Environment variables to be put into the environment when
#         calling the command. May be `None`. Dict key is the variable name as a
#         :term:`string`; dict value is the variable value as a :term:`string`
#         (without any shell escaping needed).
# 
#     Returns:
# 
#       tuple(rc, stdout, stderr): Output of the command, where:
# 
#         * rc(int): Exit code of the command.
#         * stdout(:term:`unicode string`): Standard output of the command,
#           as a unicode string with newlines represented as '\\n'.
#           An empty string, if there was no data.
#         * stderr(:term:`unicode string`): Standard error of the command,
#           as a unicode string with newlines represented as '\\n'.
#           An empty string, if there was no data.
#     """
# 
#     cli_cmd = u'zhmc'
# 
#     if env is None:
#         env = {}
#     else:
#         env = copy(env)
# 
#     # Unset the zhmc-specific env vars if not provided:
#     if 'ZHMC_HOST' not in env:
#         env['ZHMC_HOST'] = None
#     if 'ZHMC_USERID' not in env:
#         env['ZHMC_USERID'] = None
#     if 'ZHMC_SESSION_ID' not in env:
#         env['ZHMC_SESSION_ID'] = None
# 
#     env['PYTHONPATH'] = '.'  # Use local files
#     env['PYTHONWARNINGS'] = ''  # Disable for parsing output
# 
#     # Put the env vars into the environment of the current Python process,
#     # from where they will be inherited into its child processes (-> shell ->
#     # cli command).
#     for name in env:
#         value = env[name]
#         if value is None:
#             if name in os.environ:
#                 del os.environ[name]
#         else:
#             os.environ[name] = value
# 
#     assert isinstance(args, (list, tuple))
#     cmd_args = [cli_cmd]
#     for arg in args:
#         if not isinstance(arg, six.text_type):
#             arg = arg.decode('utf-8')
#         cmd_args.append(arg)
# 
#     # Note that the click package on Windows writes '\n' at the Python level
#     # as '\r\n' at the level of the shell. Some other layer (presumably the
#     # Windows shell) contriubutes another such translation, so we end up with
#     # '\r\r\n' for each '\n'. Using universal_newlines=True undoes all of that.
# 
#     # pylint: disable=consider-using-with
#     proc = Popen(cmd_args, shell=False, stdout=PIPE, stderr=PIPE,
#                  universal_newlines=True)
#     stdout_str, stderr_str = proc.communicate()
#     rc = proc.returncode
# 
#     if isinstance(stdout_str, six.binary_type):
#         stdout_str = stdout_str.decode('utf-8')
#     if isinstance(stderr_str, six.binary_type):
#         stderr_str = stderr_str.decode('utf-8')
# 
#     return rc, stdout_str, stderr_str
# 
# def assert_rc(exp_rc, rc, stdout, stderr):
#     """
#     Assert that the specified return code is as expected.
# 
#     The actual return code is compared with the expected return code,
#     and if they don't match, stdout and stderr are displayed as a means
#     to help debugging the issue.
# 
#     Parameters:
# 
#       exp_rc (int): expected return code.
# 
#       rc (int): actual return code.
# 
#       stdout (string): stdout of the command, for debugging purposes.
# 
#       stderr (string): stderr of the command, for debugging purposes.
#     """
# 
#     assert exp_rc == rc, \
#         "Unexpected exit code (expected {e}, got {g})\n" \
#         "  stdout:\n" \
#         "{so}\n" \
#         "  stderr:\n" \
#         "{se}". \
#         format(e=exp_rc, g=rc, so=stdout, se=stderr)


import re
from .utils import call_zhmc_child, assert_rc

from __future__ import absolute_import, print_function




class TestGlobalOptions(object):
    """
    All tests for the 'zhmc' command with global options that can be tested
    without a subcommand.
    """

    def test_global_help(self):
        # pylint: disable=no-self-use
        """Test 'zhmc --help'"""

        rc, stdout, stderr = call_zhmc_child(['--help'])

        assert_rc(0, rc, stdout, stderr)
        assert stdout.startswith(
            "Usage: zhmc [GENERAL-OPTIONS] COMMAND [ARGS]...\n"), \
            "stdout={s!r}".format(s=stdout)
        assert stderr == ""

    def test_global_version(self):
        # pylint: disable=no-self-use
        """Test 'zhmc --version'"""

        rc, stdout, stderr = call_zhmc_child(['--version'])


# Path: tests/function/utils.py
# def call_zhmc_child(args, env=None):
#     """
#     Invoke the 'zhmc' command as a child process.
# 
#     This requires that the 'zhmc' command is installed in the current Python
#     environment.
# 
#     Parameters:
# 
#       args (iterable of :term:`string`): Command line arguments, without the
#         command name.
#         Each single argument must be its own item in the iterable; combining
#         the arguments into a string that is provided as a single argument is
#         not allowed.
#         The arguments may be binary strings encoded in UTF-8, or unicode
#         strings.
# 
#       env (dict): Environment variables to be put into the environment when
#         calling the command. May be `None`. Dict key is the variable name as a
#         :term:`string`; dict value is the variable value as a :term:`string`
#         (without any shell escaping needed).
# 
#     Returns:
# 
#       tuple(rc, stdout, stderr): Output of the command, where:
# 
#         * rc(int): Exit code of the command.
#         * stdout(:term:`unicode string`): Standard output of the command,
#           as a unicode string with newlines represented as '\\n'.
#           An empty string, if there was no data.
#         * stderr(:term:`unicode string`): Standard error of the command,
#           as a unicode string with newlines represented as '\\n'.
#           An empty string, if there was no data.
#     """
# 
#     cli_cmd = u'zhmc'
# 
#     if env is None:
#         env = {}
#     else:
#         env = copy(env)
# 
#     # Unset the zhmc-specific env vars if not provided:
#     if 'ZHMC_HOST' not in env:
#         env['ZHMC_HOST'] = None
#     if 'ZHMC_USERID' not in env:
#         env['ZHMC_USERID'] = None
#     if 'ZHMC_SESSION_ID' not in env:
#         env['ZHMC_SESSION_ID'] = None
# 
#     env['PYTHONPATH'] = '.'  # Use local files
#     env['PYTHONWARNINGS'] = ''  # Disable for parsing output
# 
#     # Put the env vars into the environment of the current Python process,
#     # from where they will be inherited into its child processes (-> shell ->
#     # cli command).
#     for name in env:
#         value = env[name]
#         if value is None:
#             if name in os.environ:
#                 del os.environ[name]
#         else:
#             os.environ[name] = value
# 
#     assert isinstance(args, (list, tuple))
#     cmd_args = [cli_cmd]
#     for arg in args:
#         if not isinstance(arg, six.text_type):
#             arg = arg.decode('utf-8')
#         cmd_args.append(arg)
# 
#     # Note that the click package on Windows writes '\n' at the Python level
#     # as '\r\n' at the level of the shell. Some other layer (presumably the
#     # Windows shell) contriubutes another such translation, so we end up with
#     # '\r\r\n' for each '\n'. Using universal_newlines=True undoes all of that.
# 
#     # pylint: disable=consider-using-with
#     proc = Popen(cmd_args, shell=False, stdout=PIPE, stderr=PIPE,
#                  universal_newlines=True)
#     stdout_str, stderr_str = proc.communicate()
#     rc = proc.returncode
# 
#     if isinstance(stdout_str, six.binary_type):
#         stdout_str = stdout_str.decode('utf-8')
#     if isinstance(stderr_str, six.binary_type):
#         stderr_str = stderr_str.decode('utf-8')
# 
#     return rc, stdout_str, stderr_str
# 
# def assert_rc(exp_rc, rc, stdout, stderr):
#     """
#     Assert that the specified return code is as expected.
# 
#     The actual return code is compared with the expected return code,
#     and if they don't match, stdout and stderr are displayed as a means
#     to help debugging the issue.
# 
#     Parameters:
# 
#       exp_rc (int): expected return code.
# 
#       rc (int): actual return code.
# 
#       stdout (string): stdout of the command, for debugging purposes.
# 
#       stderr (string): stderr of the command, for debugging purposes.
#     """
# 
#     assert exp_rc == rc, \
#         "Unexpected exit code (expected {e}, got {g})\n" \
#         "  stdout:\n" \
#         "{so}\n" \
#         "  stderr:\n" \
#         "{se}". \
#         format(e=exp_rc, g=rc, so=stdout, se=stderr)


# Path: tests/function/test_global_opts.py
import re
from .utils import call_zhmc_child, assert_rc


from __future__ import absolute_import, print_function




class TestGlobalOptions(object):
    """
    All tests for the 'zhmc' command with global options that can be tested
    without a subcommand.
    """

    def test_global_help(self):
        # pylint: disable=no-self-use
        """Test 'zhmc --help'"""

        rc, stdout, stderr = call_zhmc_child(['--help'])

        assert_rc(0, rc, stdout, stderr)
        assert stdout.startswith(
            "Usage: zhmc [GENERAL-OPTIONS] COMMAND [ARGS]...\n"), \
            "stdout={s!r}".format(s=stdout)
        assert stderr == ""

    def test_global_version(self):
        # pylint: disable=no-self-use
        """Test 'zhmc --version'"""

        rc, stdout, stderr = call_zhmc_child(['--version'])


        assert_rc(0, rc, stdout, stderr)