Skip to content

Commit 07ccf7c

Browse files
committed
[tests] Cleanup test imports and move deprecated import tests to test_api
1 parent 71c946a commit 07ccf7c

File tree

6 files changed

+37
-43
lines changed

6 files changed

+37
-43
lines changed

tests/test_api.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,28 @@ def on_new_scene(frame_img: numpy.ndarray, frame_num: int):
142142
scene_manager = SceneManager()
143143
scene_manager.add_detector(ContentDetector())
144144
scene_manager.detect_scenes(video=video, duration=total_frames, callback=on_new_scene)
145+
146+
147+
# TODO(v0.8): Remove this test when these deprecated modules are removed from the codebase.
148+
def test_deprecated_modules_emits_warning_on_import():
149+
import importlib
150+
151+
import pytest
152+
153+
SCENE_DETECTOR_WARNING = (
154+
"The `scene_detector` submodule is deprecated, import from the base package instead."
155+
)
156+
with pytest.warns(DeprecationWarning, match=SCENE_DETECTOR_WARNING):
157+
importlib.import_module("scenedetect.scene_detector")
158+
159+
FRAME_TIMECODE_WARNING = (
160+
"The `frame_timecode` submodule is deprecated, import from the base package instead."
161+
)
162+
with pytest.warns(DeprecationWarning, match=FRAME_TIMECODE_WARNING):
163+
importlib.import_module("scenedetect.frame_timecode")
164+
165+
VIDEO_SPLITTER_WARNING = (
166+
"The `video_splitter` submodule is deprecated, import from the base package instead."
167+
)
168+
with pytest.warns(DeprecationWarning, match=VIDEO_SPLITTER_WARNING):
169+
importlib.import_module("scenedetect.video_splitter")

tests/test_cli.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,35 @@
1212

1313
import os
1414
import subprocess
15-
import typing as ty
16-
from pathlib import Path
17-
18-
import cv2
19-
import numpy as np
20-
import pytest
21-
22-
import scenedetect
23-
from scenedetect.output import is_ffmpeg_available, is_mkvmerge_available
2415

2516
# These tests validate that the CLI itself functions correctly, mainly based on the return
2617
# return code from the process. We do not yet check for correctness of the output, just a
2718
# successful invocation of the command (i.e. no exceptions/errors).
28-
2919
# TODO: Add some basic correctness tests to validate the output (just look for the
3020
# last expected log message or extract # of scenes). Might need to refactor the test cases
3121
# since we need to calculate the output file names for commands that write to disk.
32-
3322
# TODO: Define error/exit codes explicitly. Right now these tests only verify that the
3423
# exit code is zero or nonzero.
35-
3624
# TODO: These tests are very expensive since they spin up new Python interpreters.
3725
# Move most of these test cases (e.g. argument validation) to ones that interface directly
3826
# with the scenedetect._cli module. Click also supports unit testing directly, so we should
3927
# probably use that instead of spinning up new subprocesses for each run of the controller.
4028
# That will also allow splitting up the validation of argument parsing logic from the controller
4129
# logic by creating a CLI context with the desired parameters.
42-
4330
# TODO: Missing tests for --min-scene-len and --drop-short-scenes.
31+
import sys
32+
import typing as ty
33+
from pathlib import Path
34+
35+
import cv2
36+
import numpy as np
37+
import pytest
38+
39+
import scenedetect
40+
from scenedetect.output import is_ffmpeg_available, is_mkvmerge_available
41+
42+
SCENEDETECT_CMD = sys.executable + " -m scenedetect"
4443

45-
SCENEDETECT_CMD = "python -m scenedetect"
4644
ALL_DETECTORS = [
4745
"detect-content",
4846
"detect-threshold",

tests/test_detectors.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,3 @@ def test_detectors_with_stats(test_video_file):
224224
scene_manager.detect_scenes(video=video, end_time=end_time)
225225
scene_list = scene_manager.get_scene_list()
226226
assert len(scene_list) == initial_scene_len
227-
228-
229-
# TODO(v0.8): Remove this test during the removal of `scenedetect.scene_detector`.
230-
def test_deprecated_detector_module_emits_warning_on_import():
231-
SCENE_DETECTOR_WARNING = (
232-
"The `scene_detector` submodule is deprecated, import from the base package instead."
233-
)
234-
with pytest.warns(DeprecationWarning, match=SCENE_DETECTOR_WARNING):
235-
from scenedetect.scene_detector import SceneDetector as _

tests/test_output.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,3 @@ def test_save_images_zero_width_scene(test_video_file, tmp_path: Path):
191191
total_images += 1
192192

193193
assert total_images == len([path for path in tmp_path.glob(image_name_glob)])
194-
195-
196-
# TODO(v0.8): Remove this test during the removal of `scenedetect.video_splitter`.
197-
def test_deprecated_output_modules_emits_warning_on_import():
198-
VIDEO_SPLITTER_WARNING = (
199-
"The `video_splitter` submodule is deprecated, import from the base package instead."
200-
)
201-
with pytest.warns(DeprecationWarning, match=VIDEO_SPLITTER_WARNING):
202-
from scenedetect.video_splitter import split_video_ffmpeg as _

tests/test_stats_manager.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
"""
2828

2929
import csv
30-
import os
31-
import random
3230
from pathlib import Path
3331

3432
import pytest

tests/test_timecode.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,3 @@ def test_timecode_frame_num_for_vfr():
339339
tc = FrameTimecode(timecode=Timecode(pts=1001, time_base=Fraction(1, 24000)), fps=fps)
340340
# Should not raise or warn - just return the approximate frame number.
341341
assert tc.frame_num == 1
342-
343-
344-
# TODO(v0.8): Remove this test during the removal of `scenedetect.scene_detector`.
345-
def test_deprecated_timecode_module_emits_warning_on_import():
346-
FRAME_TIMECODE_WARNING = (
347-
"The `frame_timecode` submodule is deprecated, import from the base package instead."
348-
)
349-
with pytest.warns(DeprecationWarning, match=FRAME_TIMECODE_WARNING):
350-
from scenedetect.frame_timecode import FrameTimecode as _

0 commit comments

Comments
 (0)