Back to Repositories

Black Python Formatter Testing: Unit Tests with Pytest and Unittest

The Black code formatter's test suite demonstrates a comprehensive approach to Python testing, utilizing both unittest and pytest frameworks for thorough unit testing. The test suite covers critical functionality including schema validation, documentation synchronization, HTTP server capabilities, and specialized features like Jupyter notebook formatting. The tests effectively validate Black's core formatting logic while maintaining high code quality standards. Qodo Tests Hub provides developers with valuable insights into Black's testing patterns by offering detailed analysis of its test implementations. Through the platform, developers can explore how Black structures its tests, handles different Python code formatting scenarios, and implements best practices for testing complex formatting logic. This real-world example serves as an excellent reference for understanding effective Python testing approaches and implementing similar testing strategies in other projects.

Path Test Type Language Description
tests/test_black.py
unit
python This pytest/unittest test suite verifies Black’s core formatting functionality, configuration handling, and file processing capabilities
tests/test_blackd.py
unit
python This pytest unit test suite verifies the HTTP server functionality and code formatting capabilities of the Black code formatter’s daemon service.
tests/test_format.py
unit
python This pytest unit test verifies Black’s Python code formatting functionality across different scenarios and Python versions.
tests/test_ipynb.py
unit
python This pytest unit test verifies Jupyter notebook formatting functionality in Black’s code formatter, including magic command handling and cell formatting.
tests/test_ranges.py
unit
python This pytest unit test verifies the line range adjustment and sanitization functionality in Black’s ranges module.
tests/test_schema.py
unit
python This Python unit test verifies Black’s pyproject.toml schema configuration and entry point registration functionality.
tests/test_trans.py
unit
python This Python unit test verifies f-string expression span parsing functionality in the Black code formatter
tests/test_no_ipynb.py
unit
python This pytest unit test verifies Black’s handling of Jupyter notebook files when required dependencies are not installed.
tests/test_docs.py
unit
python This pytest unit test verifies the synchronization between Black’s code features and their documentation in the future style guide.
tests/test_tokenize.py
unit
python This Python unit test verifies the blib2to3 tokenizer’s ability to correctly parse and generate tokens from Python source code.