From 5b63333357fe416cbbef4ca7b3617dbd94a54e27 Mon Sep 17 00:00:00 2001 From: Theo Geddes Date: Tue, 25 Aug 2026 15:34:48 +0100 Subject: [PATCH] #171: Allow cubelist with only one history to be saved --- lib/ants/io/save.py | 3 ++- lib/ants/tests/io/save/test__update_history_cmd.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ants/io/save.py b/lib/ants/io/save.py index 07f6e4e..9ebd7bf 100644 --- a/lib/ants/io/save.py +++ b/lib/ants/io/save.py @@ -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 diff --git a/lib/ants/tests/io/save/test__update_history_cmd.py b/lib/ants/tests/io/save/test__update_history_cmd.py index 8d9fa71..fb5d09d 100644 --- a/lib/ants/tests/io/save/test__update_history_cmd.py +++ b/lib/ants/tests/io/save/test__update_history_cmd.py @@ -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(): @@ -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"]