1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-12-20 06:58:57 +00:00

[test] Add code coverage framework

Implement a comprehensive test coverage framework that integrates with pytest-cov
to generate code coverage reports for the yt-dlp codebase. Key components:

- Configuration file (.coveragerc) with appropriate include/exclude patterns
- Helper script (run_coverage.py) with parallel report generation
- GitHub Actions workflow for automatic coverage reporting on PRs and pushes
- Support for Hatch testing environment and CLI integration
- Testing documentation for running coverage reports
- Sample test for demonstrating coverage reporting
This commit is contained in:
Wilson Bilkovich
2025-03-09 01:45:57 -05:00
parent 05c8023a27
commit 1e7c02ca48
9 changed files with 311 additions and 1 deletions

View File

View File

@@ -0,0 +1,62 @@
import os
import sys
import unittest
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from devscripts import install_deps
class TestInstallDeps(unittest.TestCase):
@mock.patch('devscripts.install_deps.parse_toml')
@mock.patch('devscripts.install_deps.read_file')
@mock.patch('devscripts.install_deps.subprocess.call')
def test_print_option(self, mock_call, mock_read_file, mock_parse_toml):
# Mock the parse_toml function to return a project table with dependencies
mock_parse_toml.return_value = {
'project': {
'name': 'yt-dlp',
'dependencies': ['dep1', 'dep2'],
'optional-dependencies': {
'default': ['opt1', 'opt2'],
'test': ['test1', 'test2'],
'dev': ['dev1', 'dev2'],
},
},
}
# Mock sys.argv to simulate command line arguments
with mock.patch('sys.argv', ['install_deps.py', '--print']):
# Redirect stdout to capture the output
from io import StringIO
import sys
original_stdout = sys.stdout
try:
output = StringIO()
sys.stdout = output
# Execute the main function
install_deps.main()
# Get the captured output
printed_deps = output.getvalue().strip().split('\n')
# Check that default dependencies are included
# 2 from dependencies + default dependencies
self.assertEqual(len(printed_deps), 4)
self.assertIn('dep1', printed_deps)
self.assertIn('dep2', printed_deps)
self.assertIn('opt1', printed_deps)
self.assertIn('opt2', printed_deps)
finally:
sys.stdout = original_stdout
# Call was not made because we used --print
mock_call.assert_not_called()
if __name__ == '__main__':
unittest.main()