Back to Repositories

Testing ADB Command Correction Implementation in thefuck

This test suite validates the ADB unknown command correction functionality in thefuck, ensuring proper handling of common Android Debug Bridge command typos and misconfigurations.

Test Coverage Overview

The test suite provides comprehensive coverage for ADB command correction scenarios, including device targeting options and common command misspellings.

  • Tests various ADB command typos (lgcat, puhs)
  • Validates device-specific commands (-d, -e, -s flags)
  • Covers port configuration scenarios (-P flag)
  • Tests common ADB operations (push, pull, logcat, reboot)

Implementation Analysis

The implementation uses pytest’s parametrize feature to efficiently test multiple command variations and expected corrections.

  • Utilizes fixture for consistent output testing
  • Implements separate match and command correction tests
  • Uses Command type for structured input handling
  • Employs parametrized test cases for comprehensive coverage

Technical Details

  • Testing Framework: pytest
  • Custom Types: Command class from thefuck.types
  • Test Components: match and get_new_command functions
  • Fixture Usage: Simulated ADB version output
  • Pattern Matching: Command correction logic verification

Best Practices Demonstrated

The test suite exemplifies strong testing practices with clear separation of concerns and thorough edge case coverage.

  • Isolated test cases for matching and command correction
  • Comprehensive negative testing scenarios
  • Consistent test data structure
  • Efficient test case organization using parametrization
  • Clear test case naming and organization

nvbn/thefuck

tests/rules/test_adb_unknown_command.py

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


@pytest.fixture
def output():
    return '''Android Debug Bridge version 1.0.31

 -d                            - directs command to the only connected USB device
                                 returns an error if more than one USB device is present.
 -e                            - directs command to the only running emulator.
                                 returns an error if more than one emulator is running.
 -s <specific device>          - directs command to the device or emulator with the given
                                 serial number or qualifier. Overrides ANDROID_SERIAL
                                 environment variable.
'''


@pytest.mark.parametrize('script', [
    ('adb lgcat'),
    ('adb puhs')])
def test_match(output, script):
    assert match(Command(script, output))


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


@pytest.mark.parametrize('script, new_command', [
    ('adb puhs test.bin /sdcard/test.bin', 'adb push test.bin /sdcard/test.bin'),
    ('adb -s 1111 logcta', 'adb -s 1111 logcat'),
    ('adb -P 666 pulll /sdcard/test.bin', 'adb -P 666 pull /sdcard/test.bin'),
    ('adb -d logcatt', 'adb -d logcat'),
    ('adb -e reboott', 'adb -e reboot')])
def test_get_new_command(script, output, new_command):
    assert get_new_command(Command(script, output)) == new_command