From 7b9d823ba9ab99585194971f9071a459b3f6ac2b Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 29 Nov 2024 14:11:29 +0100 Subject: [PATCH] test/helper: add a helper for status JSON data The JSON output from "rauc status" is a bit difficult to interpret since it always requires iterating over the array elements to search for the slot. To simplify future test assertions, use a helper here that returns the slot data for a given slot name. Signed-off-by: Enrico Joerns --- test/helper.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/helper.py b/test/helper.py index d0e0d452a..48f15090d 100644 --- a/test/helper.py +++ b/test/helper.py @@ -49,3 +49,18 @@ def run(command, *, timeout=30): def run_tree(path): subprocess.check_call(["tree", "--metafirst", "-ax", "-pugs", "--inodes", path]) + + +def slot_data_from_json(status_data, slotname): + """ + Helper to return the slot data from 'rauc status' JSON output. + + :param status_data: JSON data obtained from 'rauc status'. + :param slotname: The name of the slot to find in the data. + :return: Slot data as a dictionary. + """ + for slot in status_data["slots"]: + if slotname in slot: + return slot[slotname] + else: + raise ValueError(f"Slot '{slotname}' not found")