Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
59dc6cb
commit 48e1e42
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from thefuck.rules.nixos_cmd_not_found import match, get_new_command | ||
from thefuck.types import Command | ||
|
||
|
||
@pytest.mark.parametrize('command', [ | ||
Command('vim', 'nix-env -iA nixos.vim')]) | ||
def test_match(mocker, command): | ||
mocker.patch('thefuck.rules.nixos_cmd_not_found', return_value=None) | ||
assert match(command) | ||
|
||
|
||
@pytest.mark.parametrize('command', [ | ||
Command('vim', ''), | ||
Command('', '')]) | ||
def test_not_match(mocker, command): | ||
mocker.patch('thefuck.rules.nixos_cmd_not_found', return_value=None) | ||
assert not match(command) | ||
|
||
|
||
@pytest.mark.parametrize('command, new_command', [ | ||
(Command('vim', 'nix-env -iA nixos.vim'), 'nix-env -iA nixos.vim && vim'), | ||
(Command('pacman', 'nix-env -iA nixos.pacman'), 'nix-env -iA nixos.pacman && pacman')]) | ||
def test_get_new_command(mocker, command, new_command): | ||
assert get_new_command(command) == new_command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import re | ||
from thefuck.specific.nix import nix_available | ||
from thefuck.shells import shell | ||
|
||
regex = re.compile(r'nix-env -iA ([^\s]*)') | ||
enabled_by_default = nix_available | ||
|
||
|
||
def match(command): | ||
return regex.findall(command.output) | ||
|
||
|
||
def get_new_command(command): | ||
name = regex.findall(command.output)[0] | ||
return shell.and_('nix-env -iA {}'.format(name), command.script) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from thefuck.utils import which | ||
|
||
nix_available = bool(which('nix')) |