mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-19 00:58:56 +00:00
Merge ab1833b38840c334a645a922d64c86b82e6ee6fb into fe0785bc42ed31c83bbea02edf9a341094ddefcb
This commit is contained in:
commit
e84708afb2
@ -177,7 +177,7 @@ following rules are enabled by default:
|
|||||||
* `aws_cli` – fixes misspelled commands like `aws dynamdb scan`;
|
* `aws_cli` – fixes misspelled commands like `aws dynamdb scan`;
|
||||||
* `cargo` – runs `cargo build` instead of `cargo`;
|
* `cargo` – runs `cargo build` instead of `cargo`;
|
||||||
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
||||||
* `cat_dir` – replaces `cat` with `ls` when you try to `cat` a directory
|
* `cat_dir` – replaces `cat` with `ls` when you try to `cat` a directory;
|
||||||
* `cd_correction` – spellchecks and correct failed cd commands;
|
* `cd_correction` – spellchecks and correct failed cd commands;
|
||||||
* `cd_mkdir` – creates directories before cd'ing into them;
|
* `cd_mkdir` – creates directories before cd'ing into them;
|
||||||
* `cd_parent` – changes `cd..` to `cd ..`;
|
* `cd_parent` – changes `cd..` to `cd ..`;
|
||||||
|
@ -1,15 +1,67 @@
|
|||||||
|
import errno
|
||||||
|
import gettext
|
||||||
|
import os
|
||||||
|
import warnings
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from thefuck.rules.cat_dir import match, get_new_command
|
from thefuck.rules.cat_dir import match, get_new_command
|
||||||
from thefuck.types import Command
|
from thefuck.types import Command
|
||||||
|
|
||||||
|
# patch this so the libc locale is available in the testing virtualenv
|
||||||
|
gettext._default_localedir = '/usr/share/locale'
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', [
|
lang_vars = ['LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG']
|
||||||
Command('cat foo', 'cat: foo: Is a directory\n'),
|
|
||||||
Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'),
|
|
||||||
Command('cat cat/', 'cat: cat/: Is a directory\n'),
|
@pytest.fixture(params=['en_US.UTF-8', 'fr_FR.UTF-8', 'en_US.ISO8859-1', 'fr_FR.ISO8859-1'])
|
||||||
])
|
def language(request):
|
||||||
def test_match(command):
|
return request.param
|
||||||
assert match(command)
|
|
||||||
|
|
||||||
|
@pytest.fixture(params=[''] + lang_vars)
|
||||||
|
def environment(request, language):
|
||||||
|
orig_env = os.environ.copy()
|
||||||
|
|
||||||
|
# empty the locale environment variables
|
||||||
|
for lang_var in lang_vars:
|
||||||
|
os.environ.pop(lang_var, None)
|
||||||
|
|
||||||
|
if request.param:
|
||||||
|
os.environ[request.param] = language
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
os.environ = orig_env
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def eisdir(environment):
|
||||||
|
eisdir = gettext.translation('libc', fallback=True).gettext('Is a directory')
|
||||||
|
return eisdir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(params=['foo', '/foo/var', 'cat/'])
|
||||||
|
def cat_command(request, eisdir):
|
||||||
|
return (
|
||||||
|
Command('cat %s' % request.param, 'cat: %s: %s\n' % (request.param, eisdir)),
|
||||||
|
'ls %s' % request.param
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_localization_possible(language):
|
||||||
|
if not language.startswith('en_US'):
|
||||||
|
try:
|
||||||
|
gettext.translation('libc', languages=[language])
|
||||||
|
except EnvironmentError as e:
|
||||||
|
if e.errno == errno.ENOENT:
|
||||||
|
warnings.warn("No '%s' translation file found for language '%s'; the localization tests for `cat_dir` will be ineffective" % (e.filename, language))
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def test_match(cat_command):
|
||||||
|
assert match(cat_command[0])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('command', [
|
||||||
@ -20,10 +72,5 @@ def test_not_match(command):
|
|||||||
assert not match(command)
|
assert not match(command)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command, new_command', [
|
def test_get_new_command(cat_command):
|
||||||
(Command('cat foo', 'cat: foo: Is a directory\n'), 'ls foo'),
|
assert get_new_command(cat_command[0]) == cat_command[1]
|
||||||
(Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'), 'ls /foo/bar/'),
|
|
||||||
(Command('cat cat', 'cat: cat: Is a directory\n'), 'ls cat'),
|
|
||||||
])
|
|
||||||
def test_get_new_command(command, new_command):
|
|
||||||
assert get_new_command(command) == new_command
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
|
import gettext
|
||||||
|
|
||||||
|
|
||||||
def match(command):
|
def match(command):
|
||||||
|
eisdir = gettext.translation('libc', fallback=True).gettext('Is a directory')
|
||||||
return (
|
return (
|
||||||
command.script.startswith('cat') and
|
command.script.startswith('cat') and
|
||||||
command.output.startswith('cat: ') and
|
command.output.startswith('cat: ') and
|
||||||
command.output.rstrip().endswith(': Is a directory')
|
command.output.rstrip().endswith(': %s' % eisdir)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user