# Path: jacquard/cli.py
# SUBCOMMAND_GROUPS = (("list", "show lists of various topics"), ("show", "show items"))
# def _add_subparsers_from_plugins(subparsers, plugin_group):
# def _add_help_command(parser, subparsers):
#     def _help(config, options):
# def _build_argument_parser(cwd=None):
# def argument_parser():
# def _configure_process_and_load_config_from_options(options, override_config=None):
# def main(args=sys.argv[1:], config=None):
# 
# Path: jacquard/storage/dummy.py
# class DummyStore(StorageEngine):
#     """Dummy, in-memory storage engine."""
# 
#     def __init__(self, connection_string, *, data=None):
#         """
#         Make it so.
# 
#         The connection string is ignored. If the magic keyword argument `data`
#         is provided it is used for the initial data - very handy for unit
#         tests!
#         """
#         if data is not None:
#             self.data = {key: json.dumps(value) for key, value in data.items()}
#         else:
#             self.data = {}
#         self.lock = threading.Lock()
# 
#     def __getitem__(self, key):
#         """Direct item access. This is for test usage."""
#         return json.loads(self.data.get(key, "null"))
# 
#     def begin(self):
#         """Begin transaction."""
#         self.lock.acquire()
# 
#     def commit(self, changes, deletions):
#         """Commit transaction."""
#         self.data.update(changes)
#         for deletion in deletions:
#             del self.data[deletion]
#         self.lock.release()
# 
#     def rollback(self):
#         """Roll back transaction."""
#         self.lock.release()
# 
#     def keys(self):
#         """All keys."""
#         return self.data.keys()
# 
#     def get(self, key):
#         """Get value."""
#         return self.data.get(key)


import io
import textwrap
import contextlib
import unittest.mock
import pytest
from jacquard.cli import CommandError, main, argument_parser
from jacquard.storage.dummy import DummyStore
    ERROR_MESSAGE = "MOCK ERROR: Something went wrong in the"

    mock_parser = unittest.mock.Mock()
    mock_options = unittest.mock.Mock()
    mock_options.func = unittest.mock.Mock(side_effect=CommandError(ERROR_MESSAGE))
    mock_parser.parse_args = unittest.mock.Mock(return_value=mock_options)

    stderr = io.StringIO()
    with contextlib.redirect_stderr(stderr), pytest.raises(SystemExit):
        with unittest.mock.patch(
            "jacquard.cli.argument_parser", return_value=mock_parser
        ):
            main(["command"], config=config)

    assert stderr.getvalue() == ERROR_MESSAGE + "\n"


def test_argument_parser_has_description():
    parser = argument_parser()

    assert parser.description is not None


def test_jacquard_help_without_args_gives_dash_dash_help():
    config = unittest.mock.Mock()

    stdout_reference = io.StringIO()
    stdout_actual = io.StringIO()

    with contextlib.redirect_stdout(stdout_reference), pytest.raises(SystemExit):

# Path: jacquard/cli.py
# SUBCOMMAND_GROUPS = (("list", "show lists of various topics"), ("show", "show items"))
# def _add_subparsers_from_plugins(subparsers, plugin_group):
# def _add_help_command(parser, subparsers):
#     def _help(config, options):
# def _build_argument_parser(cwd=None):
# def argument_parser():
# def _configure_process_and_load_config_from_options(options, override_config=None):
# def main(args=sys.argv[1:], config=None):
# 
# Path: jacquard/storage/dummy.py
# class DummyStore(StorageEngine):
#     """Dummy, in-memory storage engine."""
# 
#     def __init__(self, connection_string, *, data=None):
#         """
#         Make it so.
# 
#         The connection string is ignored. If the magic keyword argument `data`
#         is provided it is used for the initial data - very handy for unit
#         tests!
#         """
#         if data is not None:
#             self.data = {key: json.dumps(value) for key, value in data.items()}
#         else:
#             self.data = {}
#         self.lock = threading.Lock()
# 
#     def __getitem__(self, key):
#         """Direct item access. This is for test usage."""
#         return json.loads(self.data.get(key, "null"))
# 
#     def begin(self):
#         """Begin transaction."""
#         self.lock.acquire()
# 
#     def commit(self, changes, deletions):
#         """Commit transaction."""
#         self.data.update(changes)
#         for deletion in deletions:
#             del self.data[deletion]
#         self.lock.release()
# 
#     def rollback(self):
#         """Roll back transaction."""
#         self.lock.release()
# 
#     def keys(self):
#         """All keys."""
#         return self.data.keys()
# 
#     def get(self, key):
#         """Get value."""
#         return self.data.get(key)


# Path: jacquard/tests/test_cli.py
import io
import textwrap
import contextlib
import unittest.mock
import pytest
from jacquard.cli import CommandError, main, argument_parser
from jacquard.storage.dummy import DummyStore

    ERROR_MESSAGE = "MOCK ERROR: Something went wrong in the"

    mock_parser = unittest.mock.Mock()
    mock_options = unittest.mock.Mock()
    mock_options.func = unittest.mock.Mock(side_effect=CommandError(ERROR_MESSAGE))
    mock_parser.parse_args = unittest.mock.Mock(return_value=mock_options)

    stderr = io.StringIO()
    with contextlib.redirect_stderr(stderr), pytest.raises(SystemExit):
        with unittest.mock.patch(
            "jacquard.cli.argument_parser", return_value=mock_parser
        ):
            main(["command"], config=config)

    assert stderr.getvalue() == ERROR_MESSAGE + "\n"


def test_argument_parser_has_description():
    parser = argument_parser()

    assert parser.description is not None


def test_jacquard_help_without_args_gives_dash_dash_help():
    config = unittest.mock.Mock()

    stdout_reference = io.StringIO()
    stdout_actual = io.StringIO()

    with contextlib.redirect_stdout(stdout_reference), pytest.raises(SystemExit):

        main(["--help"], config=config)