# Path: osprofiler/cmd/shell.py
# class OSProfilerShell(object):
#     def __init__(self, argv):
#     def _get_base_parser(self):
#     def _append_subcommands(self, parent_parser):
#     def _no_project_and_domain_set(self, args):
# def main(args=None):
# 
# Path: osprofiler/exc.py
# class CommandError(Exception):
# class LogInsightAPIError(Exception):
# class LogInsightLoginTimeout(Exception):
#     def __init__(self, message=None):
#     def __str__(self):
# 
# Path: osprofiler/tests/test.py
# class TestCase(testcase.TestCase):
# class FunctionalTestCase(TestCase):
#     def setUp(self):


import io
import json
import os
import sys
import ddt
from unittest import mock
from osprofiler.cmd import shell
from osprofiler import exc
from osprofiler.tests import test
@ddt.ddt
class ShellTestCase(test.TestCase):

    TRACE_ID = "c598094d-bbee-40b6-b317-d76003b679d3"

    def setUp(self):
        super(ShellTestCase, self).setUp()
        self.old_environment = os.environ.copy()

    def tearDown(self):
        super(ShellTestCase, self).tearDown()
        os.environ = self.old_environment

    def _trace_show_cmd(self, format_=None):
        cmd = "trace show --connection-string redis:// %s" % self.TRACE_ID
        return cmd if format_ is None else "%s --%s" % (cmd, format_)

    @mock.patch("sys.stdout", io.StringIO())
    @mock.patch("osprofiler.cmd.shell.OSProfilerShell")
    def test_shell_main(self, mock_shell):
        mock_shell.side_effect = exc.CommandError("some_message")
        shell.main()
        self.assertEqual("some_message\n", sys.stdout.getvalue())

    def run_command(self, cmd):
        shell.OSProfilerShell(cmd.split())

    def _test_with_command_error(self, cmd, expected_message):
        try:
            self.run_command(cmd)

# Path: osprofiler/cmd/shell.py
# class OSProfilerShell(object):
#     def __init__(self, argv):
#     def _get_base_parser(self):
#     def _append_subcommands(self, parent_parser):
#     def _no_project_and_domain_set(self, args):
# def main(args=None):
# 
# Path: osprofiler/exc.py
# class CommandError(Exception):
# class LogInsightAPIError(Exception):
# class LogInsightLoginTimeout(Exception):
#     def __init__(self, message=None):
#     def __str__(self):
# 
# Path: osprofiler/tests/test.py
# class TestCase(testcase.TestCase):
# class FunctionalTestCase(TestCase):
#     def setUp(self):


# Path: osprofiler/tests/unit/cmd/test_shell.py
import io
import json
import os
import sys
import ddt
from unittest import mock
from osprofiler.cmd import shell
from osprofiler import exc
from osprofiler.tests import test

@ddt.ddt
class ShellTestCase(test.TestCase):

    TRACE_ID = "c598094d-bbee-40b6-b317-d76003b679d3"

    def setUp(self):
        super(ShellTestCase, self).setUp()
        self.old_environment = os.environ.copy()

    def tearDown(self):
        super(ShellTestCase, self).tearDown()
        os.environ = self.old_environment

    def _trace_show_cmd(self, format_=None):
        cmd = "trace show --connection-string redis:// %s" % self.TRACE_ID
        return cmd if format_ is None else "%s --%s" % (cmd, format_)

    @mock.patch("sys.stdout", io.StringIO())
    @mock.patch("osprofiler.cmd.shell.OSProfilerShell")
    def test_shell_main(self, mock_shell):
        mock_shell.side_effect = exc.CommandError("some_message")
        shell.main()
        self.assertEqual("some_message\n", sys.stdout.getvalue())

    def run_command(self, cmd):
        shell.OSProfilerShell(cmd.split())

    def _test_with_command_error(self, cmd, expected_message):
        try:
            self.run_command(cmd)

        except exc.CommandError as actual_error: