Back to Repositories

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

The test suite provides comprehensive coverage of Tsuru command validation scenarios.

Key areas tested include:
  • Command pattern matching for invalid Tsuru commands
  • Suggestion generation for similar valid commands
  • Edge cases with no available suggestions
  • Various command formats including hyphenated commands

Implementation Analysis

The testing approach uses pytest’s parametrize decorator to efficiently test multiple input scenarios against expected outcomes.

Technical implementation features:
  • Parametrized test cases for both matching and non-matching scenarios
  • Command object usage for input standardization
  • Structured assertion testing for command suggestions

Technical Details

Testing infrastructure includes:
  • pytest framework for test organization
  • Command type from thefuck.types
  • match and get_new_command functions from tsuru_not_command module
  • Parametrized test fixtures for various command scenarios

Best Practices Demonstrated

The test suite exemplifies several testing best practices.

Notable elements include:
  • Clear separation of positive and negative test cases
  • Comprehensive edge case coverage
  • Consistent test structure and naming
  • Efficient test data organization using parametrization

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