File: conftest.py

package info (click to toggle)
python-watchgod 0.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 220 kB
  • sloc: python: 1,040; makefile: 55
file content (49 lines) | stat: -rw-r--r-- 1,258 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
from pathlib import Path
from typing import Dict, Union

import pytest

PathDict = Dict[str, Union['PathDict', str, bytes]]


def mktree(root_dir: Path, path_dict: PathDict):
    """
    Create a tree of files from a dictionary of name > content lookups.
    """
    for name, content in path_dict.items():
        path = root_dir / name

        if isinstance(content, dict):
            path.mkdir(parents=True, exist_ok=True)
            mktree(path, content)
        elif isinstance(content, str):
            path.write_text(content)
        else:
            assert isinstance(content, bytes), 'content must be a dict, str or bytes'
            path.write_bytes(content)


@pytest.fixture
def tmp_work_path(tmp_path: Path):
    """
    Create a temporary working directory.
    """
    previous_cwd = Path.cwd()
    os.chdir(tmp_path)

    yield tmp_path

    os.chdir(previous_cwd)


@pytest.fixture(
    params=[
        pytest.param(('asyncio', {'use_uvloop': True}), id='asyncio+uvloop'),
        pytest.param(('asyncio', {'use_uvloop': False}), id='asyncio'),
        pytest.param(('trio', {'restrict_keyboard_interrupt_to_checkpoints': True}), id='trio'),
    ],
    autouse=True,
)
def anyio_backend(request):
    return request.param