Anim: Unit tests for inserting keyframes #114465

Merged
Christoph Lendenfeld merged 9 commits from ChrisLend/blender:keyframing_unittests into main 2023-11-07 16:17:41 +01:00

Cover the current behavior of keyframe insertion with unit tests,
so the changes planned in #113278: Anim: Keyframing Rework are less likely to break things.

Unit tests added:

  • InsertKeyTest - very basic test to ensure keying things by name or with a keying set adds the right keys
  • VisualKeyingTest - check if visual keying produces the correct keyframe values
  • CycleAwareKeyingTest - check if cycle aware keying remaps the keyframes correctly and adds fcurve modifiers
Cover the current behavior of keyframe insertion with unit tests, so the changes planned in [#113278: Anim: Keyframing Rework](https://projects.blender.org/blender/blender/issues/113278) are less likely to break things. Unit tests added: * InsertKeyTest - very basic test to ensure keying things by name or with a keying set adds the right keys * VisualKeyingTest - check if visual keying produces the correct keyframe values * CycleAwareKeyingTest - check if cycle aware keying remaps the keyframes correctly and adds fcurve modifiers
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2023-11-03 17:55:08 +01:00
Christoph Lendenfeld added 3 commits 2023-11-03 17:55:21 +01:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-11-03 17:57:38 +01:00
Christoph Lendenfeld added 1 commit 2023-11-03 18:01:59 +01:00
Nathan Vegdahl requested changes 2023-11-07 12:08:31 +01:00
Nathan Vegdahl left a comment
Member

I'm not super familiar with the Python unit testing framework, but things basically look good to me. Just some minor comments.

I'm not super familiar with the Python unit testing framework, but things basically look good to me. Just some minor comments.
@ -0,0 +14,4 @@
def _fcurve_paths_match(fcurves: list, expected_paths: list) -> bool:
data_paths = list(set([fcurve.data_path for fcurve in fcurves]))
Member

I might be misunderstanding something, but the list(set()) looks redundant to me. Can't it just be [fcurve.data_path for fcurve in fcurves] stand-alone?

I might be misunderstanding something, but the `list(set())` looks redundant to me. Can't it just be `[fcurve.data_path for fcurve in fcurves]` stand-alone?
Author
Member

the data_path for fcurves is e.g. "location"
so when you have fcurves on location x, y and z you would get "location" 3 times within data_paths

the data_path for fcurves is e.g. "location" so when you have fcurves on location x, y and z you would get "location" 3 times within data_paths
Member

Ah, got it. Thanks for the explanation!

Ah, got it. Thanks for the explanation!
nathanvegdahl marked this conversation as resolved
@ -0,0 +34,4 @@
def _insert_by_name_test(insert_key: str, expected_paths: list):
bpy.ops.mesh.primitive_monkey_add()
Member

I don't feel strongly about this, so feel free to ignore if your disagree. But since we're not testing the the add object operator, I would prefer to add objects via the Python API rather than by operator, and explicitly link it to the scene collection and make it selected+active. It's more verbose, but doesn't rely on implicit side effects of operators.

And since you do this multiple times in the code, just making a function out of it would make sense. And then you can include setting the rotation mode as well.

I don't feel strongly about this, so feel free to ignore if your disagree. But since we're not testing the the add object operator, I would prefer to add objects via the Python API rather than by operator, and explicitly link it to the scene collection and make it selected+active. It's more verbose, but doesn't rely on implicit side effects of operators. And since you do this multiple times in the code, just making a function out of it would make sense. And then you can include setting the rotation mode as well.
Author
Member

that's a good point. will do

that's a good point. will do
nathanvegdahl marked this conversation as resolved
@ -0,0 +41,4 @@
with bpy.context.temp_override(**_get_view3d_context()):
bpy.ops.anim.keyframe_insert_by_name(type=insert_key)
match = _fcurve_paths_match(keyed_object.animation_data.action.fcurves, expected_paths)
bpy.ops.object.delete(use_global=False)
Member

Similarly, I would prefer deleting the object via the Python API rather than by operator.

Similarly, I would prefer deleting the object via the Python API rather than by operator.
nathanvegdahl marked this conversation as resolved
@ -0,0 +185,4 @@
self.assertEqual(len(fcurve.keyframe_points), 4)
for key in fcurve.keyframe_points:
# No keyframe should be outside the cyclic range.
self.assertLessEqual(key.co.x, cyclic_range_end)
Member

I think it would be better to test for the exact frame values you expect here. Additionally, it might be good to add a key at a frame earlier than the action frame range to make sure that gets mapped back in properly as well.

I think it would be better to test for the exact frame values you expect here. Additionally, it might be good to add a key at a frame earlier than the action frame range to make sure that gets mapped back in properly as well.
Author
Member

Good point, done that :)

Good point, done that :)
nathanvegdahl marked this conversation as resolved
Christoph Lendenfeld added 2 commits 2023-11-07 12:47:02 +01:00
Christoph Lendenfeld added 1 commit 2023-11-07 12:53:49 +01:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-11-07 12:54:10 +01:00
Nathan Vegdahl requested changes 2023-11-07 15:37:37 +01:00
@ -0,0 +94,4 @@
def test_visual_location_keying_set(self):
t_value = 1
bpy.ops.object.empty_add(type="PLAIN_AXES", align="WORLD", location=(t_value, t_value, t_value))
Member

Looks like there are still some left over operator-based object adds.

Looks like there are still some left over operator-based object adds.
Author
Member

thanks, replaced those now with the same function call

thanks, replaced those now with the same function call
nathanvegdahl marked this conversation as resolved
Christoph Lendenfeld added 2 commits 2023-11-07 16:14:20 +01:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-11-07 16:15:14 +01:00
Nathan Vegdahl approved these changes 2023-11-07 16:15:56 +01:00
Nathan Vegdahl left a comment
Member

Looks good to me!

Looks good to me!
Christoph Lendenfeld merged commit 40dccc1975 into main 2023-11-07 16:17:41 +01:00
Christoph Lendenfeld deleted branch keyframing_unittests 2023-11-07 16:17:43 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#114465
No description provided.