Testing Tsuru Command Correction Implementation in thefuck
This test suite validates the Tsuru command correction functionality in the thefuck project, focusing on handling invalid Tsuru commands and suggesting appropriate alternatives. The tests verify the pattern matching and command suggestion logic for various Tsuru CLI scenarios.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
nvbn/thefuck
tests/rules/test_tsuru_not_command.py
import pytest
from thefuck.types import Command
from thefuck.rules.tsuru_not_command import match, get_new_command
@pytest.mark.parametrize('command', [
Command('tsuru log', (
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
'\tapp-log
'
'\tlogin
'
'\tlogout
'
)),
Command('tsuru app-l', (
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
'\tapp-list
'
'\tapp-log
'
)),
Command('tsuru user-list', (
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
'\tteam-user-list
'
)),
Command('tsuru targetlist', (
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
'\ttarget-list
'
)),
])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('tsuru tchururu', (
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
)),
Command('tsuru version', 'tsuru version 0.16.0.'),
Command('tsuru help', (
'tsuru version 0.16.0.
'
'
Usage: tsuru command [args]
'
)),
Command('tsuru platform-list', (
'- java
'
'- logstashgiro
'
'- newnode
'
'- nodejs
'
'- php
'
'- python
'
'- python3
'
'- ruby
'
'- ruby20
'
'- static
'
)),
Command('tsuru env-get', 'Error: App thefuck not found.'),
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_commands', [
(Command('tsuru log', (
'tsuru: "log" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
'\tapp-log
'
'\tlogin
'
'\tlogout
'
)), ['tsuru login', 'tsuru logout', 'tsuru app-log']),
(Command('tsuru app-l', (
'tsuru: "app-l" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
'\tapp-list
'
'\tapp-log
'
)), ['tsuru app-log', 'tsuru app-list']),
(Command('tsuru user-list', (
'tsuru: "user-list" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
'\tteam-user-list
'
)), ['tsuru team-user-list']),
(Command('tsuru targetlist', (
'tsuru: "targetlist" is not a tsuru command. See "tsuru help".
'
'
Did you mean?
'
'\ttarget-list
'
)), ['tsuru target-list']),
])
def test_get_new_command(command, new_commands):
assert get_new_command(command) == new_commands