File: test_animation.py

package info (click to toggle)
terminaltexteffects 0.14.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,324 kB
  • sloc: python: 16,857; makefile: 3
file content (589 lines) | stat: -rw-r--r-- 26,306 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
"""Unit tests for the animation functionality within the terminaltexteffects package."""

import pytest

from terminaltexteffects.engine.animation import CharacterVisual, Frame, Scene
from terminaltexteffects.engine.base_character import EffectCharacter
from terminaltexteffects.utils import easing
from terminaltexteffects.utils.exceptions import (
    ActivateEmptySceneError,
    AnimationSceneError,
    FrameDurationError,
    SceneNotFoundError,
)
from terminaltexteffects.utils.geometry import Coord
from terminaltexteffects.utils.graphics import Color, ColorPair, Gradient

pytestmark = [pytest.mark.engine, pytest.mark.animation, pytest.mark.smoke]


@pytest.fixture
def character_visual_default() -> CharacterVisual:
    """Return a default CharacterVisual instance with the symbol set to "a".

    Returns:
        CharacterVisual: A new instance of CharacterVisual with the default symbol "a".

    """
    return CharacterVisual(
        symbol="a",
    )


@pytest.fixture
def character_visual_all_modes_enabled() -> CharacterVisual:
    """Return a CharacterVisual instance with all modes enabled.

    Returns:
        CharacterVisual: A new instance of CharacterVisual with all attributes set.

    """
    return CharacterVisual(
        symbol="a",
        bold=True,
        dim=True,
        italic=True,
        underline=True,
        blink=True,
        reverse=True,
        hidden=True,
        strike=True,
        colors=ColorPair("#ffffff", "#ffffff"),
        _fg_color_code="ffffff",
        _bg_color_code="ffffff",
    )


@pytest.fixture
def character() -> EffectCharacter:
    """Return a default EffectCharacter instance."""
    return EffectCharacter(0, "a", 0, 0)


def test_character_visual_init(character_visual_all_modes_enabled: CharacterVisual) -> None:
    """Test that the formatted_symbol of character_visual_all_modes_enabled is correctly initialized."""
    assert (
        character_visual_all_modes_enabled.formatted_symbol
        == "\x1b[1m\x1b[3m\x1b[4m\x1b[5m\x1b[7m\x1b[8m\x1b[9m\x1b[38;2;255;255;255m\x1b[48;2;255;255;255ma\x1b[0m"
    )


def test_character_visual_init_default(character_visual_default: CharacterVisual) -> None:
    """Test that the default formatted symbol is 'a'."""
    assert character_visual_default.formatted_symbol == "a"


def test_frame_init(character_visual_default: CharacterVisual) -> None:
    """Test that the Frame instance is correctly initialized."""
    frame = Frame(character_visual=character_visual_default, duration=5)
    assert frame.character_visual == character_visual_default
    assert frame.duration == 5
    assert frame.ticks_elapsed == 0


def test_scene_init() -> None:
    """Test that the Scene instance is correctly initialized."""
    scene = Scene(scene_id="test_scene", is_looping=True, sync=Scene.SyncMetric.STEP, ease=easing.in_sine)
    assert scene.scene_id == "test_scene"
    assert scene.is_looping is True
    assert scene.sync == Scene.SyncMetric.STEP
    assert scene.ease == easing.in_sine


def test_scene_add_frame() -> None:
    """Test that a frame can be added to the Scene instance."""
    scene = Scene(scene_id="test_scene")
    scene.add_frame(
        symbol="a",
        duration=5,
        colors=ColorPair("#ffffff", "#ffffff"),
        bold=True,
        italic=True,
        blink=True,
        hidden=True,
    )
    assert len(scene.frames) == 1
    frame = scene.frames[0]
    assert (
        frame.character_visual.formatted_symbol
        == "\x1b[1m\x1b[3m\x1b[5m\x1b[8m\x1b[38;2;255;255;255m\x1b[48;2;255;255;255ma\x1b[0m"
    )
    assert frame.duration == 5
    assert frame.character_visual.colors == ColorPair("#ffffff", "#ffffff")
    assert frame.character_visual.bold is True


