]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pytests: add helper to grab a directory from environment
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 7 Jul 2023 04:12:19 +0000 (16:12 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 24 Aug 2023 02:53:30 +0000 (02:53 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/__init__.py

index f117d0b1341969281ef83f606af67878721690d4..09c70aab134604a6e8a42a06517b3a935bc38ae6 100644 (file)
@@ -704,3 +704,19 @@ def check_help_consistency(out,
 
     if errors:
         return "\n".join(errors)
+
+
+def get_env_dir(key):
+    """A helper to pull a directory name from the environment, used in
+    some tests that optionally write e.g. fuzz seeds into a directory
+    named in an environment valiable.
+    """
+    dir = os.environ.get(key)
+    if dir is None:
+        return None
+
+    if not os.path.isdir(dir):
+        raise ValueError(
+            f"{key} should name an existing directory (got '{dir}')")
+
+    return dir