Back to Repositories

Testing Git Recursive Remove Command Handling in TheFuck

This test suite validates the git_rm_recursive rule functionality in TheFuck tool, focusing on handling recursive directory removal commands in Git. The tests ensure proper behavior when users attempt to remove directories without the required -r flag.

Test Coverage Overview

The test suite provides comprehensive coverage of the git_rm_recursive rule implementation.

Key areas tested include:
  • Command matching for invalid git rm operations
  • Verification of error message parsing
  • Command transformation logic
  • Multiple input variations with single and multiple targets

Implementation Analysis

The testing approach utilizes pytest’s parametrize feature for efficient test case management. The implementation follows fixture-based testing patterns with dedicated test functions for matching and command generation scenarios.

Technical implementation details:
  • Parametrized test cases for various input combinations
  • Fixture usage for consistent output generation
  • Separate test functions for positive and negative matches

Technical Details

Testing infrastructure includes:
  • Pytest framework for test execution
  • Command object usage from thefuck.types
  • Parametrized test decorators
  • Fixture-based test data setup
  • Boolean assertions for match validation
  • String comparison for command verification

Best Practices Demonstrated

The test suite exemplifies several testing best practices in Python unit testing.

Notable practices include:
  • Clear separation of test scenarios
  • Effective use of pytest fixtures
  • Comprehensive edge case coverage
  • DRY principle through parametrization
  • Isolated test functions for specific behaviors

nvbn/thefuck

tests/rules/test_git_rm_recursive.py

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


@pytest.fixture
def output(target):
    return "fatal: not removing '{}' recursively without -r".format(target)


@pytest.mark.parametrize('script, target', [
    ('git rm foo', 'foo'),
    ('git rm foo bar', 'foo bar')])
def test_match(output, script, target):
    assert match(Command(script, output))


@pytest.mark.parametrize('script', ['git rm foo', 'git rm foo bar'])
def test_not_match(script):
    assert not match(Command(script, ''))


@pytest.mark.parametrize('script, target, new_command', [
    ('git rm foo', 'foo', 'git rm -r foo'),
    ('git rm foo bar', 'foo bar', 'git rm -r foo bar')])
def test_get_new_command(output, script, target, new_command):
    assert get_new_command(Command(script, output)) == new_command