# Path: thefuck/rules/scm_correction.py
# @for_app(*wrong_scm_patterns.keys())
# def match(command):
#     scm = command.script_parts[0]
#     pattern = wrong_scm_patterns[scm]
# 
#     return pattern in command.output and _get_actual_scm()
# 
# def get_new_command(command):
#     scm = _get_actual_scm()
#     return u' '.join([scm] + command.script_parts[1:])
# 
# 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
from thefuck.rules.scm_correction import match, get_new_command
from thefuck.types import Command
def get_actual_scm_mock(mocker):
    return mocker.patch('thefuck.rules.scm_correction._get_actual_scm',
                        return_value=None)


@pytest.mark.parametrize('script, output, actual_scm', [
    ('git log', 'fatal: Not a git repository '
                '(or any of the parent directories): .git',
     'hg'),
    ('hg log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
               "(.hg not found)!",
     'git')])
def test_match(get_actual_scm_mock, script, output, actual_scm):
    get_actual_scm_mock.return_value = actual_scm
    assert match(Command(script, output))


@pytest.mark.parametrize('script, output, actual_scm', [
    ('git log', '', 'hg'),
    ('git log', 'fatal: Not a git repository '
                '(or any of the parent directories): .git',
     None),
    ('hg log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
               "(.hg not found)!",
     None),
    ('not-scm log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
                    "(.hg not found)!",
     'git')])
def test_not_match(get_actual_scm_mock, script, output, actual_scm):
    get_actual_scm_mock.return_value = actual_scm

# Path: thefuck/rules/scm_correction.py
# @for_app(*wrong_scm_patterns.keys())
# def match(command):
#     scm = command.script_parts[0]
#     pattern = wrong_scm_patterns[scm]
# 
#     return pattern in command.output and _get_actual_scm()
# 
# def get_new_command(command):
#     scm = _get_actual_scm()
#     return u' '.join([scm] + command.script_parts[1:])
# 
# 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/rules/test_scm_correction.py
import pytest
from thefuck.rules.scm_correction import match, get_new_command
from thefuck.types import Command

def get_actual_scm_mock(mocker):
    return mocker.patch('thefuck.rules.scm_correction._get_actual_scm',
                        return_value=None)


@pytest.mark.parametrize('script, output, actual_scm', [
    ('git log', 'fatal: Not a git repository '
                '(or any of the parent directories): .git',
     'hg'),
    ('hg log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
               "(.hg not found)!",
     'git')])
def test_match(get_actual_scm_mock, script, output, actual_scm):
    get_actual_scm_mock.return_value = actual_scm
    assert match(Command(script, output))


@pytest.mark.parametrize('script, output, actual_scm', [
    ('git log', '', 'hg'),
    ('git log', 'fatal: Not a git repository '
                '(or any of the parent directories): .git',
     None),
    ('hg log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
               "(.hg not found)!",
     None),
    ('not-scm log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
                    "(.hg not found)!",
     'git')])
def test_not_match(get_actual_scm_mock, script, output, actual_scm):
    get_actual_scm_mock.return_value = actual_scm

    assert not match(Command(script, output))