def test_scene_add_frame_invalid_duration() -> None:
    """Test that a FrameDurationError is raised when a frame with a duration of 0 is added to the scene."""
    scene = Scene(scene_id="test_scene")
    with pytest.raises(FrameDurationError):
        scene.add_frame(symbol="a", duration=0, colors=ColorPair("#ffffff", "#ffffff"))


def test_scene_apply_gradient_to_symbols_equal_colors_and_symbols() -> None:
    """Test symbols are correctly assigned colors from a gradient when the colors and symbols are equal in length."""
    scene = Scene(scene_id="test_scene")
    gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=2)
    symbols = ["a", "b", "c"]
    scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=gradient)
    assert len(scene.frames) == 3
    for i, frame in enumerate(scene.frames):
        assert frame.duration == 1
        assert frame.character_visual._fg_color_code == gradient.spectrum[i].rgb_color


def test_scene_apply_gradient_to_symbols_unequal_colors_and_symbols() -> None:
    """Test that all colors and symbols are represented when the gradient and symbols length are unequal.

    Verify the gradient is represented in the scene frames and
    the symbols are progressed such that the first and final symbols align to the
    first and final colors.
    """
    scene = Scene(scene_id="test_scene")
    gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=4)
    symbols = ["q", "z"]
    scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=gradient)
    assert len(scene.frames) == 5
    assert scene.frames[0].character_visual._fg_color_code == gradient.spectrum[0].rgb_color
    assert "q" in scene.frames[0].character_visual.symbol
    assert scene.frames[-1].character_visual._fg_color_code == gradient.spectrum[-1].rgb_color
    assert "z" in scene.frames[-1].character_visual.symbol


def test_animation_init(character: EffectCharacter) -> None:
    """Test that the EffectCharacter instance is correctly initialized."""
    assert character.animation.character == character
    assert character.animation.scenes == {}
    assert character.animation.active_scene is None
    assert character.animation.use_xterm_colors is False
    assert character.animation.no_color is False
    assert character.animation.xterm_color_map == {}
    assert character.animation.active_scene_current_step == 0


def test_animation_new_scene(character: EffectCharacter) -> None:
    """Test that a new scene can be created."""
    animation = character.animation
    scene = animation.new_scene(scene_id="test_scene", is_looping=True)
    assert isinstance(scene, Scene)
    assert scene.scene_id == "test_scene"
    assert scene.is_looping is True
    assert "test_scene" in animation.scenes


def test_animation_new_scene_without_id(character: EffectCharacter) -> None:
    """Test that a new scene can be created without a specified ID."""
    animation = character.animation
    scene = animation.new_scene()
    assert isinstance(scene, Scene)
    assert scene.scene_id == "0"
    assert "0" in animation.scenes


def test_animation_new_scene_id_generation_deleted_scene(character: EffectCharacter) -> None:
    """Test that a new scene ID is generated when the previous scene ID has been deleted."""
    for _ in range(4):
        character.animation.new_scene()
    character.animation.scenes.pop("2")
    character.animation.new_scene()


def test_animation_query_scene(character: EffectCharacter) -> None:
    """Test that a scene can be queried from the animation."""
    animation = character.animation
    scene = animation.new_scene(scene_id="test_scene", is_looping=True)
    assert animation.query_scene("test_scene") is scene


def test_animation_query_nonexistent_scene(character: EffectCharacter) -> None:
    """Test that querying a non-existent scene on the EffectCharacter's animation raises a SceneNotFoundError."""
    animation = character.animation
    with pytest.raises(SceneNotFoundError):
        animation.query_scene("nonexistent_scene")


def test_animation_looping_active_scene_is_complete(character: EffectCharacter) -> None:
    """Test that the looping active scene is complete after all frames have been processed."""
    animation = character.animation
    scene = animation.new_scene(scene_id="test_scene", is_looping=True)
    scene.add_frame(symbol="a", duration=2)
    animation.activate_scene(scene)
    assert animation.active_scene_is_complete() is True


def test_animation_non_looping_active_scene_is_complete(character: EffectCharacter) -> None:
    """Test that the non-looping active scene is complete after processing all frames."""
    animation = character.animation
    scene = animation.new_scene(scene_id="test_scene")
    scene.add_frame(symbol="a", duration=1)
    animation.activate_scene(scene)
    assert animation.active_scene_is_complete() is False
    animation.step_animation()
    assert animation.active_scene_is_complete() is True


def test_animation_get_color_code_no_color(character: EffectCharacter) -> None:
    """Test that the color code is None when no_color is enabled."""
    character.animation.no_color = True
    assert character.animation._get_color_code(Color("#ffffff")) is None


def test_animation_get_color_code_use_xterm_colors(character: EffectCharacter) -> None:
    """Ensure xterm color mapping is used when the flag is enabled."""
    character.animation.use_xterm_colors = True
    assert character.animation._get_color_code(Color("#ffffff")) == 15
    assert character.animation._get_color_code(Color(0)) == 0
    assert character.animation._get_color_code(Color("#ffffff")) == 15


def test_animation_get_color_code_rgb_color(character: EffectCharacter) -> None:
    """Ensure standard RGB color codes are returned when xterm colors are disabled."""
    assert character.animation._get_color_code(Color("#ffffff")) == "ffffff"


def test_animation_get_color_code_color_is_none(character: EffectCharacter) -> None:
    """Verify None is safely handled when requesting a color code."""
    assert character.animation._get_color_code(None) is None


def test_animation_set_appearance_existing_colors(character: EffectCharacter) -> None:
    """Ensure existing colors take precedence when the handling mode is 'always'."""
    character.animation.existing_color_handling = "always"
    character.animation.input_fg_color = Color("#ffffff")
    character.animation.input_bg_color = Color("#000000")
    character.animation.set_appearance("a", colors=ColorPair("#f0f0f0", "#0f0f0f"))
    assert character.animation.current_character_visual.colors == ColorPair(
        "#ffffff",
        "#000000",
    )


def test_animation_adjust_color_brightness_half(character: EffectCharacter) -> None:
    """Confirm halving brightness scales the color toward black."""
    red = Color("#ff0000")
    new_color = character.animation.adjust_color_brightness(red, 0.5)
    assert new_color == Color("#7f0000")


def test_animation_adjust_color_brightness_double(character: EffectCharacter) -> None:
    """Verify doubling brightness clamps the value to white."""
    red = Color("#ff0000")
    new_color = character.animation.adjust_color_brightness(red, 2)
    assert new_color == Color("#ffffff")


def test_animation_adjust_color_brightness_quarter(character: EffectCharacter) -> None:
    """Ensure quarter brightness darkens the color proportionally."""
    red = Color("#ff0000")
    new_color = character.animation.adjust_color_brightness(red, 0.25)
    assert new_color == Color("#3f0000")


def test_animation_adjust_color_brightness_zero(character: EffectCharacter) -> None:
    """Validate zero brightness results in pure black."""
    red = Color("#ff0000")
    new_color = character.animation.adjust_color_brightness(red, 0)
    assert new_color == Color("#000000")


def test_animation_adjust_color_brightness_negative(character: EffectCharacter) -> None:
    """Ensure negative brightness factors are clamped to black."""
    red = Color("#ff0000")
    new_color = character.animation.adjust_color_brightness(red, -0.5)
    assert new_color == Color("#000000")


def test_animation_adjust_color_brightness_black(character: EffectCharacter) -> None:
    """Confirm adjusting brightness of black always returns black."""
    black = Color("#000000")
    new_color = character.animation.adjust_color_brightness(black, 0.5)
    assert new_color == Color("#000000")


def test_animation_ease_animation_no_active_scene(character: EffectCharacter) -> None:
    """Ensure the easing helper defaults to zero with no active scene."""
    assert character.animation._ease_animation(easing.in_sine) == 0


def test_animation_ease_animation_active_scene(character: EffectCharacter) -> None:
    """Verify easing value is calculated based on the active scene's progress."""
    scene = character.animation.new_scene(scene_id="test_scene", ease=easing.in_sine)
    scene.add_frame(symbol="a", duration=10)
    scene.add_frame(symbol="b", duration=10)
    character.animation.activate_scene(scene)
    for _ in range(10):
        character.animation.step_animation()
    n = character.animation._ease_animation(easing.in_sine)
    assert n == 0.2928932188134524


def test_animation_step_animation_sync_step(character: EffectCharacter) -> None:
    """Ensure animations synchronized to steps advance correctly."""
    p = character.motion.new_path()
    p.new_waypoint(Coord(10, 10))
    character.motion.activate_path(p)
    s = character.animation.new_scene(sync=Scene.SyncMetric.STEP)
    s.add_frame(symbol="a", duration=10)
    s.add_frame(symbol="b", duration=10)
    character.animation.activate_scene(s)
    for _ in range(5):
        character.animation.step_animation()


def test_animation_step_animation_sync_distance(character: EffectCharacter) -> None:
    """Ensure animations synchronized to distance progress when traveling."""
    p = character.motion.new_path()
    p.new_waypoint(Coord(10, 10))
    character.motion.activate_path(p)
    s = character.animation.new_scene(sync=Scene.SyncMetric.DISTANCE)
    s.add_frame(symbol="a", duration=10)
    s.add_frame(symbol="b", duration=10)
    character.animation.activate_scene(s)
    for _ in range(5):
        character.animation.step_animation()


def test_animation_step_animation_sync_waypoint_deactivated(character: EffectCharacter) -> None:
    """Confirm animation stepping behaves when the associated path deactivates."""
    p = character.motion.new_path()
    p.new_waypoint(Coord(10, 10))
    character.motion.activate_path(p)
    s = character.animation.new_scene(sync=Scene.SyncMetric.DISTANCE)
    s.add_frame(symbol="a", duration=10)
    s.add_frame(symbol="b", duration=10)
    character.animation.activate_scene(s)
    for _ in range(5):
        character.animation.step_animation()
    character.motion.deactivate_path(p)
    character.animation.step_animation()


def test_animation_step_animation_eased_scene(character: EffectCharacter) -> None:
    """Ensure eased scenes progress until completion."""
    scene = character.animation.new_scene(scene_id="test_scene", ease=easing.in_sine)
    scene.add_frame(symbol="a", duration=10)
    scene.add_frame(symbol="b", duration=10)
    character.animation.activate_scene(scene)
    while character.animation.active_scene:
        character.animation.step_animation()


def test_animation_step_animation_eased_scene_looping(character: EffectCharacter) -> None:
    """Ensure eased looping scenes continue cycling without errors."""
    scene = character.animation.new_scene(scene_id="test_scene", ease=easing.in_sine, is_looping=True)
    scene.add_frame(symbol="a", duration=10)
    scene.add_frame(symbol="b", duration=10)
    character.animation.activate_scene(scene)
    for _ in range(100):
        character.animation.step_animation()


def test_animation_deactivate_scene(character: EffectCharacter) -> None:
    """Verify that deactivating a scene clears the active scene reference."""
    scene = character.animation.new_scene(scene_id="test_scene")
    scene.add_frame(symbol="a", duration=10)
    character.animation.activate_scene(scene)
    character.animation.deactivate_scene()
    assert character.animation.active_scene is None


def test_scene_get_color_code_no_color(character: EffectCharacter) -> None:
    """Ensure Scene mirrors Animation color handling when color is disabled."""
    character.animation.no_color = True
    new_scene = character.animation.new_scene()
    assert new_scene._get_color_code(Color("#ffffff")) is None


def test_scene_get_color_code_use_xterm_colors(character: EffectCharacter) -> None:
    """Validate Scene resolves xterm codes when that option is enabled."""
    character.animation.use_xterm_colors = True
    new_scene = character.animation.new_scene()
    assert new_scene._get_color_code(Color("#ffffff")) == 15
    assert new_scene._get_color_code(Color(0)) == 0
    assert new_scene._get_color_code(Color("#ffffff")) == 15


