1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-11-11 04:16:07 +00:00

Compare commits

..

5 Commits
1.36 ... 1.37

Author SHA1 Message Date
nvbn
29e70e14a0 Bump to 1.37 2015-05-07 14:16:17 +02:00
nvbn
0cdd23edcf Use wheel 2015-05-07 14:16:07 +02:00
nvbn
36d80859a4 Add tox config 2015-05-07 13:51:27 +02:00
nvbn
2b12b4bfce Improve tests with mocker 2015-05-07 13:42:52 +02:00
nvbn
91c1fe414a Update thefuck-alias entry point 2015-05-07 13:32:23 +02:00
9 changed files with 42 additions and 50 deletions

View File

@@ -28,4 +28,4 @@ call('git commit -am "Bump to {}"'.format(version), shell=True)
call('git tag {}'.format(version), shell=True) call('git tag {}'.format(version), shell=True)
call('git push', shell=True) call('git push', shell=True)
call('git push --tags', shell=True) call('git push --tags', shell=True)
call('python setup.py sdist upload', shell=True) call('python setup.py sdist bdist_wheel upload', shell=True)

View File

@@ -1,2 +1,4 @@
pytest pytest
mock mock
pytest-mock
wheel

2
setup.cfg Normal file
View File

@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1

View File

@@ -1,7 +1,7 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
VERSION = '1.36' VERSION = '1.37'
setup(name='thefuck', setup(name='thefuck',
@@ -17,4 +17,5 @@ setup(name='thefuck',
zip_safe=False, zip_safe=False,
install_requires=['pathlib', 'psutil', 'colorama', 'six'], install_requires=['pathlib', 'psutil', 'colorama', 'six'],
entry_points={'console_scripts': [ entry_points={'console_scripts': [
'thefuck = thefuck.main:main', 'thefuck-alias = thefuck.main:alias']}) 'thefuck = thefuck.main:main',
'thefuck-alias = thefuck.shells:app_alias']})

View File

@@ -14,10 +14,8 @@ def test_default(enabled, rules, result):
@pytest.fixture @pytest.fixture
def load_source(monkeypatch): def load_source(mocker):
mock = Mock() return mocker.patch('thefuck.conf.load_source')
monkeypatch.setattr('thefuck.conf.load_source', mock)
return mock
@pytest.fixture @pytest.fixture

View File

@@ -6,15 +6,15 @@ from thefuck import main, conf, types
from tests.utils import Rule, Command from tests.utils import Rule, Command
def test_load_rule(monkeypatch): def test_load_rule(mocker):
match = object() match = object()
get_new_command = object() get_new_command = object()
load_source = Mock() load_source = mocker.patch(
load_source.return_value = Mock(match=match, 'thefuck.main.load_source',
return_value=Mock(match=match,
get_new_command=get_new_command, get_new_command=get_new_command,
enabled_by_default=True, enabled_by_default=True,
priority=900) priority=900))
monkeypatch.setattr('thefuck.main.load_source', load_source)
assert main.load_rule(Path('/rules/bash.py')) \ assert main.load_rule(Path('/rules/bash.py')) \
== Rule('bash', match, get_new_command, priority=900) == Rule('bash', match, get_new_command, priority=900)
load_source.assert_called_once_with('bash', '/rules/bash.py') load_source.assert_called_once_with('bash', '/rules/bash.py')
@@ -22,10 +22,8 @@ def test_load_rule(monkeypatch):
class TestGetRules(object): class TestGetRules(object):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def glob(self, monkeypatch): def glob(self, mocker):
mock = Mock(return_value=[]) return mocker.patch('thefuck.main.Path.glob', return_value=[])
monkeypatch.setattr('thefuck.main.Path.glob', mock)
return mock
def _compare_names(self, rules, names): def _compare_names(self, rules, names):
return [r.name for r in rules] == names return [r.name for r in rules] == names
@@ -118,10 +116,8 @@ class TestGetMatchedRule(object):
class TestRunRule(object): class TestRunRule(object):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def confirm(self, monkeypatch): def confirm(self, mocker):
mock = Mock(return_value=True) return mocker.patch('thefuck.main.confirm', return_value=True)
monkeypatch.setattr('thefuck.main.confirm', mock)
return mock
def test_run_rule(self, capsys): def test_run_rule(self, capsys):
main.run_rule(Rule(get_new_command=lambda *_: 'new-command'), main.run_rule(Rule(get_new_command=lambda *_: 'new-command'),
@@ -147,10 +143,8 @@ class TestRunRule(object):
class TestConfirm(object): class TestConfirm(object):
@pytest.fixture @pytest.fixture
def stdin(self, monkeypatch): def stdin(self, mocker):
mock = Mock(return_value='\n') return mocker.patch('sys.stdin.read', return_value='\n')
monkeypatch.setattr('sys.stdin.read', mock)
return mock
def test_when_not_required(self, capsys): def test_when_not_required(self, capsys):
assert main.confirm('command', None, Mock(require_confirmation=False)) assert main.confirm('command', None, Mock(require_confirmation=False))

View File

@@ -1,20 +1,15 @@
import pytest import pytest
from mock import Mock, MagicMock
from thefuck import shells from thefuck import shells
@pytest.fixture @pytest.fixture
def builtins_open(monkeypatch): def builtins_open(mocker):
mock = MagicMock() return mocker.patch('six.moves.builtins.open')
monkeypatch.setattr('six.moves.builtins.open', mock)
return mock
@pytest.fixture @pytest.fixture
def isfile(monkeypatch): def isfile(mocker):
mock = Mock(return_value=True) return mocker.patch('os.path.isfile', return_value=True)
monkeypatch.setattr('os.path.isfile', mock)
return mock
class TestGeneric(object): class TestGeneric(object):
@@ -32,9 +27,8 @@ class TestGeneric(object):
@pytest.mark.usefixtures('isfile') @pytest.mark.usefixtures('isfile')
class TestBash(object): class TestBash(object):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def Popen(self, monkeypatch): def Popen(self, mocker):
mock = Mock() mock = mocker.patch('thefuck.shells.Popen')
monkeypatch.setattr('thefuck.shells.Popen', mock)
mock.return_value.stdout.read.return_value = ( mock.return_value.stdout.read.return_value = (
b'alias l=\'ls -CF\'\n' b'alias l=\'ls -CF\'\n'
b'alias la=\'ls -A\'\n' b'alias la=\'ls -A\'\n'
@@ -59,9 +53,8 @@ class TestBash(object):
@pytest.mark.usefixtures('isfile') @pytest.mark.usefixtures('isfile')
class TestZsh(object): class TestZsh(object):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def Popen(self, monkeypatch): def Popen(self, mocker):
mock = Mock() mock = mocker.patch('thefuck.shells.Popen')
monkeypatch.setattr('thefuck.shells.Popen', mock)
mock.return_value.stdout.read.return_value = ( mock.return_value.stdout.read.return_value = (
b'l=\'ls -CF\'\n' b'l=\'ls -CF\'\n'
b'la=\'ls -A\'\n' b'la=\'ls -A\'\n'
@@ -77,9 +70,9 @@ class TestZsh(object):
def test_to_shell(self): def test_to_shell(self):
assert shells.Zsh().to_shell('pwd') == 'pwd' assert shells.Zsh().to_shell('pwd') == 'pwd'
def test_put_to_history(self, builtins_open, monkeypatch): def test_put_to_history(self, builtins_open, mocker):
monkeypatch.setattr('thefuck.shells.time', mocker.patch('thefuck.shells.time',
lambda: 1430707243.3517463) return_value=1430707243.3517463)
shells.Zsh().put_to_history('ls') shells.Zsh().put_to_history('ls')
builtins_open.return_value.__enter__.return_value. \ builtins_open.return_value.__enter__.return_value. \
write.assert_called_once_with(': 1430707243:0;ls\n') write.assert_called_once_with(': 1430707243:0;ls\n')

View File

@@ -121,10 +121,6 @@ def run_rule(rule, command, settings):
print(new_command) print(new_command)
def alias():
print(shells.app_alias())
def main(): def main():
colorama.init() colorama.init()
user_dir = setup_user_dir() user_dir = setup_user_dir()

6
tox.ini Normal file
View File

@@ -0,0 +1,6 @@
[tox]
envlist = py27,py33,py34
[testenv]
deps = -rrequirements.txt
commands = py.test