summaryrefslogtreecommitdiff
path: root/subplot
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-07-25 11:00:55 +0300
committerLars Wirzenius <liw@liw.fi>2021-07-25 11:38:40 +0300
commita24b6242e6c41dc222f368194cc141c76b36a5e9 (patch)
treeadf913be2175d9ee6a796c892716052023cd9e88 /subplot
parent77a7d5a0fec242b929f62295a1b7d8e7700bfc35 (diff)
downloadvmadm-a24b6242e6c41dc222f368194cc141c76b36a5e9.tar.gz
test: make tilde expansion be more generic
Sponsored-by: author
Diffstat (limited to 'subplot')
-rw-r--r--subplot/vmadm.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/subplot/vmadm.py b/subplot/vmadm.py
index 42f857a..916458f 100644
--- a/subplot/vmadm.py
+++ b/subplot/vmadm.py
@@ -119,13 +119,19 @@ def stdout_json_matches(ctx, filename=None):
with open(filename) as f:
expected = json.load(f)
- for key in expected:
- value = expected[key]
- if isinstance(value, str):
- expected[key] = os.path.expanduser(value)
- elif isinstance(value, list) and value and isinstance(value[0], str):
- expected[key] = [os.path.expanduser(item) for item in value]
+ expected = _expand_tilde(expected)
logging.debug(f"actual: {actual}")
logging.debug(f"expect: {expected}")
assert_dict_eq(actual, expected)
+
+
+def _expand_tilde(o):
+ if isinstance(o, str):
+ return os.path.expanduser(o)
+ elif isinstance(o, dict):
+ return {key: _expand_tilde(o[key]) for key in o}
+ elif isinstance(o, list):
+ return [_expand_tilde(value) for value in o]
+ else:
+ return o