ffplayout/tests/run_time_machine.py

65 lines
1.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2021-02-11 09:44:58 +01:00
"""
Test script, for simulating different date and time.
This is useful for testing the transition from one playlist to another,
specially when the day_start time is in the night.
"""
import datetime
import os
import sys
2021-07-04 13:36:51 +02:00
from importlib import import_module
2022-01-01 23:09:20 +01:00
from unittest.mock import patch
2021-12-19 11:25:14 +01:00
from zoneinfo import ZoneInfo
import time_machine
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
2021-02-11 09:28:15 +01:00
# set time zone
_TZ = ZoneInfo("Europe/Berlin")
# fake date and time
SOURCE_TIME = [2022, 1, 24, 12, 12, 0]
2022-01-01 23:09:20 +01:00
FAKE_DELTA = -2.2
2022-01-01 23:09:20 +01:00
def fake_delta(node):
"""
override list init function for fake delta
"""
delta, total_delta = get_delta(node['begin'])
seek = abs(delta) + node['seek'] if abs(delta) + node['seek'] >= 1 else 0
seek = round(seek, 3)
seek += FAKE_DELTA
if node['out'] - seek > total_delta:
out = total_delta + seek
else:
out = node['out']
if out - seek > 1:
node['out'] = out
node['seek'] = seek
return src_or_dummy(node)
return None
@patch('ffplayout.playlist.handle_list_init', fake_delta)
2021-02-11 09:28:15 +01:00
@time_machine.travel(datetime.datetime(*SOURCE_TIME, tzinfo=_TZ))
def run_in_time_machine():
2021-07-04 13:36:51 +02:00
if stdin_args.mode:
output = import_module(f'ffplayout.output.{stdin_args.mode}').output
output()
else:
desktop.output()
if __name__ == '__main__':
2021-02-09 16:29:58 +01:00
from ffplayout.output import desktop
2022-01-01 23:09:20 +01:00
from ffplayout.utils import get_delta, src_or_dummy, stdin_args
run_in_time_machine()