Skip to content

Commit

Permalink
fix MDA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyAJohnston committed Jun 12, 2024
1 parent 10c278f commit 6a4ad61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
9 changes: 9 additions & 0 deletions tests/__snapshots__/test_mda.ambr
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# serializer version: 1
# name: TestMDA.test_save_persistance
[[0.4 0.3 0.5]
[0.4 0.3 0.5]
[0.4 0.3 0.5]
...
[1.3 0.3 0.6]
[1.3 0.4 0.6]
[1.3 0.4 0.6]]
# ---
# name: TestMDA.test_save_persistance[False]
[[0.4 0.3 0.5]
[0.4 0.3 0.5]
Expand Down
35 changes: 19 additions & 16 deletions tests/test_mda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import molecularnodes as mn
from . import utils
from molecularnodes.blender.obj import get_attribute
from molecularnodes.blender.obj import get_attribute, ObjectTracker

import MDAnalysis as mda
import numpy as np
Expand Down Expand Up @@ -216,35 +216,38 @@ def test_update_deleted_objects(self, in_memory, mda_session, universe):
# remove the cube
bpy.data.objects.remove(bpy.data.objects["Cube"])

@pytest.mark.parametrize("in_memory", [False, True])
def test_save_persistance(
self,
snapshot_custom: NumpySnapshotExtension,
tmp_path,
in_memory,
mda_session,
universe,
):
remove_all_molecule_objects(mda_session)
mda_session.show(universe, in_memory=in_memory)
# save
bpy.ops.wm.save_as_mainfile(filepath=str(tmp_path / "test.blend"))
# start with a fresh file and no objects added
bpy.ops.wm.read_homefile()
for item in bpy.data.objects:
bpy.data.objects.remove(item)

mda_session.show(universe, in_memory=False, style="ribbon")
bpy.context.scene.frame_set(0)

# test that we can save the file and it is created only after saving
assert not os.path.exists(str(tmp_path / "test.mda_session"))
bpy.ops.wm.save_as_mainfile(filepath=str(tmp_path / "test.blend"))
assert os.path.exists(str(tmp_path / "test.mda_session"))

# reload
remove_all_molecule_objects(mda_session)
bpy.ops.wm.open_mainfile(filepath=str(tmp_path / "test.blend"))
bob = bpy.data.objects["atoms"]
bob = bpy.data.objects[-1]

verts_frame_0 = mn.blender.obj.get_attribute(bob, "position")

# change blender frame to 1
bpy.context.scene.frame_set(1)
bob = bpy.data.objects["atoms"]
verts_frame_1 = mn.blender.obj.get_attribute(bob, "position")
assert snapshot_custom == verts_frame_1
# change blender frame to 4
bpy.context.scene.frame_set(4)

verts_frame_4 = mn.blender.obj.get_attribute(bob, "position")

assert not np.isclose(verts_frame_0, verts_frame_1).all()
assert snapshot_custom == verts_frame_4
assert not np.allclose(verts_frame_0, verts_frame_4)


class TestMDA_FrameMapping:
Expand Down

0 comments on commit 6a4ad61

Please sign in to comment.