Add test-only Jenkins pipeline and document regression tests

This commit is contained in:
Dandaedre 2026-10-20 10:10:39 +02:00
parent c85fa86072
commit 537339684b
5 changed files with 292 additions and 1 deletions

View File

@ -15,6 +15,10 @@ in `README.md`.
locally installed AppImages. PDF-to-PDF is a successful no-op.
- `test_exporter.py` covers exporter validation, no-op behavior, conversion
failures, and overwrite behavior.
- `test_pptx_videos.py` covers slide discovery, extraction, temporary probing,
report formatting, and error handling.
- `Jenkinsfile` runs the Python unit tests on `rust_no_docker`. CI is test-only:
no publishing, badges, or archived artifacts.
## Working conventions
@ -28,7 +32,8 @@ in `README.md`.
in visual reports.
- Update `README.md` when command-line options or workflows change.
- Run checks appropriate to the change before committing. Exporter regression
tests run with `python -m unittest test_exporter -v`. For rendering changes,
tests and video-report tests run with
`python3 -m unittest -v test_exporter test_pptx_videos`. For rendering changes,
test with the actual external tools when available and inspect visual output.
Report any checks that could not be completed.

58
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,58 @@
pipeline {
agent { label 'rust_no_docker' }
options {
skipDefaultCheckout(true)
timeout(time: 10, unit: 'MINUTES')
}
environment {
PYTHONUNBUFFERED = '1'
PYTHONDONTWRITEBYTECODE = '1'
NO_COLOR = '1'
}
stages {
stage('Checkout') {
steps {
deleteDir()
checkout scm
}
}
stage('Check Python') {
steps {
sh '''
set -eu
if ! command -v python3 >/dev/null 2>&1; then
echo "ERROR: python3 is required on this Jenkins worker." >&2
exit 1
fi
python3 --version
python3 -c 'import sys; sys.exit("Python 3.9 or newer is required." if sys.version_info < (3, 9) else 0)'
'''
}
}
stage('Tests') {
steps {
sh '''
set -eu
python3 -m unittest -v test_exporter test_pptx_videos
'''
}
}
}
post {
success {
echo 'All Python unit tests passed. No artifacts were published.'
}
failure {
echo 'Checkout, Python setup, or tests failed. See the build log.'
}
unstable {
echo 'The build is unstable. See the build log.'
}
}
}

View File

@ -48,3 +48,32 @@ inside `images/`. Images default to 144 DPI. Existing output requires
`--overwrite`, which replaces generated files and removes stale numbered
slide/page PNGs. PDF-to-PDF is a successful no-op; other input extensions are
errors. Rendering completes in temporary storage before output is copied.
## Tests and Jenkins
Run the same suite locally and in Jenkins:
```sh
python3 -m unittest -v test_exporter test_pptx_videos
```
The declarative `Jenkinsfile` uses the `rust_no_docker` worker label and requires
Git and Python 3.9 or newer. It performs a clean SCM checkout, checks Python,
and runs the standard-library unit tests. No packages are installed.
Tests cover export validation, overwrite handling, failed conversions, PPTX
discovery and slide order, temporary video cleanup, report formats, and PDF
compiler invocation. External CLI calls are mocked: CI does not require FFmpeg,
Typst, DeckCraft, or PdfCraft and does not claim to verify rendering fidelity.
This is a test-only pipeline on every configured branch: no build artifacts,
archives, publication, badges, or Checks API calls. Status is reported in Jenkins.
There are no pipeline credential bindings; SCM access uses the Jenkins job's
configured repository credentials.
Configure a Pipeline from SCM or multibranch job for this repository with
`Jenkinsfile` as the script path (`main` is the default branch). For a Gitea-aware
multibranch job, use the installation's Jenkins base URL plus
`/gitea-webhook/post` as the Gitea webhook target and enable push events.
The Jenkins administrator must supply the actual reachable URL and SCM
credentials. This repository does not create the job or register the webhook.

View File

