summaryrefslogtreecommitdiff
path: root/subplot/data.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-04 11:07:09 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-04 11:07:31 +0200
commitad48a051596f6b9748340b7ea5b30659e2692684 (patch)
tree0820209b255f83bae4132d30df067161e04ec899 /subplot/data.py
parent22202d176259d962abdbfdefef1e6213408df06c (diff)
downloadobnam2-ad48a051596f6b9748340b7ea5b30659e2692684.tar.gz
test: add scenario test for obnam config subcommand
Diffstat (limited to 'subplot/data.py')
-rw-r--r--subplot/data.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/subplot/data.py b/subplot/data.py
index a24cd0c..2a54037 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -1,6 +1,8 @@
+import json
import logging
import os
import random
+import yaml
def create_file_with_random_data(ctx, filename=None):
@@ -57,3 +59,30 @@ def files_match(ctx, first=None, second=None):
logging.debug(f"files_match: f:\n{f}")
logging.debug(f"files_match: s:\n{s}")
assert_eq(f, s)
+
+
+def convert_yaml_to_json(ctx, yaml_name=None, json_name=None):
+ with open(yaml_name) as f:
+ obj = yaml.safe_load(f)
+ with open(json_name, "w") as f:
+ json.dump(obj, f)
+
+
+def match_stdout_to_json_file(ctx, filename=None):
+ runcmd_get_stdout = globals()["runcmd_get_stdout"]
+ assert_eq = globals()["assert_eq"]
+
+ stdout = runcmd_get_stdout(ctx)
+ stdout = json.loads(stdout.strip())
+ obj = json.load(open(filename))
+ logging.debug(f"match_stdout_to_json_file: stdout={stdout!r}")
+ logging.debug(f"match_stdout_to_json_file: file={obj!r}")
+
+ for key in obj:
+ if key not in stdout:
+ logging.error(f"{key} not in stdout")
+ assert key in stdout
+
+ if stdout[key] != obj[key]:
+ logging.error(f"stdout value for key is not what was exptected")
+ assert_eq(stdout[key], obj[key])