File: conftest.py

package info (click to toggle)
prometheus-fastapi-instrumentator 7.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 492 kB
  • sloc: python: 2,586; makefile: 5
file content (80 lines) | stat: -rw-r--r-- 1,976 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import pathlib
import shutil
from typing import Optional

import pytest


class Helpers:
    """Contains (possibly) useful random utilities

    Combined with the fixture that returns this class it is easy to share
    common functions across multiple tests. Simply use `helpers` as a parameter
    for the respective test function.

    Helpers should be static methods generally.
    """

    separator = "-" * 80
    should_debug = True

    @staticmethod
    def wrapped_debug(element, description: Optional[str] = None) -> None:
        """Calls devtools `debug` and adds horizontal lines and description.

        Args:
            element: Whatever that should be printed by devtools `debug`.
            description (Optional[str], optional): Description. Defaults to None.
        """

        if Helpers.should_debug:
            print(f"\n{Helpers.separator}\n")
            if description:
                print(f"{description}\n")
            print(f"\n{Helpers.separator}\n")


@pytest.fixture
def helpers():
    """Fixture that returns `Helpers` class.

    Returns:
        Helpers: Helpers class.
    """

    return Helpers


FILE = __file__


@pytest.fixture
def data_path(tmp_path: pathlib.Path):
    """Fixture that returns a temporary path with data.

    If the directory `data` exists, its content will be copied to a temporary
    location.

    Args:
        tmp_path (pathlib.Path): Path to temporary location.

    Returns:
        pathlib.Path: Path to temporary location.
    """

    source = pathlib.Path(FILE).parent.joinpath("data")
    destination = tmp_path

    if source.is_dir():
        for item in os.listdir(source):
            s = os.path.join(source, item)
            print(s)
            d = os.path.join(destination, item)
            print(d)
            if os.path.isdir(s):
                shutil.copytree(s, d, symlinks=False, ignore=None)
            else:
                shutil.copy2(s, d)

    return tmp_path