From a12be862e22bdec6a243a3f0b5f4f28d69084a2a Mon Sep 17 00:00:00 2001 From: Brianna Rainey Date: Thu, 22 Jan 2026 16:29:46 -0500 Subject: fix #89 with Image component v2.0 + 23 tests (#90) * qtbot is needed in any test that uses a QObject previously these tests would fail if they ran before qtbot was initialized by another test. I'm now running tests in a random order * add tests for drawBars, readAudioFile, BlankFrame * replace numpy.seterr with numpy.errstate * fix incorrect comment * add MockVideoWorker and imageDataSum * test further into visualization (less likely to be a false positive) * test FloodFrame function * add failing test for Image component one step towards fixing #89 * test component name CLI parsing * prevent log warning when 1 setting changed * correct tests to use widgets when needed * test undo and blockSignals * remove stretch_scale (use scale only) * image ignores scale if stretch checkbox checked fixes #89 * test Title Text component, ffmpeg command * Image v2: replace stretched setting with resizeMode 3 resize modes are scale, cover, and stretch. Scale only applies when resizeMode is set to scale. Cover uses ImageOps.fit() to stretch while maintaining aspect ratio. Also, spinBox_scale was moved to be underneath comboBox_resizeMode. * change transformData into staticmethod the purpose is to allow easier reuse in other components * add respondToAudio option to Image component this causes the image to scale up and down slightly based on the input audio file * cache static portion of image when animating increases rendering speed of a 1-minute video by 12 seconds (based on two manual tests anyway)--- tests/test_image_comp.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/test_image_comp.py (limited to 'tests/test_image_comp.py') diff --git a/tests/test_image_comp.py b/tests/test_image_comp.py new file mode 100644 index 0000000..a4f05e1 --- /dev/null +++ b/tests/test_image_comp.py @@ -0,0 +1,50 @@ +from avp.command import Command +from pytestqt import qtbot +from pytest import fixture +from . import audioData, MockSignal, imageDataSum, getTestDataPath + + +sampleSize = 1470 # 44100 / 30 = 1470 + + +@fixture +def coreWithImageComp(qtbot): + """Fixture providing a Command object with Image component added""" + command = Command() + command.settings.setValue("outputHeight", 1080) + command.settings.setValue("outputWidth", 1920) + command.core.insertComponent(0, command.core.moduleIndexFor("Image"), command) + yield command.core + + +def test_comp_image_set_path(coreWithImageComp): + "Set imagePath of Image component" + comp = coreWithImageComp.selectedComponents[0] + comp.imagePath = getTestDataPath("test.jpg") + image = comp.previewRender() + assert imageDataSum(image) == 463711601 + + +def test_comp_image_scale_50_1080p(coreWithImageComp): + """Image component stretches image to 50% at 1080p""" + comp = coreWithImageComp.selectedComponents[0] + comp.imagePath = getTestDataPath("test.jpg") + image = comp.previewRender() + sum = imageDataSum(image) + comp.page.spinBox_scale.setValue(50) + assert imageDataSum(comp.previewRender()) - sum / 4 < 2000 + + +def test_comp_image_scale_50_720p(coreWithImageComp): + """Image component stretches image to 50% at 720p""" + comp = coreWithImageComp.selectedComponents[0] + comp.imagePath = getTestDataPath("test.jpg") + comp.page.spinBox_scale.setValue(50) + image = comp.previewRender() + sum = imageDataSum(image) + comp.parent.settings.setValue("outputHeight", 720) + comp.parent.settings.setValue("outputWidth", 1280) + newImage = comp.previewRender() + assert image.width == 1920 + assert newImage.width == 1280 + assert imageDataSum(comp.previewRender()) == sum -- cgit v1.2.3