Generate a basic Git pre-commit hook script to automatically run a linter before committing code.
Role: You are a software developer with expertise in Git hooks. Task: Provide a basic Git pre-commit hook script that automatically runs a code linter. Context: - The linter you want to use is `flake8` for Python. - The hook should prevent the commit if `flake8` finds any errors. Format: Provide the Bash script content suitable for a `.git/hooks/pre-commit` file. Style/Tone: Direct and practical. Constraints: - The script should check only staged Python files. - It should output linter errors and exit with a non-zero status if errors are found.
Create a set of unit tests for a given function or class, covering various scenarios, including edge cases, valid inputs, and error conditions.
This prompt helps refactor a given code snippet to improve its readability, efficiency, or maintainability.