Back to Repositories

Testing Git Help Alias Resolution in TheFuck

This test suite validates the git_help_aliased rule in TheFuck project, which handles Git help commands for aliased commands. It ensures proper resolution of Git aliases to their original commands when using the help function.

Test Coverage Overview

The test suite provides comprehensive coverage for Git help command alias resolution. It tests both matching and non-matching scenarios for aliased Git commands.

Key areas covered:
  • Alias to command mapping validation
  • Non-aliased command handling
  • Command transformation verification

Implementation Analysis

The implementation uses pytest’s parametrize decorator to efficiently test multiple scenarios with minimal code duplication. The testing approach focuses on the match() and get_new_command() functions, validating both positive and negative cases for Git command alias resolution.

Technical patterns include:
  • Parameterized test cases
  • Command object handling
  • Boolean assertion validation

Technical Details

Testing tools and configuration:
  • pytest framework for test organization
  • Command class from thefuck.types
  • Parametrized test fixtures
  • Direct function testing without mocking

Best Practices Demonstrated

The test suite exemplifies several testing best practices in Python. It demonstrates clear separation of test cases, efficient use of pytest features, and comprehensive coverage of functionality.

Notable practices:
  • Separate test functions for matching and non-matching cases
  • Parameterized test data
  • Clear test case organization
  • Explicit assertion statements

nvbn/thefuck

tests/rules/test_git_help_aliased.py

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


@pytest.mark.parametrize('script, output', [
    ('git help st', "`git st' is aliased to `status'"),
    ('git help ds', "`git ds' is aliased to `diff --staged'")])
def test_match(script, output):
    assert match(Command(script, output))


@pytest.mark.parametrize('script, output', [
    ('git help status', "GIT-STATUS(1)...Git Manual...GIT-STATUS(1)"),
    ('git help diff', "GIT-DIFF(1)...Git Manual...GIT-DIFF(1)")])
def test_not_match(script, output):
    assert not match(Command(script, output))


@pytest.mark.parametrize('script, output, new_command', [
    ('git help st', "`git st' is aliased to `status'", 'git help status'),
    ('git help ds', "`git ds' is aliased to `diff --staged'", 'git help diff')])
def test_get_new_command(script, output, new_command):
    assert get_new_command(Command(script, output)) == new_command