Back to Repositories

Testing Trailing Cedilla Character Removal in TheFuck Command Handler

This test suite validates the functionality of the remove_trailing_cedilla rule in TheFuck project, which handles commands containing trailing cedilla characters. The tests ensure proper detection and removal of cedilla characters from command strings.

Test Coverage Overview

The test suite provides comprehensive coverage for cedilla character handling in commands.

Key areas tested include:
  • Command matching with trailing cedilla
  • Command transformation by removing cedilla
  • Single word and multi-word command handling
  • Edge cases with different command formats

Implementation Analysis

The testing approach uses pytest’s parametrize decorator to efficiently test multiple input scenarios with minimal code duplication.

Technical implementation features:
  • Parametrized test cases for both match and command transformation
  • Command object usage for input handling
  • Direct assertion validation for expected outcomes

Technical Details

Testing infrastructure includes:
  • Pytest framework for test execution
  • Custom Command type implementation
  • CEDILLA constant usage
  • Parametrized test fixtures
  • Direct import of rule functions (match, get_new_command)

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Separation of matching and transformation tests
  • Clear test case organization
  • Efficient use of parametrization
  • Focused test scope per function
  • Consistent assertion patterns

nvbn/thefuck

tests/rules/test_remove_trailing_cedilla.py

            
import pytest
from thefuck.rules.remove_trailing_cedilla import match, get_new_command, CEDILLA
from thefuck.types import Command


@pytest.mark.parametrize('command', [
    Command('wrong' + CEDILLA, ''),
    Command('wrong with args' + CEDILLA, '')])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize('command, new_command', [
    (Command('wrong' + CEDILLA, ''), 'wrong'),
    (Command('wrong with args' + CEDILLA, ''), 'wrong with args')])
def test_get_new_command(command, new_command):
    assert get_new_command(command) == new_command