@ -46,6 +46,44 @@ class ExporterTests(unittest.TestCase):
self.assertEqual(self.invoke(source, '--output', 'pdf,images', '-d', destination), 1)
self.assertFalse(destination.exists())
def test_pdf_render_uses_one_based_pages_and_requested_dpi(self):
source = self.root / 'input.pdf'
source.touch()
destination = self.root / 'output'
commands = []
def fake_run(command, **kwargs):
commands.append(command)
if command[1] == 'info':
return '{"pages": 2}'
Path(command[-1]).write_bytes(b'image')
return ''
with patch.object(exporter, 'find_cli', return_value=Path('/fake/cli')), patch.object(exporter, 'run', side_effect=fake_run):
self.assertEqual(self.invoke(source, '--output', 'pdf,images', '--dpi', 192, '-d', destination), 0)
self.assertEqual([command[4] for command in commands[1:]], ['1', '2'])
self.assertTrue(all(command[6] == '192' for command in commands[1:]))
self.assertEqual(sorted(path.name for path in (destination / 'images').iterdir()),
['page-0001.png', 'page-0002.png'])
self.assertFalse((destination / 'input.pdf').exists())
def test_invalid_page_count_does_not_publish(self):
source = self.root / 'input.pdf'
source.touch()
for pages in ('0', '-1', 'null', '"2"', 'true'):
with self.subTest(pages=pages), \
patch.object(exporter, 'find_cli', return_value=Path('/fake/cli')), \
patch.object(exporter, 'run', return_value='{"pages": ' + pages + '}'):
self.assertEqual(self.invoke(source, '--output', 'images'), 1)
self.assertFalse((self.root / 'input_export').exists())
def test_missing_cli_does_not_create_output(self):
source = self.root / 'input.pptx'
source.touch()
with patch.object(exporter, 'find_cli', side_effect=RuntimeError('CLI missing')):
self.assertEqual(self.invoke(source, '--output', 'pdf'), 1)
self.assertFalse((self.root / 'input_export').exists())
def test_overwrite_removes_stale_pages_but_preserves_other_files(self):
source = self.root / 'input.pdf'
source.touch()

161
test_pptx_videos.py Normal file
View File

