From cdb791c16c90fed7719f9a6e539f02eede82d1c3 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 4 Nov 2022 05:10:10 +0000 Subject: [PATCH] Allow getting the state chunk by `__id__` on MultiStateResult Fixes #140 Signed-off-by: Pedro Algarvio --- changelog/140.improvement.rst | 1 + src/saltfactories/utils/functional.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelog/140.improvement.rst diff --git a/changelog/140.improvement.rst b/changelog/140.improvement.rst new file mode 100644 index 00000000..1ce3a0ae --- /dev/null +++ b/changelog/140.improvement.rst @@ -0,0 +1 @@ +Allow getting the state chunk by `__id__` on MultiStateResult diff --git a/src/saltfactories/utils/functional.py b/src/saltfactories/utils/functional.py index 5e11ef94..7997712b 100644 --- a/src/saltfactories/utils/functional.py +++ b/src/saltfactories/utils/functional.py @@ -364,12 +364,19 @@ def run_num(self): """ return self.full_return["__run_num__"] or 0 + @property + def id(self): + """ + The ``__id__`` key on the full state return dictionary. + """ + return self.full_return.get("__id__") + @property def name(self): """ The ``name`` key on the full state return dictionary. """ - return self.full_return["name"] + return self.full_return.get("name") @property def result(self): @@ -520,7 +527,7 @@ def __contains__(self, key): Check the presence of ``key`` in the state return. """ for state_result in self: - if state_result.state_id == key: + if key in (state_result.id, state_result.state_id, state_result.name): return True return False @@ -532,7 +539,7 @@ def __getitem__(self, state_id_or_index): # We're trying to get the state run by index return self._structured[state_id_or_index] for state_result in self: - if state_result.state_id == state_id_or_index: + if state_id_or_index in (state_result.id, state_result.state_id, state_result.name): return state_result raise KeyError("No state by the ID of '{}' was found".format(state_id_or_index))