47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
"""Clip length picker: a save asks for N seconds, never more than the buffer holds."""
|
|
import sys, pathlib
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
from framegen import replay
|
|
from framegen.settings import BY_KEY
|
|
|
|
|
|
def test_lengths_match_ps5_style_menu():
|
|
assert replay.LENGTHS == (0, 15, 30, 60, 180, 300, 600)
|
|
assert BY_KEY["replay"].choices == replay.LENGTHS
|
|
assert BY_KEY["replay_clip"].choices == (15, 30, 60, 180, 300, 600)
|
|
|
|
|
|
def test_clip_never_longer_than_buffer():
|
|
# the cut length is min(wanted, buffer): mirrors Recorder._save_inner
|
|
for buffer, want, expect in ((60, 600, 60), (600, 15, 15), (300, None, 300)):
|
|
assert (min(want, buffer) if want else buffer) == expect
|
|
|
|
|
|
def test_memory_for_ten_minutes_is_reasonable():
|
|
assert 2500 < replay.memory_mb(600) < 3500
|
|
|
|
|
|
def test_global_key_saves_the_default_clip_length_not_the_whole_buffer(monkeypatch):
|
|
# Ctrl+Alt+R used to call save() with no length: a 60 s buffer with a 30 s default wrote 60 s.
|
|
from framegen import globalkeys
|
|
grabbed = {}
|
|
|
|
class FakeKeys:
|
|
def __init__(self, keys): grabbed.update(keys)
|
|
def start(self): pass
|
|
def stop(self): pass
|
|
|
|
monkeypatch.setattr(globalkeys, "GlobalKeys", FakeKeys)
|
|
rec = replay.Recorder(0, hotkeys=True, device="cpu")
|
|
rec.default_clip = 30
|
|
calls = []
|
|
monkeypatch.setattr(rec, "save", lambda *a, **k: calls.append((a, k)))
|
|
rec.length = 60
|
|
rec.set_length(60) # turns the key grab on
|
|
grabbed["ctrl+alt+r"]()
|
|
assert calls == [((), {"length": 30})]
|
|
rec.default_clip = 0
|
|
grabbed["ctrl+alt+r"]()
|
|
assert calls[-1] == ((), {"length": None})
|
|
rec.close()
|