From 2f5986dc6a3a36dcc52c1ca5656c00bf86c61bd5 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Mon, 18 Dec 2023 12:38:08 -0500 Subject: [PATCH] fix(Executables): support collection-style membership test --- autotest/test_executables.py | 3 +++ modflow_devtools/executables.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/autotest/test_executables.py b/autotest/test_executables.py index c06edc3..7f9f330 100644 --- a/autotest/test_executables.py +++ b/autotest/test_executables.py @@ -26,3 +26,6 @@ def test_access(exes): # .get() works too assert exes.get("not a target") is None assert exes.get("not a target", exes["pytest"]) == exes["pytest"] + # membership test + assert "not a target" not in exes + assert "pytest" in exes diff --git a/modflow_devtools/executables.py b/modflow_devtools/executables.py index 9e34149..59408ae 100644 --- a/modflow_devtools/executables.py +++ b/modflow_devtools/executables.py @@ -16,6 +16,9 @@ class Executables(SimpleNamespace): def __init__(self, **kwargs): super().__init__(**kwargs) + def __contains__(self, item): + return item in self.__dict__ + def __setitem__(self, key, item): self.__dict__[key] = item