File: test_utils.py

package info (click to toggle)
vdirsyncer 0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 944 kB
  • sloc: python: 7,380; makefile: 205; sh: 66
file content (31 lines) | stat: -rw-r--r-- 964 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations

import pytest

from vdirsyncer import exceptions
from vdirsyncer.cli.utils import handle_cli_error
from vdirsyncer.cli.utils import storage_instance_from_config
from vdirsyncer.cli.utils import storage_names


def test_handle_cli_error(capsys):
    try:
        raise exceptions.InvalidResponse("ayy lmao")
    except BaseException:
        handle_cli_error()

    out, err = capsys.readouterr()
    assert "returned something vdirsyncer doesn't understand" in err
    assert "ayy lmao" in err


@pytest.mark.asyncio
async def test_storage_instance_from_config(monkeypatch, aio_connector):
    class Dummy:
        def __init__(self, **kw):
            assert kw == {"foo": "bar", "baz": 1}

    monkeypatch.setitem(storage_names._storages, "lol", Dummy)
    config = {"type": "lol", "foo": "bar", "baz": 1}
    storage = await storage_instance_from_config(config, connector=aio_connector)
    assert isinstance(storage, Dummy)