def test_scene_input_color_from_existing(character: EffectCharacter) -> None:
    """Ensure Scenes capture preexisting input colors from the animation."""
    character.animation.existing_color_handling = "always"
    character.animation.input_fg_color = Color("#ffffff")
    character.animation.input_bg_color = Color("#000000")
    new_scene = character.animation.new_scene()
    assert new_scene.preexisting_colors == ColorPair("#ffffff", "#000000")


def test_scene_add_frame_existing_colors(character: EffectCharacter) -> None:
    """Confirm scene-level preexisting colors override per-frame colors."""
    character.animation.existing_color_handling = "always"
    character.animation.input_fg_color = Color("#ffffff")
    character.animation.input_bg_color = Color("#000000")
    new_scene = character.animation.new_scene()
    new_scene.add_frame(symbol="a", duration=1, colors=ColorPair("#f0f0f0", "#0f0f0f"))
    # the frame colors should be overridden by the scene colors derived from the input
    assert new_scene.frames[0].character_visual.colors == ColorPair("#ffffff", "#000000")


def test_activate_scene_with_no_frames(character: EffectCharacter) -> None:
    """Ensure activating an empty scene raises an error."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    with pytest.raises(ActivateEmptySceneError):
        character.animation.activate_scene(new_scene)


def test_scene_get_next_visual_looping(character: EffectCharacter) -> None:
    """Verify looping scenes wrap around when fetching visuals."""
    new_scene = character.animation.new_scene(scene_id="test_scene", is_looping=True)
    new_scene.add_frame(symbol="a", duration=1)
    new_scene.add_frame(symbol="b", duration=1)
    character.animation.activate_scene(new_scene)
    visual = new_scene.get_next_visual()
    assert visual.symbol == "a"
    visual = new_scene.get_next_visual()
    assert visual.symbol == "b"
    visual = new_scene.get_next_visual()
    assert visual.symbol == "a"


def test_scene_apply_gradient_to_symbols_empty_gradient(character: EffectCharacter) -> None:
    """Ensure empty gradient spectra trigger an error."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=2)
    gradient.spectrum.clear()
    symbols = ["a", "b", "c"]
    with pytest.raises(AnimationSceneError):
        new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=gradient)


def test_scene_apply_gradient_to_symbols_both_gradients_empty(character: EffectCharacter) -> None:
    """Ensure both empty gradients raise the same error path."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=2)
    gradient.spectrum.clear()
    symbols = ["a", "b", "c"]
    with pytest.raises(AnimationSceneError):
        new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=gradient, bg_gradient=gradient)


def test_scene_apply_gradient_to_symbols_invalid_symbols(character: EffectCharacter) -> None:
    """Test that an ApplyGradientToSymbolsInvalidSymbolError is raised when a symbol with length > 1 is passed."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=2)
    symbols = ["aa", "b", "c"]
    with pytest.raises(AnimationSceneError):
        new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=gradient)


def test_scene_apply_gradient_to_symbols_single_single_step(character: EffectCharacter) -> None:
    """Verify a single-step gradient produces start and end frames."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=1)
    symbols = ["a"]
    new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=gradient, bg_gradient=gradient)
    assert len(new_scene.frames) == 2
    for i, frame in enumerate(new_scene.frames):
        assert frame.character_visual._fg_color_code == gradient.spectrum[i].rgb_color
        assert symbols[0] in frame.character_visual.symbol


def test_scene_apply_gradient_to_symbols_fg_bg_spectrums_not_equal(character: EffectCharacter) -> None:
    """Ensure frames expand to cover both spectrum lengths when unequal."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    fg_gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=8)
    bg_gradient = Gradient(Color("#ffffff"), Color("#000000"), steps=6)
    symbols = ["a", "b", "c"]
    new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=fg_gradient, bg_gradient=bg_gradient)
    assert len(new_scene.frames) == 9
    for i, frame in enumerate(new_scene.frames):
        assert frame.character_visual._fg_color_code == fg_gradient.spectrum[i].rgb_color


