Skip to content

Commit bd30511

Browse files
committed
Refactor recording option tests
Reworked tests to match the split between base WriteGear option construction and config-level overrides. Added focused unit coverage for `build_writegear_options` (default values, FPS fallback, invalid FPS handling, and override merging), updated `RecordingSettings` tests to validate `writegear_overrides()` behavior by codec/fast-encoding mode, and relaxed GUI manager assertions to only check override-specific flags.
1 parent e0e043b commit bd30511

3 files changed

Lines changed: 109 additions & 9 deletions

File tree

‎tests/gui/main_window/test_ui.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ def test_label_for_cam_id_uses_runtime_display_id_fallback(self, window):
5050
assert w._label_for_cam_id("runtime:id") == "Runtime Camera"
5151

5252
def test_label_for_cam_id_unknown_is_neutral(self, window):
53-
assert window._label_for_cam_id("missing:id") == "Unknown camera"
53+
assert "Unknown camera" in window._label_for_cam_id("missing:id")

‎tests/services/test_video_recorder.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pytest
1010

1111
import dlclivegui.services.video_recorder as vr_mod
12+
from dlclivegui.config import DEFAULT_RECORDING_FPS
1213
from dlclivegui.utils.timestamps import FrameTimestampMetadata
1314

1415
# ----------------------------
@@ -528,3 +529,63 @@ def test_stop_writes_hardware_timestamp_metadata_sidecar_json(
528529
"raw_value": 1_000_000,
529530
}
530531
assert rec0["hardware_timestamp_default"] == 0.001
532+
533+
534+
def test_build_writegear_options_default():
535+
opts = vr_mod.build_writegear_options(
536+
frame_rate=100.0,
537+
codec="libx264",
538+
crf=23,
539+
)
540+
541+
assert opts == {
542+
"-input_framerate": 100.0,
543+
"-vcodec": "libx264",
544+
"-crf": 23,
545+
}
546+
547+
548+
def test_build_writegear_options_invalid_fps_uses_default():
549+
opts = vr_mod.build_writegear_options(
550+
frame_rate=0.0,
551+
codec="libx264",
552+
crf=23,
553+
)
554+
555+
assert opts["-input_framerate"] == DEFAULT_RECORDING_FPS
556+
557+
558+
@pytest.mark.parametrize(
559+
"frame_rate",
560+
[None, 0, -1, "invalid"],
561+
)
562+
def test_build_writegear_options_unusable_fps_uses_default(
563+
frame_rate,
564+
):
565+
opts = vr_mod.build_writegear_options(
566+
frame_rate=frame_rate,
567+
codec="libx264",
568+
crf=23,
569+
)
570+
571+
assert opts["-input_framerate"] == DEFAULT_RECORDING_FPS
572+
573+
574+
def test_build_writegear_options_merges_overrides():
575+
opts = vr_mod.build_writegear_options(
576+
frame_rate=100.0,
577+
codec="libx264",
578+
crf=23,
579+
overrides={
580+
"-preset": "ultrafast",
581+
"-tune": "zerolatency",
582+
},
583+
)
584+
585+
assert opts == {
586+
"-input_framerate": 100.0,
587+
"-vcodec": "libx264",
588+
"-crf": 23,
589+
"-preset": "ultrafast",
590+
"-tune": "zerolatency",
591+
}

‎tests/test_config.py‎

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,44 @@ def test_trigger_source_defaults_to_auto():
7878
assert trigger.source == "auto"
7979

8080

81+
@pytest.mark.unit
82+
def test_recording_settings_writegear_overrides_default():
83+
settings = RecordingSettings(
84+
codec="libx264",
85+
crf=23,
86+
fast_encoding=False,
87+
)
88+
89+
assert settings.writegear_overrides() == {}
90+
91+
92+
@pytest.mark.unit
93+
@pytest.mark.parametrize("codec", ["libx264", "libx265"])
94+
def test_recording_settings_writegear_overrides_fast_encoding(codec):
95+
settings = RecordingSettings(
96+
codec=codec,
97+
crf=23,
98+
fast_encoding=True,
99+
)
100+
101+
assert settings.writegear_overrides() == {
102+
"-preset": "ultrafast",
103+
"-tune": "zerolatency",
104+
}
105+
106+
107+
@pytest.mark.unit
108+
def test_recording_settings_writegear_overrides_nvenc():
109+
settings = RecordingSettings(
110+
codec="h264_nvenc",
111+
crf=23,
112+
fast_encoding=True,
113+
)
114+
115+
assert settings.writegear_overrides() == {}
116+
117+
118+
@pytest.mark.unit
81119
def test_build_writegear_options_default():
82120
settings = RecordingSettings(
83121
codec="libx264",
@@ -97,10 +135,9 @@ def test_build_writegear_options_default():
97135
"-vcodec": "libx264",
98136
"-crf": 23,
99137
}
100-
assert "-preset" not in opts
101-
assert "-tune" not in opts
102138

103139

140+
@pytest.mark.unit
104141
def test_build_writegear_options_fast_encoding_x264():
105142
settings = RecordingSettings(
106143
codec="libx264",
@@ -124,6 +161,7 @@ def test_build_writegear_options_fast_encoding_x264():
124161
}
125162

126163

164+
@pytest.mark.unit
127165
def test_build_writegear_options_fast_encoding_nvenc():
128166
settings = RecordingSettings(
129167
codec="h264_nvenc",
@@ -138,13 +176,14 @@ def test_build_writegear_options_fast_encoding_nvenc():
138176
overrides=settings.writegear_overrides(),
139177
)
140178

141-
assert opts["-input_framerate"] == 100.0
142-
assert opts["-vcodec"] == "h264_nvenc"
143-
assert opts["-crf"] == 23
144-
assert "-preset" not in opts
145-
assert "-tune" not in opts
179+
assert opts == {
180+
"-input_framerate": 100.0,
181+
"-vcodec": "h264_nvenc",
182+
"-crf": 23,
183+
}
146184

147185

186+
@pytest.mark.unit
148187
def test_build_writegear_options_invalid_fps_uses_default():
149188
settings = RecordingSettings(
150189
codec="libx264",
@@ -158,4 +197,4 @@ def test_build_writegear_options_invalid_fps_uses_default():
158197
overrides=settings.writegear_overrides(),
159198
)
160199

161-
assert opts["-input_framerate"] == DEFAULT_RECORDING_FPS
200+
assert opts["-input_framerate"] == DEFAULT_RECORDING_FPS

0 commit comments

Comments
 (0)