"""Offline, statically declared enums and timing metadata for editor use.""" from pathlib import Path import sys import unittest sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "Content/Python")) from ue_workshop.animation_clip import AnimationClip from ue_workshop.animations import FighterAnimations, CreatureAnimations from ue_workshop.characters import FIGHTER_MODEL, CREATURE_MODEL, _clips class TimingClip(AnimationClip): WALK = ("walk", 2.0) FLOAT_DURATION = ("float_duration", 3.200000047683716) FRACTIONAL = ("fractional", 2.1) class CatalogTests(unittest.TestCase): def test_catalog_covers_all_source_files_without_duplicate_keys(self): for catalog, model in ((FighterAnimations, FIGHTER_MODEL), (CreatureAnimations, CREATURE_MODEL)): with self.subTest(model=model): keys = [clip.key for clip in catalog] self.assertEqual(set(keys), set(_clips(model))) self.assertEqual(len(keys), len(set(keys))) self.assertTrue(all(clip.seconds > 0 for clip in catalog)) def test_metadata_is_available_without_loading_unreal(self): self.assertNotIn("unreal", sys.modules) self.assertEqual(FighterAnimations.DRAW_A_GREAT_SWORD_1.key, "draw_a_great_sword_1") self.assertEqual(FighterAnimations.DRAW_A_GREAT_SWORD_1.seconds, 0.5) self.assertEqual(FighterAnimations.DRAW_A_GREAT_SWORD_1.frames(24), 12) def test_frames_respect_fps_speed_and_fractional_end(self): self.assertEqual(TimingClip.WALK.frames(24), 48) self.assertEqual(TimingClip.WALK.frames(30, speed=2), 30) self.assertEqual(TimingClip.FRACTIONAL.frames(24), 51) self.assertEqual(TimingClip.FLOAT_DURATION.frames(30), 96) def test_invalid_fps_and_speed_are_rejected(self): for fps in (0, -1, True, 24.5): with self.subTest(fps=fps), self.assertRaises(ValueError): TimingClip.WALK.frames(fps) for speed in (0, -1, True, float("nan"), float("inf")): with self.subTest(speed=speed), self.assertRaises(ValueError): TimingClip.WALK.frames(24, speed)