def test_config(setup_test): vd = TaskRunner() c = """ [daily-videos] # minterpolate = False # fps = 25 # speedup = None [recap-videos] recaps = [ { label = "Last 7 days", days = 7 , speedup=30}, { label ="Last 30 days", days = 30 }, { label = "From beginning", days = 0 } ] """ vd.configs(c) assert len(vd.tasks) == 2
def test_mostrecent(setup_test): c = """ [most-recent] """ vd = TaskRunner() vd.raise_task_exceptions = True vd.configs(c) vd.run_tasks()
def test_sched(setup_test): s = dt.now() c = """ [recap-videos] # null """ vd = TaskRunner() vd.interval = timedelta(seconds=1) vd.configs(c) for _ in range(0, 4): vd.run_tasks() assert pytest.approx((dt.now()-s).total_seconds(), 4, abs=2)
def test_recap_speeds(setup_test): # 2019-10-22.mp4 2019-10-23.mp4 2019-10-24.mp4 previews with freeze_time(parse("2019-10-24 23:00:00")): print(f"getcwd={os.getcwd()}") vd = TaskRunner() c = """ [recap-videos] create = [ { label = "Last 1 days", days = 1 , speed = 1}, { label = "Last 3 days", days = 3, speed = 3 }, ] """ vd.configs(c) logging.getLogger("tmv.video").setLevel(logging.DEBUG) vd.run_tasks()
def test_diagonal_videos(setup_test_cal_cross): logging.basicConfig(format=LOG_FORMAT) logging.getLogger("tmv.video").setLevel(logging.DEBUG) c = """ [diagonal-videos] sliceage = "1 hour" """ vd = TaskRunner() vd.configs(c) vd.run_tasks() f = Path("diagonal-videos/diagonal-all.mp4") assert f.is_file() video_run1 = f.stat() # check we don't run again vd.run_tasks() video_run2 = f.stat() assert video_run1 == video_run2 # Check # frames vi = VideoInfo(f) assert vi.frames == pytest.approx(365, abs=1) fi = VideoInfo(f) assert fi.fps == 25
def test_preview_videos(setup_test): c = """ [preview-videos] filters.scale="128:-1" filters.fps = "fps=5" filters.setpts = "0.25*PTS" """ vd = TaskRunner() vd.configs(c) vd.run_tasks() assert Path("daily-videos/previews/2019-10-22.mp4").is_file frames_o = frames("daily-videos/2019-10-22.mp4") fps_o = fps("daily-videos/2019-10-22.mp4") frames_p = frames("daily-videos/previews/2019-10-22.mp4") fps_p = fps("daily-videos/previews/2019-10-22.mp4") assert fps_o == 25 assert fps_p == 5 assert frames_p == pytest.approx((fps_p / fps_o) * 0.25 * frames_o, abs=5) # assert False, "Output at " + os.getcwd() # run again - should NOT make previews of previews! run1_files = list(Path(".").glob("**/*.mp4")) vd.run_tasks() run2_files = list(Path(".").glob("**/*.mp4")) assert run1_files == run2_files, f"{run1_files} != {run2_files}"
def test_daily(setup_test): vd = TaskRunner() c = """ [daily-videos] """ vd.configs(c) vd.raise_task_exceptions = True vd.run_tasks() # make 3 days' videos d1 = Path("daily-videos/2000-01-01.mp4") d2 = Path("daily-videos/2000-01-02.mp4") d3 = Path("daily-videos/2000-01-03.mp4") assert d1.is_file() and d2.is_file() and d3.is_file() # don't re-make d1_mtime = d1.stat().st_mtime vd.run_tasks() assert d1.stat().st_mtime == d1_mtime # even if image updated Path("daily-photos/2000-01-01T01-00-00.jpg").touch() vd.run_tasks() assert d1_mtime == d1.stat().st_mtime # but only on new image updated im = Path("daily-photos/2000-01-01/2000-01-01T01-00-00.jpg") im_new = Path("daily-photos/2000-01-01/2000-01-01T01-30-00.jpg") shutil.copy(str(im), str(im_new)) vd.run_tasks() d1 = Path("daily-videos/2000-01-01.mp4") assert d1.stat().st_mtime > d1_mtime
def test_errors(setup_test, caplog): logging.getLogger("tmv.videod").setLevel(logging.DEBUG) vd = TaskRunner() c = """ [daily-videos] """ vd.configs(c) dud_file = Path("daily-photos/wrong-0place-not-an-image.moose") dud_image = Path("daily-photos/2000-01-01/no-date.jpg") null_image = Path("daily-photos/2000-01-01/2000-01-01T00-00-01.jpg") null_image.touch() dud_file.touch() dud_image.touch() vd.run_tasks() assert 'Ignoring exception' in caplog.text d1 = Path("daily-videos/2000-01-01.mp4") d2 = Path("daily-videos/2000-01-02.mp4") d3 = Path("daily-videos/2000-01-03.mp4") assert d1.is_file() and d2.is_file() and d3.is_file() d2.unlink() caplog.clear() vd = TaskRunner() c = """ [recap-videos] """ vd.configs(c) caplog.clear() null_video = Path("daily-videos/2000-01-04.mp4") null_video.touch() vd.run_tasks() assert 'Ignoring 1 invalid video' in caplog.text v1 = Path("recap-videos/last-7-days.mp4") v2 = Path("recap-videos/last-30-days.mp4") v3 = Path("recap-videos/complete.mp4") assert v1.is_file() and v2.is_file() and v3.is_file()
def test_recap_videos(setup_test): # daily-videos are : 2019-10-22, 23, 24 with freeze_time(parse("2019-10-24 23:00:00")): vd = TaskRunner() c = """ # [daily-videos] # minterpolate = False # fps = 25 # speedup = None [recap-videos] # any-name = { label = human readable, days = from now() to now() - X days, [ speedup = auto or X]} create = [ { label = "Last 1 days", days = 1 , speedup=1 }, { label ="Last 2 days", days = 2 }, { label = "From beginning", days = 0 } ] # [diagonal-videos] """ vd.configs(c) vd.raise_task_exceptions = True vd.run_tasks() v1 = Path("recap-videos/last-1-days.mp4") v2 = Path("recap-videos/last-2-days.mp4") v3 = Path("recap-videos/from-beginning.mp4") v1_mtime = v1.stat().st_mtime assert v1.is_file() and v2.is_file() and v3.is_file() vd.run_tasks() # shouldn't overwrite... assert v1.stat().st_mtime == v1_mtime Path("daily-videos/dummy").touch() # ... unless daily-videos folder mtime is updated vd.run_tasks() assert v1.stat().st_mtime > v1_mtime