From 8471cc1996245b6a6ddf931e9c2c126055fcb8cb Mon Sep 17 00:00:00 2001 From: Colin Basnett Date: Wed, 2 Apr 2025 17:34:58 -0700 Subject: [PATCH] Added simple PSA import test Just validates that the actions get imported. --- tests/data/Shrek.psa | 3 +++ tests/data/Shrek.psk | 3 +++ tests/psa_import_test.py | 39 +++++++++++++++++++++++++++++++++++++++ tests/psk_import_test.py | 1 + 4 files changed, 46 insertions(+) create mode 100644 tests/data/Shrek.psa create mode 100644 tests/data/Shrek.psk create mode 100644 tests/psa_import_test.py diff --git a/tests/data/Shrek.psa b/tests/data/Shrek.psa new file mode 100644 index 0000000..eda1310 --- /dev/null +++ b/tests/data/Shrek.psa @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39c927947184cdbe665131eb4711d58a316860a2c498c8e713780c5a0b7ae1b5 +size 13092664 diff --git a/tests/data/Shrek.psk b/tests/data/Shrek.psk new file mode 100644 index 0000000..394c3d3 --- /dev/null +++ b/tests/data/Shrek.psk @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9679ee4660787edf558426e75a2c24e96330f5e2d0945510aa156b6ef4911931 +size 95020 diff --git a/tests/psa_import_test.py b/tests/psa_import_test.py new file mode 100644 index 0000000..feb543b --- /dev/null +++ b/tests/psa_import_test.py @@ -0,0 +1,39 @@ +import bpy +import pytest + +SHREK_PSK_FILEPATH = 'tests/data/Shrek.psk' +SHREK_PSA_FILEPATH = 'tests/data/Shrek.psa' + + +@pytest.fixture(autouse=True) +def run_before_and_after_Tests(tmpdir): + # Setup: Run before the tests + bpy.ops.wm.read_homefile(app_template='') + yield + # Teardown: Run after the tests + pass + + +def test_psa_import_all(): + assert bpy.ops.psk.import_file( + filepath=SHREK_PSK_FILEPATH, + components='ALL', + ) == {'FINISHED'}, "PSK import failed." + + armature_object = bpy.data.objects.get('Shrek', None) + assert armature_object is not None, "Armature object not found in the scene." + assert armature_object.type == 'ARMATURE', "Object is not of type ARMATURE." + + # Select the armature object + bpy.context.view_layer.objects.active = armature_object + armature_object.select_set(True) + + # Import the associated PSA file with import_all operator. + assert bpy.ops.psa.import_all( + filepath=SHREK_PSA_FILEPATH + ) == {'FINISHED'}, "PSA import failed." + + # TODO: More thorough tests on the imported data for the animations. + EXPECTED_ACTION_COUNT = 135 + assert len(bpy.data.actions) == EXPECTED_ACTION_COUNT, \ + f"Expected {EXPECTED_ACTION_COUNT} actions, but found {len(bpy.data.actions)}." diff --git a/tests/psk_import_test.py b/tests/psk_import_test.py index a13908f..ed26856 100644 --- a/tests/psk_import_test.py +++ b/tests/psk_import_test.py @@ -23,6 +23,7 @@ def test_psk_import_all(): armature_object = bpy.data.objects.get('Suzanne', None) + assert armature_object is not None, "Armature object not found in the scene" assert armature_object.type == 'ARMATURE', "Armature object type should be ARMATURE" assert armature_object is not None, "Armature object not found in the scene" assert len(armature_object.children) == 1, "Armature object should have one child"