# Path: thefuck/types.py
# class Command(object):
#     """Command that should be fixed."""
# 
#     def __init__(self, script, output):
#         """Initializes command with given values.
# 
#         :type script: basestring
#         :type output: basestring
# 
#         """
#         self.script = script
#         self.output = output
# 
#     @property
#     def stdout(self):
#         logs.warn('`stdout` is deprecated, please use `output` instead')
#         return self.output
# 
#     @property
#     def stderr(self):
#         logs.warn('`stderr` is deprecated, please use `output` instead')
#         return self.output
# 
#     @property
#     def script_parts(self):
#         if not hasattr(self, '_script_parts'):
#             try:
#                 self._script_parts = shell.split_command(self.script)
#             except Exception:
#                 logs.debug(u"Can't split command script {} because:\n {}".format(
#                     self, sys.exc_info()))
#                 self._script_parts = []
# 
#         return self._script_parts
# 
#     def __eq__(self, other):
#         if isinstance(other, Command):
#             return (self.script, self.output) == (other.script, other.output)
#         else:
#             return False
# 
#     def __repr__(self):
#         return u'Command(script={}, output={})'.format(
#             self.script, self.output)
# 
#     def update(self, **kwargs):
#         """Returns new command with replaced fields.
# 
#         :rtype: Command
# 
#         """
#         kwargs.setdefault('script', self.script)
#         kwargs.setdefault('output', self.output)
#         return Command(**kwargs)
# 
#     @classmethod
#     def from_raw_script(cls, raw_script):
#         """Creates instance of `Command` from a list of script parts.
# 
#         :type raw_script: [basestring]
#         :rtype: Command
#         :raises: EmptyCommand
# 
#         """
#         script = format_raw_script(raw_script)
#         if not script:
#             raise EmptyCommand
# 
#         expanded = shell.from_shell(script)
#         output = get_output(script, expanded)
#         return cls(expanded, output)


import pytest
import warnings
from mock import Mock, call, patch
from thefuck.utils import default_settings, \
    memoize, get_closest, get_all_executables, replace_argument, \
    get_all_matched_commands, is_app, for_app, cache, \
    get_valid_history_without_current, _cache, get_close_matches
from thefuck.types import Command
      'Did you mean one of these?\n'
      '\trebase\n'
      '\treset\n'
      '\tgrep\n'
      '\trm'), ['rebase', 'reset', 'grep', 'rm']),
    (('tsuru: "target" is not a tsuru command. See "tsuru help".\n'
      '\n'
      'Did you mean one of these?\n'
      '\tservice-add\n'
      '\tservice-bind\n'
      '\tservice-doc\n'
      '\tservice-info\n'
      '\tservice-list\n'
      '\tservice-remove\n'
      '\tservice-status\n'
      '\tservice-unbind'), ['service-add', 'service-bind', 'service-doc',
                            'service-info', 'service-list', 'service-remove',
                            'service-status', 'service-unbind'])])
def test_get_all_matched_commands(stderr, result):
    assert list(get_all_matched_commands(stderr)) == result


@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize('script, names, result', [
    ('/usr/bin/git diff', ['git', 'hub'], True),
    ('/bin/hdfs dfs -rm foo', ['hdfs'], True),
    ('git diff', ['git', 'hub'], True),
    ('hub diff', ['git', 'hub'], True),
    ('hg diff', ['git', 'hub'], False)])
def test_is_app(script, names, result):

# Path: thefuck/types.py
# class Command(object):
#     """Command that should be fixed."""
# 
#     def __init__(self, script, output):
#         """Initializes command with given values.
# 
#         :type script: basestring
#         :type output: basestring
# 
#         """
#         self.script = script
#         self.output = output
# 
#     @property
#     def stdout(self):
#         logs.warn('`stdout` is deprecated, please use `output` instead')
#         return self.output
# 
#     @property
#     def stderr(self):
#         logs.warn('`stderr` is deprecated, please use `output` instead')
#         return self.output
# 
#     @property
#     def script_parts(self):
#         if not hasattr(self, '_script_parts'):
#             try:
#                 self._script_parts = shell.split_command(self.script)
#             except Exception:
#                 logs.debug(u"Can't split command script {} because:\n {}".format(
#                     self, sys.exc_info()))
#                 self._script_parts = []
# 
#         return self._script_parts
# 
#     def __eq__(self, other):
#         if isinstance(other, Command):
#             return (self.script, self.output) == (other.script, other.output)
#         else:
#             return False
# 
#     def __repr__(self):
#         return u'Command(script={}, output={})'.format(
#             self.script, self.output)
# 
#     def update(self, **kwargs):
#         """Returns new command with replaced fields.
# 
#         :rtype: Command
# 
#         """
#         kwargs.setdefault('script', self.script)
#         kwargs.setdefault('output', self.output)
#         return Command(**kwargs)
# 
#     @classmethod
#     def from_raw_script(cls, raw_script):
#         """Creates instance of `Command` from a list of script parts.
# 
#         :type raw_script: [basestring]
#         :rtype: Command
#         :raises: EmptyCommand
# 
#         """
#         script = format_raw_script(raw_script)
#         if not script:
#             raise EmptyCommand
# 
#         expanded = shell.from_shell(script)
#         output = get_output(script, expanded)
#         return cls(expanded, output)


# Path: tests/test_utils.py
import pytest
import warnings
from mock import Mock, call, patch
from thefuck.utils import default_settings, \
    memoize, get_closest, get_all_executables, replace_argument, \
    get_all_matched_commands, is_app, for_app, cache, \
    get_valid_history_without_current, _cache, get_close_matches
from thefuck.types import Command

      'Did you mean one of these?\n'
      '\trebase\n'
      '\treset\n'
      '\tgrep\n'
      '\trm'), ['rebase', 'reset', 'grep', 'rm']),
    (('tsuru: "target" is not a tsuru command. See "tsuru help".\n'
      '\n'
      'Did you mean one of these?\n'
      '\tservice-add\n'
      '\tservice-bind\n'
      '\tservice-doc\n'
      '\tservice-info\n'
      '\tservice-list\n'
      '\tservice-remove\n'
      '\tservice-status\n'
      '\tservice-unbind'), ['service-add', 'service-bind', 'service-doc',
                            'service-info', 'service-list', 'service-remove',
                            'service-status', 'service-unbind'])])
def test_get_all_matched_commands(stderr, result):
    assert list(get_all_matched_commands(stderr)) == result


@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize('script, names, result', [
    ('/usr/bin/git diff', ['git', 'hub'], True),
    ('/bin/hdfs dfs -rm foo', ['hdfs'], True),
    ('git diff', ['git', 'hub'], True),
    ('hub diff', ['git', 'hub'], True),
    ('hg diff', ['git', 'hub'], False)])
def test_is_app(script, names, result):

    assert is_app(Command(script, ''), *names) == result