Add test for cfg round-trip dump+load

pull/357/head
nyanpasu64 2019-01-16 20:55:09 -08:00
rodzic b0da03cc47
commit 80ec450dc9
1 zmienionych plików z 14 dodań i 8 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ import shlex
from os.path import abspath
from pathlib import Path
from typing import TYPE_CHECKING, Callable
from unittest import mock
import click
import pytest
@ -32,17 +33,22 @@ def call_main(argv):
# corrscope configuration sinks
def yaml_sink(mocker: "pytest_mock.MockFixture", command: str):
""" Mocks yaml.dump() and returns call args. Does not test dumping to string. """
dump = mocker.patch.object(yaml, "dump")
def yaml_sink(_mocker, command: str):
""" Mocks yaml.dump() and returns call args. Also tests dumping and loading. """
with mock.patch.object(yaml, "dump") as dump:
argv = shlex.split(command) + ["-w"]
call_main(argv)
argv = shlex.split(command) + ["-w"]
call_main(argv)
dump.assert_called_once()
(cfg, stream), kwargs = dump.call_args
dump.assert_called_once()
(cfg, stream), kwargs = dump.call_args
assert isinstance(cfg, Config)
yaml_dump = yaml.dump(cfg)
cfg_round_trip = yaml.load(yaml_dump)
assert cfg_round_trip == cfg, yaml_dump
assert isinstance(cfg, Config)
return (cfg, stream)