Move special data types to types

This commit is contained in:
nvbn
2015-04-22 23:04:22 +02:00
parent 54c408a6b5
commit d3d1f99232
17 changed files with 89 additions and 88 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
from thefuck.main import Command
from thefuck.types import Command
from thefuck.rules.cd_parent import match, get_new_command
+1 -1
View File
@@ -1,5 +1,5 @@
import pytest
from thefuck.main import Command
from thefuck.types import Command
from thefuck.rules.git_not_command import match, get_new_command
+1 -1
View File
@@ -1,5 +1,5 @@
import pytest
from thefuck.main import Command
from thefuck.types import Command
from thefuck.rules.git_push import match, get_new_command
+1 -1
View File
@@ -1,5 +1,5 @@
from mock import Mock, patch
from thefuck.rules. has_exists_script import match, get_new_command
from thefuck.rules.has_exists_script import match, get_new_command
def test_match():
+1 -1
View File
@@ -1,4 +1,4 @@
from thefuck.main import Command
from thefuck.types import Command
from thefuck.rules.mkdir_p import match, get_new_command
+3 -1
View File
@@ -1,9 +1,11 @@
from thefuck.main import Command
from thefuck.types import Command
from thefuck.rules.python_command import match, get_new_command
def test_match():
assert match(Command('temp.py', '', 'Permission denied'), None)
assert not match(Command('', '', ''), None)
def test_get_new_command():
assert get_new_command(Command('./test_sudo.py', '', ''), None) == 'python ./test_sudo.py'
+1 -1
View File
@@ -1,4 +1,4 @@
from thefuck.main import Command
from thefuck.types import Command
from thefuck.rules.rm_dir import match, get_new_command
+1 -1
View File
@@ -1,7 +1,7 @@
import os
import pytest
from mock import Mock
from thefuck.main import Command
from thefuck.types import Command
from thefuck.rules.ssh_known_hosts import match, get_new_command, remove_offending_keys
+1 -1
View File
@@ -1,4 +1,4 @@
from thefuck.main import Command
from thefuck.types import Command
from thefuck.rules.sudo import match, get_new_command
+1 -15
View File
@@ -1,15 +1,8 @@
from mock import patch, Mock
from thefuck.main import Rule
from thefuck.types import Rule
from thefuck import conf
def test_rules_names_list():
assert conf.RulesNamesList(['bash', 'lisp']) == ['bash', 'lisp']
assert conf.RulesNamesList(['bash', 'lisp']) == conf.RulesNamesList(['bash', 'lisp'])
assert Rule('lisp', None, None, False) in conf.RulesNamesList(['lisp'])
assert Rule('bash', None, None, False) not in conf.RulesNamesList(['lisp'])
def test_default():
assert Rule('test', None, None, True) in conf.DEFAULT_RULES
assert Rule('test', None, None, False) not in conf.DEFAULT_RULES
@@ -66,10 +59,3 @@ def test_settings_from_env_with_DEFAULT():
patch('thefuck.conf.os.environ', new_callable=lambda: {'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'}):
settings = conf.get_settings(Mock())
assert settings.rules == conf.DEFAULT_RULES + ['bash', 'lisp']
def test_update_settings():
settings = conf.Settings({'key': 'val'})
new_settings = settings.update(key='new-val')
assert new_settings.key == 'new-val'
assert settings.key == 'val'
+17 -17
View File
@@ -1,7 +1,7 @@
from subprocess import PIPE
from pathlib import PosixPath, Path
from mock import patch, Mock
from thefuck import main, conf
from thefuck import main, conf, types
def test_load_rule():
@@ -13,7 +13,7 @@ def test_load_rule():
get_new_command=get_new_command,
enabled_by_default=True)) as load_source:
assert main.load_rule(Path('/rules/bash.py')) \
== main.Rule('bash', match, get_new_command, True)
== types.Rule('bash', match, get_new_command, True)
load_source.assert_called_once_with('bash', '/rules/bash.py')
@@ -26,15 +26,15 @@ def test_get_rules():
assert list(main.get_rules(
Path('~'),
Mock(rules=conf.DEFAULT_RULES))) \
== [main.Rule('bash', 'bash', 'bash', True),
main.Rule('lisp', 'lisp', 'lisp', True),
main.Rule('bash', 'bash', 'bash', True),
main.Rule('lisp', 'lisp', 'lisp', True)]
== [types.Rule('bash', 'bash', 'bash', True),
types.Rule('lisp', 'lisp', 'lisp', True),
types.Rule('bash', 'bash', 'bash', True),
types.Rule('lisp', 'lisp', 'lisp', True)]
assert list(main.get_rules(
Path('~'),
Mock(rules=conf.RulesNamesList(['bash'])))) \
== [main.Rule('bash', 'bash', 'bash', True),
main.Rule('bash', 'bash', 'bash', True)]
Mock(rules=types.RulesNamesList(['bash'])))) \
== [types.Rule('bash', 'bash', 'bash', True),
types.Rule('bash', 'bash', 'bash', True)]
def test_get_command():
@@ -47,7 +47,7 @@ def test_get_command():
Popen.return_value.stderr.read.return_value = b'stderr'
assert main.get_command(Mock(), ['thefuck', 'apt-get',
'search', 'vim']) \
== main.Command('apt-get search vim', 'stdout', 'stderr')
== types.Command('apt-get search vim', 'stdout', 'stderr')
Popen.assert_called_once_with('apt-get search vim',
shell=True,
stdout=PIPE,
@@ -57,12 +57,12 @@ def test_get_command():
def test_get_matched_rule(capsys):
rules = [main.Rule('', lambda x, _: x.script == 'cd ..', None, True),
main.Rule('', lambda *_: False, None, True),
main.Rule('rule', Mock(side_effect=OSError('Denied')), None, True)]
assert main.get_matched_rule(main.Command('ls', '', ''),
rules = [types.Rule('', lambda x, _: x.script == 'cd ..', None, True),
types.Rule('', lambda *_: False, None, True),
types.Rule('rule', Mock(side_effect=OSError('Denied')), None, True)]
assert main.get_matched_rule(types.Command('ls', '', ''),
rules, Mock(no_colors=True)) is None
assert main.get_matched_rule(main.Command('cd ..', '', ''),
assert main.get_matched_rule(types.Command('cd ..', '', ''),
rules, Mock(no_colors=True)) == rules[0]
assert capsys.readouterr()[1].split('\n')[0] \
== '[WARN] Rule rule:'
@@ -70,11 +70,11 @@ def test_get_matched_rule(capsys):
def test_run_rule(capsys):
with patch('thefuck.main.confirm', return_value=True):
main.run_rule(main.Rule('', None, lambda *_: 'new-command', True),
main.run_rule(types.Rule('', None, lambda *_: 'new-command', True),
None, None)
assert capsys.readouterr() == ('new-command\n', '')
with patch('thefuck.main.confirm', return_value=False):
main.run_rule(main.Rule('', None, lambda *_: 'new-command', True),
main.run_rule(types.Rule('', None, lambda *_: 'new-command', True),
None, None)
assert capsys.readouterr() == ('', '')
+15
View File
@@ -0,0 +1,15 @@
from thefuck.types import Rule, RulesNamesList, Settings
def test_rules_names_list():
assert RulesNamesList(['bash', 'lisp']) == ['bash', 'lisp']
assert RulesNamesList(['bash', 'lisp']) == RulesNamesList(['bash', 'lisp'])
assert Rule('lisp', None, None, False) in RulesNamesList(['lisp'])
assert Rule('bash', None, None, False) not in RulesNamesList(['lisp'])
def test_update_settings():
settings = Settings({'key': 'val'})
new_settings = settings.update(key='new-val')
assert new_settings.key == 'new-val'
assert settings.key == 'val'
+2 -3
View File
@@ -1,11 +1,10 @@
from mock import Mock
from thefuck.utils import sudo_support, wrap_settings
from thefuck.main import Command
from thefuck.conf import Settings
from thefuck.types import Command, Settings
def test_wrap_settings():
fn = lambda _, settings: settings._conf
fn = lambda _, settings: settings
assert wrap_settings({'key': 'val'})(fn)(None, Settings({})) \
== {'key': 'val'}
assert wrap_settings({'key': 'new-val'})(fn)(