File: conftest.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 (36 lines) | stat: -rw-r--r-- 833 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
32
33
34
35
36
from __future__ import annotations

from textwrap import dedent

import pytest
from click.testing import CliRunner

import vdirsyncer.cli as cli


class _CustomRunner:
    def __init__(self, tmpdir):
        self.tmpdir = tmpdir
        self.cfg = tmpdir.join("config")
        self.runner = CliRunner()

    def invoke(self, args, env=None, **kwargs):
        env = env or {}
        env.setdefault("VDIRSYNCER_CONFIG", str(self.cfg))
        return self.runner.invoke(cli.app, args, env=env, **kwargs)

    def write_with_general(self, data):
        self.cfg.write(
            dedent(
                """
        [general]
        status_path = "{}/status/"
        """
            ).format(str(self.tmpdir))
        )
        self.cfg.write(data, mode="a")


@pytest.fixture
def runner(tmpdir):
    return _CustomRunner(tmpdir)