Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/rules/test_pip_externally_managed_enviroment
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
from thefuck.rules.pip_externally_managed import match, get_new_command
from thefuck.types import Command

EXTERNALLY_MANAGED_ERROR = """
error: externally-managed-environment\r\n
--break-system-packages"""
"""

@pytest.mark.parametrize('command', [
Command('pip install requests', EXTERNALLY_MANAGED_ERROR),
Command('pip3 install requests', EXTERNALLY_MANAGED_ERROR),
Command('python -m pip install requests', EXTERNALLY_MANAGED_ERROR),
])
def test_match(command):
assert match(command) is True

@pytest.mark.parametrize('command', [
Command('pip install requests', ''),
Command('ls', EXTERNALLY_MANAGED_ERROR),
])
def test_not_match(command):
assert match(command) is False

def test_get_new_command():
cmd = Command('pip install requests', EXTERNALLY_MANAGED_ERROR)
assert get_new_command(cmd) == 'pip install requests --break-system-packages'
9 changes: 9 additions & 0 deletions thefuck/rules/pip_externally_managed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def match(command):
return (
('pip install' in command.script or
'pip3 install' in command.script) and
'externally-managed-environment' in command.output
)

def get_new_command(command):
return command.script + ' --break-system-packages'