"""Test detect_max_volume.""" import ffmpeg import pytest from video.connectors import s3 as s3_connector from video.constants import job_io_fields from video.logic.activities import detect_max_volume @pytest.mark.parametrize(( 'test_description', 'test_stderr', 'expected_max_volume' ), [ ( 'max_volume found', b""" aergerg [Parsed_volumedetect_0 @ 0x7f9e99692ec0] n_samples: 52609024 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] mean_volume: -32.9 dB [Parsed_volumedetect_0 @ 0x7f9e99692ec0] max_volume: -4.0 dB [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_3db: 1 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_4db: 76 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_5db: 536 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_6db: 368 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_7db: 318 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_8db: 437 regr3wgf3we4 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_9db: 974 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_10db: 1386 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_11db: 2718 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_12db: 5222 asefgawegera [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_13db: 9880 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_14db: 16270 [Parsed_volumedetect_0 @ 0x7f9e99692ec0] histogram_15db: 28315 awfgegr wegwefrfw """, # noqa -4, ), ( 'max_volume not found', b""" applesauce bananas """, None, ), ]) def test_detect_max_volume( mocker, test_description, test_stderr, expected_max_volume ): """Test detect_max_volume.""" mocker.patch.object( s3_connector, 'get_url_for_s3_object', return_value='test_url', autospec=True, ) mocker.patch.object( ffmpeg, 'input', autospec=True, ) input_mock = ffmpeg.input filter_mock = input_mock.return_value.filter output_mock = filter_mock.return_value.output run_mock = output_mock.return_value.run run_mock.return_value = 'test stdout'.encode(), test_stderr inputs = { job_io_fields.DETECT_MAX_VOLUME_JOB_ID: 123, job_io_fields.INPUT_VIDEO_S3_BUCKET: 'test_bucket', job_io_fields.INPUT_VIDEO_S3_KEY: 'test_key/123.mov', } expected_outputs = { job_io_fields.MAX_VOLUME_DECIBELS: expected_max_volume, } outputs = detect_max_volume.detect_max_volume(inputs) assert expected_outputs == outputs input_mock.assert_called_once_with('test_url') filter_mock.assert_called_once_with('volumedetect') output_mock.assert_called_once_with( 'pipe:', format='null', **{'vn': None}, ) run_mock.assert_called_once_with( capture_stderr=True, )