Back to Repositories

Testing Heroku Command Correction Implementation in thefuck

This test suite validates the Heroku command correction functionality in thefuck, specifically testing the behavior when users enter invalid Heroku CLI commands. It ensures the application correctly identifies and suggests proper command alternatives.

Test Coverage Overview

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

  • Tests command matching for invalid Heroku commands
  • Verifies correct suggestion of alternative commands
  • Validates non-Heroku command scenarios
  • Covers error message parsing and command correction

Implementation Analysis

The testing approach utilizes pytest’s parametrize feature for efficient test case management. Tests are structured to validate both positive and negative scenarios for command matching and correction functionality.

  • Uses pytest.mark.parametrize for multiple test cases
  • Implements isolated test functions for match and get_new_command
  • Employs Command class for input handling

Technical Details

  • Framework: pytest
  • Test Type: Unit tests
  • Key Components: Command class, match function, get_new_command function
  • Test Data: Simulated Heroku CLI output and commands

Best Practices Demonstrated

The test implementation showcases several testing best practices for Python unit testing.

  • Clear test function naming conventions
  • Separation of concerns between matching and command generation
  • Effective use of parametrized testing
  • Comprehensive positive and negative test cases

nvbn/thefuck

tests/rules/test_heroku_not_command.py

            
# -*- coding: utf-8 -*-

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


suggest_output = '''
 ▸    log is not a heroku command.
 ▸    Perhaps you meant logs?
 ▸    Run heroku _ to run heroku logs.
 ▸    Run heroku help for a list of available commands.'''


@pytest.mark.parametrize('cmd', ['log'])
def test_match(cmd):
    assert match(
        Command('heroku {}'.format(cmd), suggest_output))


@pytest.mark.parametrize('script, output', [
    ('cat log', suggest_output)])
def test_not_match(script, output):
    assert not match(Command(script, output))


@pytest.mark.parametrize('cmd, result', [
    ('log', 'heroku logs')])
def test_get_new_command(cmd, result):
    command = Command('heroku {}'.format(cmd), suggest_output)
    assert get_new_command(command) == result