@ -0,0 +1,161 @@
from collections import defaultdict
import contextlib
import io
import json
from pathlib import Path
import subprocess
import tempfile
import unittest
from unittest.mock import patch
import zipfile
import pptx_videos as videos
class VideoTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
def invoke(self, source, *args):
with patch('sys.argv', ['pptx_videos.py', str(source), *args]), \
contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
return videos.main()
def deck(self, name='sample.pptx', media=True):
path = self.root / name
with zipfile.ZipFile(path, 'w') as archive:
if media:
archive.writestr('ppt/media/clip.mp4', b'video fixture')
return path
def test_discovery_uses_presentation_order_and_relationships(self):
source = self.root / 'ordered.pptx'
with zipfile.ZipFile(source, 'w') as archive:
archive.writestr('ppt/presentation.xml', f'''
<p:presentation xmlns:p="{videos.P_NS}" xmlns:r="{videos.R_NS}">
<p:sldIdLst><p:sldId r:id="second"/><p:sldId r:id="first"/></p:sldIdLst>
</p:presentation>''')
archive.writestr('ppt/_rels/presentation.xml.rels', f'''
<Relationships xmlns="{videos.REL_NS}">
<Relationship Id="first" Target="slides/slide1.xml"/>
<Relationship Id="second" Target="slides/slide2.xml"/>
</Relationships>''')
for number in (1, 2):
archive.writestr(f'ppt/slides/slide{number}.xml', f'''
<p:sld xmlns:p="{videos.P_NS}" xmlns:r="{videos.R_NS}">
<videoFile r:link="video"/><videoFile r:link="remote"/>
</p:sld>''')
archive.writestr(f'ppt/slides/_rels/slide{number}.xml.rels', f'''
<Relationships xmlns="{videos.REL_NS}">
<Relationship Id="video" Target="../media/clip{number}.mp4" Type="example/video"/>
<Relationship Id="remote" Target="https://example.invalid/video" TargetMode="External" Type="example/video"/>
</Relationships>''')
archive.writestr(f'ppt/media/clip{number}.mp4', b'video')
archive.writestr('ppt/media/audio.mp3', b'audio')
with zipfile.ZipFile(source) as archive:
parts, uses, external = videos.discover(archive)
self.assertEqual(parts, ['ppt/media/clip1.mp4', 'ppt/media/clip2.mp4'])
self.assertEqual(uses['ppt/media/clip2.mp4'], {1})
self.assertEqual(uses['ppt/media/clip1.mp4'], {2})
self.assertEqual(external, {1, 2})
def test_empty_deck_creates_no_output_and_requires_no_tools(self):
source = self.deck(media=False)
with patch.object(videos.shutil, 'which', side_effect=AssertionError('No tools needed')):
self.assertEqual(self.invoke(source, '--timings-only', '--report', 'pdf'), 0)
self.assertFalse((self.root / 'sample_videos').exists())
def test_timings_only_probes_temporary_copy_then_removes_it(self):
source = self.deck()
probed = []
def probe(path):
self.assertEqual(path.read_bytes(), b'video fixture')
probed.append(path)
return 1.25, '1920×1080', 'h264'
with patch.object(videos.shutil, 'which', return_value='/ffprobe'), patch.object(videos, 'probe', side_effect=probe):
self.assertEqual(self.invoke(source, '--timings-only', '--report', 'json,md'), 0)
output = self.root / 'sample_videos'
self.assertFalse((output / 'clip.mp4').exists())
self.assertEqual(len(probed), 1)
self.assertFalse(probed[0].exists())
data = json.loads((output / 'timings.json').read_text())
self.assertEqual(data['videos'][0]['duration_seconds'], 1.25)
self.assertIsNone(data['videos'][0]['extracted_file'])
self.assertNotIn('[clip.mp4]', (output / 'timings.md').read_text())
def test_extract_only_does_not_probe_or_write_reports(self):
source = self.deck()
with patch.object(videos, 'probe', side_effect=AssertionError('No probing')):
self.assertEqual(self.invoke(source, '--extract-only'), 0)
output = self.root / 'sample_videos'
self.assertEqual([p.name for p in output.iterdir()], ['clip.mp4'])
self.assertEqual((output / 'clip.mp4').read_bytes(), b'video fixture')
def report(self):
rows = [
('a', 'clip.mp4', 1024, 2.5, '1920×1080', 'h264'),
('b', 'A <clip> #1.mp4', 512, 1.0, '32×24', 'mpeg4'),
('c', 'unused.mp4', 128, None, 'Unknown', 'Unknown'),
]
return videos.report_data(Path('Review & plans.pptx'), rows,
defaultdict(set, a={10}, b={2, 12}), {5}, self.root)
def test_reports_sort_numerically_and_preserve_unknown_duration(self):
data = self.report()
self.assertEqual([v['slides'] for v in data['videos']], [[2, 12], [10], []])
self.assertEqual(data['total_duration_seconds'], 3.5)
self.assertEqual(data['known_durations'], 2)
decoded = json.loads(videos.render_report(data, 'json'))
self.assertIsNone(decoded['videos'][-1]['duration_seconds'])
self.assertEqual(decoded['external_media_slides'], [5])
def test_text_tables_align_and_put_duration_second(self):
for format in ('md', 'txt'):
with self.subTest(format=format):
lines = [line for line in videos.render_report(self.report(), format).splitlines() if line.startswith('|')]
self.assertEqual(lines[0].split('|')[2].strip(), 'Duration')
columns = {tuple(i for i, char in enumerate(line) if char == '|') for line in lines}
self.assertEqual(len(columns), 1)
self.assertIn('Unreferenced', lines[-1])
def test_visual_reports_escape_document_data(self):
data = self.report()
rendered = videos.render_report(data, 'html')
self.assertIn('Review &amp; plans.pptx', rendered)
self.assertIn('A &lt;clip&gt; #1.mp4', rendered)
self.assertNotIn('<clip>', rendered)
data['presentation'] = 'Quotes " and #panic("oops").pptx'
rendered = videos.render_report(data, 'typst')
self.assertIn(videos.typst_string(data['presentation']), rendered)
self.assertEqual(videos.typst_string('a\\b"\n'), '"a\\\\b\\"\\u{a}"')
def test_pdf_generation_keeps_source_and_invokes_typst(self):
def compile_pdf(command, **kwargs):
self.assertEqual(command[:2], ['typst', 'compile'])
self.assertTrue(Path(command[2]).is_file())
Path(command[3]).write_bytes(b'%PDF-test')
with patch.object(videos.subprocess, 'run', side_effect=compile_pdf) as run, contextlib.redirect_stdout(io.StringIO()):
videos.write_reports(self.report(), ['pdf'], self.root)
run.assert_called_once()
self.assertTrue((self.root / 'timings.typ').is_file())
self.assertEqual((self.root / 'timings.pdf').read_bytes(), b'%PDF-test')
def test_failed_probe_returns_unknown_metadata(self):
failure = subprocess.CalledProcessError(1, ['ffprobe'])
with patch.object(videos.subprocess, 'run', side_effect=failure):
self.assertEqual(videos.probe(self.root / 'bad.mp4'), (None, 'Unknown', 'Unknown'))
def test_invalid_archive_fails_without_output(self):
source = self.root / 'bad.pptx'
source.write_bytes(b'not a zip')
self.assertEqual(self.invoke(source, '--timings-only'), 1)
self.assertFalse((self.root / 'bad_videos').exists())
if __name__ == '__main__':
unittest.main()