1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-10-12 14:54:02 +01:00

#N/A: Improve how version is fetched for all shells (#920)

This commit is contained in:
Pablo Aguiar
2019-05-27 18:24:55 +02:00
committed by Vladimir Iakovlev
parent ba949f7fd9
commit ff2944086d
12 changed files with 137 additions and 23 deletions

View File

@@ -10,6 +10,11 @@ class TestPowershell(object):
def shell(self):
return Powershell()
@pytest.fixture(autouse=True)
def Popen(self, mocker):
mock = mocker.patch('thefuck.shells.powershell.Popen')
return mock
def test_and_(self, shell):
assert shell.and_('ls', 'cd') == '(ls) -and (cd)'
@@ -20,3 +25,20 @@ class TestPowershell(object):
def test_how_to_configure(self, shell):
assert not shell.how_to_configure().can_configure_automatically
@pytest.mark.parametrize('side_effect, expected_version, call_args', [
([b'''Major Minor Build Revision
----- ----- ----- --------
5 1 17763 316 \n'''], 'PowerShell 5.1.17763.316', ['powershell.exe']),
([IOError, b'PowerShell 6.1.2\n'], 'PowerShell 6.1.2', ['powershell.exe', 'pwsh'])])
def test_info(self, side_effect, expected_version, call_args, shell, Popen):
Popen.return_value.stdout.read.side_effect = side_effect
assert shell.info() == expected_version
assert Popen.call_count == len(call_args)
assert all([Popen.call_args_list[i][0][0][0] == call_arg for i, call_arg in enumerate(call_args)])
def test_get_version_error(self, shell, Popen):
Popen.return_value.stdout.read.side_effect = RuntimeError
with pytest.raises(RuntimeError):
shell._get_version()
assert Popen.call_args[0][0] == ['powershell.exe', '$PSVersionTable.PSVersion']