2021-02-17 09:27:07 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""
|
|
|
|
Test script, for testing different situations, like:
|
|
|
|
- different day_start times
|
2021-02-18 05:29:02 -05:00
|
|
|
- different situ where playlist is empty, not long enough or to long
|
2021-02-17 09:27:07 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from datetime import datetime
|
|
|
|
from threading import Thread
|
|
|
|
from time import sleep
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
import time_machine
|
|
|
|
|
2021-03-01 06:50:44 -05:00
|
|
|
try:
|
|
|
|
from zoneinfo import ZoneInfo
|
|
|
|
except ImportError:
|
|
|
|
from backports.zoneinfo import ZoneInfo
|
|
|
|
|
2021-02-17 09:27:07 -05:00
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
|
|
# from ffplayout import playlist
|
|
|
|
|
|
|
|
# set time zone
|
|
|
|
_TZ = ZoneInfo("Europe/Berlin")
|
|
|
|
|
|
|
|
|
|
|
|
def run_at(time_tuple):
|
|
|
|
dt = datetime(*time_tuple, tzinfo=_TZ).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
|
|
@time_machine.travel(dt)
|
|
|
|
def run_in_time_machine():
|
|
|
|
desktop.output()
|
|
|
|
|
|
|
|
print(f'simulated date and time: {dt}\n')
|
|
|
|
|
|
|
|
run_in_time_machine()
|
|
|
|
|
|
|
|
|
|
|
|
def run_time(seconds):
|
|
|
|
"""
|
|
|
|
validate json values in new thread
|
|
|
|
and test if source paths exist
|
|
|
|
"""
|
|
|
|
def timer(seconds):
|
|
|
|
print(f'run test for {seconds} seconds...')
|
|
|
|
sleep(seconds)
|
|
|
|
terminate_processes()
|
2021-02-18 05:29:02 -05:00
|
|
|
print('terminated successfully')
|
2021-02-17 09:27:07 -05:00
|
|
|
|
|
|
|
terminator = Thread(name='timer', target=timer, args=(seconds,))
|
|
|
|
terminator.daemon = True
|
|
|
|
terminator.start()
|
|
|
|
|
|
|
|
|
|
|
|
def print_separater():
|
2021-02-17 11:37:12 -05:00
|
|
|
print('\n')
|
2021-02-17 09:27:07 -05:00
|
|
|
print(79 * '-')
|
|
|
|
print(79 * '-')
|
|
|
|
|
|
|
|
|
|
|
|
def shorten_playlist(file):
|
|
|
|
json_object = json.load(file)
|
|
|
|
del json_object['program'][-1:]
|
|
|
|
return json_object
|
|
|
|
|
|
|
|
|
|
|
|
def extend_playlist(file):
|
|
|
|
json_object = json.load(file)
|
|
|
|
elems = json_object['program'][:2]
|
|
|
|
json_object['program'].extend(elems)
|
|
|
|
return json_object
|
|
|
|
|
|
|
|
|
|
|
|
def clear_playlist(file):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
@patch('ffplayout.playlist.valid_json', shorten_playlist)
|
|
|
|
def run_with_less_elements(time_tuple):
|
|
|
|
run_at(time_tuple)
|
|
|
|
|
|
|
|
|
|
|
|
@patch('ffplayout.playlist.valid_json', extend_playlist)
|
|
|
|
def run_with_more_elements(time_tuple):
|
|
|
|
run_at(time_tuple)
|
|
|
|
|
|
|
|
|
|
|
|
@patch('ffplayout.playlist.valid_json', clear_playlist)
|
|
|
|
def run_with_no_elements(time_tuple):
|
|
|
|
run_at(time_tuple)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from ffplayout.output import desktop
|
2021-03-25 09:39:03 -04:00
|
|
|
from ffplayout.utils import playlist, terminate_processes
|
2021-02-17 09:27:07 -05:00
|
|
|
|
2021-02-17 11:37:12 -05:00
|
|
|
print('\ntest playlists, which are empty')
|
2021-03-25 09:39:03 -04:00
|
|
|
playlist.start = 0
|
2021-02-17 11:37:12 -05:00
|
|
|
run_time(140)
|
2021-02-18 05:29:02 -05:00
|
|
|
run_with_no_elements((2021, 2, 15, 23, 59, 53))
|
2021-02-17 09:27:07 -05:00
|
|
|
|
|
|
|
print_separater()
|
|
|
|
|
2021-02-17 11:37:12 -05:00
|
|
|
print('\ntest playlists, which are to short')
|
2021-03-25 09:39:03 -04:00
|
|
|
playlist.start = 0
|
2021-02-17 11:37:12 -05:00
|
|
|
run_time(140)
|
|
|
|
run_with_less_elements((2021, 2, 15, 23, 58, 3))
|
2021-02-17 09:27:07 -05:00
|
|
|
|
|
|
|
print_separater()
|
|
|
|
|
2021-02-17 11:37:12 -05:00
|
|
|
print('\ntest playlists, which are to long')
|
2021-03-25 09:39:03 -04:00
|
|
|
playlist.start = 0
|
2021-02-17 11:37:12 -05:00
|
|
|
run_time(140)
|
|
|
|
run_with_more_elements((2021, 2, 15, 23, 59, 33))
|
2021-02-17 09:27:07 -05:00
|
|
|
|
|
|
|
print_separater()
|
|
|
|
|
|
|
|
print('\ntest transition from playlists, with day_start at: 05:59:25')
|
2021-03-25 09:39:03 -04:00
|
|
|
playlist.start = 21575
|
2021-02-17 11:37:12 -05:00
|
|
|
run_time(140)
|
2021-02-17 09:27:07 -05:00
|
|
|
run_at((2021, 2, 17, 5, 58, 3))
|
|
|
|
|
|
|
|
print_separater()
|
|
|
|
|
|
|
|
print('\ntest transition from playlists, with day_start at: 20:00:00')
|
2021-03-25 09:39:03 -04:00
|
|
|
playlist.start = 72000
|
2021-02-17 11:37:12 -05:00
|
|
|
run_time(140)
|
2021-02-17 09:27:07 -05:00
|
|
|
run_at((2021, 2, 17, 19, 58, 23))
|