Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ants/io/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ def _update_history_cmd(cube):
combined_history = []
if combine_histories:
for cc in cubes:
combined_history.append(cc.attributes["history"])
if "history" in cc.attributes:
combined_history.append(cc.attributes["history"])
combined_history = "\n".join(combined_history)
for cc in cubes:
cc.attributes["history"] = combined_history
Expand Down
12 changes: 12 additions & 0 deletions lib/ants/tests/io/save/test__update_history_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ants.io.save as save
import ants.tests
import ants.utils
import iris.cube


def test_multiple_cubes_different_history():
Expand Down Expand Up @@ -45,3 +46,14 @@ def test_single_cube_append_history():
save._update_history_cmd(foo)
assert foo_history in foo.attributes["history"]
assert foo.attributes["history"] != foo_history


def test_one_cube_histoy():
"""Tests that if only one cube in a CubeList has history, all cubes will get it."""
cube1 = ants.tests.stock.geodetic([2, 2])
cube1.attributes["history"] = "the history of cube1"
cube2 = ants.tests.stock.geodetic([2, 2])
cube3 = ants.tests.stock.geodetic([2, 2])
cubelist = iris.cube.CubeList([cube1, cube2, cube3])
save._update_history_cmd(cubelist)
assert cube3.attributes["history"] == cube1.attributes["history"]
Loading