From 80ec450dc91bb9a3ff993bb25b22f7deeaad49d6 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Wed, 16 Jan 2019 20:55:09 -0800 Subject: [PATCH] Add test for cfg round-trip dump+load --- tests/test_cli.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index d95c011..5f5551e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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)