clan-config: fix tests

This commit is contained in:
DavHau
2023-08-22 23:15:34 +02:00
parent 48686591d8
commit 780fd881c3
4 changed files with 43 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
import argparse
import json
import sys
import tempfile
from pathlib import Path
from typing import Any
@@ -32,15 +33,20 @@ def test_set_some_option(
monkeypatch: pytest.MonkeyPatch,
) -> None:
# monkeypatch sys.argv
monkeypatch.setattr(sys, "argv", [""] + argv)
parser = argparse.ArgumentParser()
config.register_parser(parser=parser, optionsFile=Path(example_options))
args = parser.parse_args()
args.func(args)
captured = capsys.readouterr()
print(captured.out)
json_out = json.loads(captured.out)
assert json_out == expected
# create temporary file for out_file
with tempfile.NamedTemporaryFile() as out_file:
with open(out_file.name, "w") as f:
json.dump({}, f)
monkeypatch.setattr(sys, "argv", ["", "--out-file", out_file.name] + argv)
parser = argparse.ArgumentParser()
config._register_parser(
parser=parser,
options=json.loads(Path(example_options).read_text()),
)
args = parser.parse_args()
args.func(args)
json_out = json.loads(open(out_file.name).read())
assert json_out == expected
def test_walk_jsonschema_all_types() -> None: