Back to Repositories

Testing Git Branch Deletion Command Correction in thefuck

This test suite validates the git branch deletion functionality in the ‘thefuck’ command-line tool, specifically focusing on the handling of unmerged branch deletion scenarios. The tests ensure proper command correction behavior when users attempt to delete branches using the -d flag.

Test Coverage Overview

The test suite provides comprehensive coverage of git branch deletion command correction functionality.

Key areas tested include:
  • Branch deletion command matching
  • Unmerged branch deletion scenarios
  • Command transformation from -d to -D flag
  • Invalid command handling
The tests verify both positive and negative test cases for command matching and transformation.

Implementation Analysis

The implementation uses pytest’s fixture-based approach for test data management. The testing strategy focuses on two main components: the match function for identifying applicable scenarios and the get_new_command function for generating corrected commands.

The tests utilize pytest’s assertion framework and Command object pattern to validate behavior across different input scenarios.

Technical Details

Testing tools and configuration:
  • pytest as the primary testing framework
  • Custom Command class for input handling
  • Fixture-based test data setup
  • String output validation for command correction

Best Practices Demonstrated

The test suite demonstrates several testing best practices including isolated test cases, clear test naming, and comprehensive edge case coverage.

Notable practices include:
  • Separation of test data using fixtures
  • Explicit positive and negative test cases
  • Clean assertion patterns
  • Focused test functions with single responsibility

nvbn/thefuck

tests/rules/test_git_branch_delete.py

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


@pytest.fixture
def output():
    return '''error: The branch 'branch' is not fully merged.
If you are sure you want to delete it, run 'git branch -D branch'.

'''


def test_match(output):
    assert match(Command('git branch -d branch', output))
    assert not match(Command('git branch -d branch', ''))
    assert not match(Command('ls', output))


def test_get_new_command(output):
    assert get_new_command(Command('git branch -d branch', output))\
        == "git branch -D branch"