kopia lustrzana https://github.com/corrscope/corrscope
Add test for cfg round-trip dump+load
rodzic
b0da03cc47
commit
80ec450dc9
|
@ -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)
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue