import subprocess import sys import tempfile import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] CLI = ROOT / 'changelog.py' class IntegrationTests(unittest.TestCase): def git(self, repo, *args): return subprocess.run(['git', '-C', str(repo), *args], check=True, text=True, capture_output=True) def test_revision_range_to_output_file(self): with tempfile.TemporaryDirectory() as tmp: repo = Path(tmp) self.git(repo, 'init', '-q') self.git(repo, 'config', 'user.name', 'Fixture User') self.git(repo, 'config', 'user.email', 'fixture@example.invalid') (repo / 'file.txt').write_text('one\n', encoding='utf-8') self.git(repo, 'add', 'file.txt') self.git(repo, 'commit', '-q', '-m', 'chore: initial fixture') self.git(repo, 'tag', 'v1.0.0') (repo / 'file.txt').write_text('one\ntwo\n', encoding='utf-8') self.git(repo, 'commit', '-qam', 'feat(api): add export') (repo / 'file.txt').write_text('one\ntwo\nthree\n', encoding='utf-8') self.git(repo, 'commit', '-qam', 'fix!: reject malformed rows') output = repo / 'CHANGELOG.draft.md' subprocess.run([sys.executable, str(CLI), '--repo', str(repo), '--since', 'v1.0.0', '--title', '1.1.0', '--output', str(output)], check=True) text = output.read_text(encoding='utf-8') self.assertIn('## [1.1.0]', text) self.assertIn('### Added\n\n- **api:** add export', text) self.assertIn('### Fixed\n\n- **BREAKING:** reject malformed rows', text) self.assertNotIn('initial fixture', text) if __name__ == '__main__': unittest.main()