Back to Repositories

Testing Yarn Command Alias Detection and Correction in thefuck

This test suite verifies the yarn alias correction functionality in thefuck, focusing on command matching and substitution. It ensures the tool can properly identify and correct common yarn command aliases and typos.

Test Coverage Overview

The test suite provides comprehensive coverage of yarn command alias handling.

Key areas tested include:
  • Command alias matching (rm → remove)
  • Typo correction (etil → etl)
  • Alternative syntax handling (ls → list)
Integration points focus on the command parsing and suggestion generation pipeline.

Implementation Analysis

The testing approach utilizes pytest’s parametrize feature for efficient test case management.

Technical patterns include:
  • Parameterized test cases for both matching and command generation
  • Command object usage for input/output simulation
  • Separate validation of match detection and command correction

Technical Details

Testing infrastructure includes:
  • pytest framework for test execution
  • Command class from thefuck.types
  • Mock command outputs for different scenarios
  • Parametrized test decorators for multiple test cases

Best Practices Demonstrated

The test suite exemplifies solid testing practices through clear separation of concerns and thorough validation.

Notable practices include:
  • Isolated test cases for matching and command generation
  • Consistent test data structure
  • Comprehensive error message coverage
  • Efficient test case organization using parametrization

nvbn/thefuck

tests/rules/test_yarn_alias.py

            
import pytest
from thefuck.rules.yarn_alias import match, get_new_command
from thefuck.types import Command


output_remove = 'error Did you mean `yarn remove`?'
output_etl = 'error Command "etil" not found. Did you mean "etl"?'
output_list = 'error Did you mean `yarn list`?'


@pytest.mark.parametrize('command', [
    Command('yarn rm', output_remove),
    Command('yarn etil', output_etl),
    Command('yarn ls', output_list)])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize('command, new_command', [
    (Command('yarn rm', output_remove), 'yarn remove'),
    (Command('yarn etil', output_etl), 'yarn etl'),
    (Command('yarn ls', output_list), 'yarn list')])
def test_get_new_command(command, new_command):
    assert get_new_command(command) == new_command