File size: 2,041 Bytes
be73e94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os, sys
import pytest

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
sys.path.insert(0, os.path.join(HERE, ".."))
sys.path.insert(0, os.path.join(HERE, "..", "pipeline"))

from helpers import build_dataset  # noqa: E402

DEMO_V1 = {
    "demo/__init__.py": (
        "from .frame import Frame, read\n"
        "from . import util\n"
        "def old_helper(x): pass\n"
        "def connect(host, port=80, timeout=None): pass\n"
    ),
    "demo/frame.py": (
        "class Frame:\n"
        "    def __init__(self, data=None, copy=False): pass\n"
        "    def append(self, other, ignore_index=False): pass\n"
        "    def to_csv(self, path, line_terminator='\\n'): pass\n"
        "def read(path, error_bad_lines=True, sep=','): pass\n"
    ),
    "demo/util.py": "def tool(a, b=1): pass\n",
}
DEMO_V2 = {
    "demo/__init__.py": (
        "import warnings\n"
        "from .frame import Frame, read\n"
        "from . import util\n"
        "def connect(host, port=80, *, timeout=None): pass\n"
        "def legacy():\n    warnings.warn('legacy is deprecated', DeprecationWarning)\n"
        "def brand_new(): pass\n"
    ),
    "demo/frame.py": (
        "class Frame:\n"
        "    def __init__(self, data=None, copy=False): pass\n"
        "    def to_csv(self, path, lineterminator='\\n'): pass\n"
        "    def concat(self, other): pass\n"
        "def read(path, on_bad_lines='error', sep=','): pass\n"
    ),
    "demo/util.py": "def tool(a, b=1): pass\n",
}


@pytest.fixture(scope="session")
def data_dir(tmp_path_factory):
    d = tmp_path_factory.mktemp("data")
    v15 = dict(DEMO_V1)
    v15["demo/__init__.py"] = DEMO_V1["demo/__init__.py"] + (
        "import warnings\ndef legacy():\n    warnings.warn('legacy is deprecated', DeprecationWarning)\n")
    return build_dataset(str(d), {"demo-lib": [("1.0.0", DEMO_V1), ("1.5.0", v15), ("2.0.0", DEMO_V2)]})


@pytest.fixture(scope="session")
def store(data_dir):
    from apidrift.check import Store
    return Store(data_dir)