def test_scene_apply_gradient_to_symbols_empty_spectrums(character: EffectCharacter) -> None:
    """Ensure clearing both spectrums raises an AnimationSceneError."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    fg_gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=1)
    bg_gradient = Gradient(Color("#ffffff"), Color("#000000"), steps=1)
    fg_gradient.spectrum.clear()
    bg_gradient.spectrum.clear()
    symbols = ["a", "b", "c"]
    with pytest.raises(AnimationSceneError):
        new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=fg_gradient, bg_gradient=bg_gradient)


def test_scene_apply_gradient_to_symbols_no_gradients(character: EffectCharacter) -> None:
    """Verify omitting both gradients is considered invalid."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    symbols = ["a", "b", "c"]
    with pytest.raises(AnimationSceneError):
        new_scene.apply_gradient_to_symbols(symbols, duration=1)


def test_scene_apply_gradient_to_symbols_larger_bg_spectrum(character: EffectCharacter) -> None:
    """Ensure larger background spectrums determine the frame count when longer."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    fg_gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=3)
    bg_gradient = Gradient(Color("#ffffff"), Color("#000000"), steps=6)
    symbols = ["a", "b", "c"]
    new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=fg_gradient, bg_gradient=bg_gradient)
    assert len(new_scene.frames) == 7
    for i, frame in enumerate(new_scene.frames):
        assert frame.character_visual._bg_color_code == bg_gradient.spectrum[i].rgb_color


def test_scene_apply_gradient_to_symbols_larger_fg_spectrum(character: EffectCharacter) -> None:
    """Ensure larger foreground spectrums determine the total frame count."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    fg_gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=6)
    bg_gradient = Gradient(Color("#ffffff"), Color("#000000"), steps=3)
    symbols = ["a", "b", "c"]
    new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=fg_gradient, bg_gradient=bg_gradient)
    assert len(new_scene.frames) == 7
    for i, frame in enumerate(new_scene.frames):
        assert frame.character_visual._fg_color_code == fg_gradient.spectrum[i].rgb_color


def test_scene_apply_gradient_to_symbols_fg_gradient_only(character: EffectCharacter) -> None:
    """Ensure supplying only a foreground gradient still creates frames."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    fg_gradient = Gradient(Color("#000000"), Color("#ffffff"), steps=3)
    symbols = ["a", "b", "c"]
    new_scene.apply_gradient_to_symbols(symbols, duration=1, fg_gradient=fg_gradient)
    assert len(new_scene.frames) == 4
    for i, frame in enumerate(new_scene.frames):
        assert frame.character_visual._fg_color_code == fg_gradient.spectrum[i].rgb_color


def test_scene_apply_gradient_to_symbols_bg_gradient_only(character: EffectCharacter) -> None:
    """Ensure supplying only a background gradient still creates frames."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    bg_gradient = Gradient(Color("#ffffff"), Color("#000000"), steps=3)
    symbols = ["a", "b", "c"]
    new_scene.apply_gradient_to_symbols(symbols, duration=1, bg_gradient=bg_gradient)
    assert len(new_scene.frames) == 4
    for i, frame in enumerate(new_scene.frames):
        assert frame.character_visual._bg_color_code == bg_gradient.spectrum[i].rgb_color


def test_scene_reset_scene(character: EffectCharacter) -> None:
    """Verify resetting a scene clears playback state and frame ticks."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    new_scene.add_frame(symbol="a", duration=3)
    new_scene.add_frame(symbol="b", duration=3)
    for _ in range(4):
        new_scene.get_next_visual()
    new_scene.reset_scene()
    for sequence in new_scene.frames:
        assert sequence.ticks_elapsed == 0
    assert not new_scene.played_frames


def test_scene_id_equality(character: EffectCharacter) -> None:
    """Ensure scenes with matching IDs compare as equal."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    new_scene2 = character.animation.new_scene(scene_id="test_scene")
    assert new_scene == new_scene2


def test_scene_equality_incorrect_type(character: EffectCharacter) -> None:
    """Ensure Scene equality checks guard against other object types."""
    new_scene = character.animation.new_scene(scene_id="test_scene")
    assert new_scene != "test_scene"