File: test_external_location.py

package info (click to toggle)
python-inline-snapshot 0.29.0-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,400 kB
  • sloc: python: 8,877; makefile: 37; sh: 30
file content (91 lines) | stat: -rw-r--r-- 3,334 bytes parent folder | download | duplicates (3)
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
81
82
83
84
85
86
87
88
89
90
91
from inline_snapshot._external._external_location import ExternalLocation
from inline_snapshot._inline_snapshot import snapshot
from inline_snapshot.testing._example import Example


def test_external_location():

    results = snapshot(
        {
            "hash:a.txt": ExternalLocation(
                storage="hash", stem="a", suffix=".txt", filename=None, qualname=None
            ),
            "hash:a.b.txt": ExternalLocation(
                storage="hash", stem="a", suffix=".b.txt", filename=None, qualname=None
            ),
            "hash:a": "ValueError: 'hash:a' is missing a suffix",
            "hash:.txt": ExternalLocation(
                storage="hash", stem="", suffix=".txt", filename=None, qualname=None
            ),
            "hash:.b.txt": ExternalLocation(
                storage="hash", stem="", suffix=".b.txt", filename=None, qualname=None
            ),
            "hash:": ExternalLocation(
                storage="hash", stem="", suffix="", filename=None, qualname=None
            ),
            "a.txt": ExternalLocation(
                storage="uuid", stem="a", suffix=".txt", filename=None, qualname=None
            ),
            "a.b.txt": ExternalLocation(
                storage="uuid", stem="a", suffix=".b.txt", filename=None, qualname=None
            ),
            "a": "ValueError: 'a' is missing a suffix",
            ".txt": ExternalLocation(
                storage="uuid", stem="", suffix=".txt", filename=None, qualname=None
            ),
            ".b.txt": ExternalLocation(
                storage="uuid", stem="", suffix=".b.txt", filename=None, qualname=None
            ),
            """""": ExternalLocation(
                storage="uuid", stem="", suffix="", filename=None, qualname=None
            ),
            "invalid:a.txt": "ValueError: storage has to be hash or uuid",
            "invalid:a.b.txt": "ValueError: storage has to be hash or uuid",
            "invalid:a": "ValueError: storage has to be hash or uuid",
            "invalid:.txt": "ValueError: storage has to be hash or uuid",
            "invalid:.b.txt": "ValueError: storage has to be hash or uuid",
            "invalid:": "ValueError: storage has to be hash or uuid",
        }
    )

    for h in ("hash:", "invalid:", ""):
        for n in ("a", ""):
            for s in (".txt", ".b.txt", ""):
                name = h + n + s
                try:
                    assert ExternalLocation.from_name(name) == results[name]
                except Exception as e:
                    assert results[name] == f"{type(e).__name__}: {e}"


def test_missing_suffix():
    Example(
        """
from inline_snapshot import external

def test_a():
    if False:
        assert "a" == external("a")
    else:
        assert "a" == external(".txt")
    """
    ).run_pytest(
        ["--inline-snapshot=create"],
        changed_files=snapshot(
            {
                "tests/__inline_snapshot__/test_something/test_a/e3e70682-c209-4cac-a29f-6fbed82c07cd.txt": "a",
                "tests/test_something.py": """\

from inline_snapshot import external

def test_a():
    if False:
        assert "a" == external("a")
    else:
        assert "a" == external("uuid:e3e70682-c209-4cac-a29f-6fbed82c07cd.txt")
    \
""",
            }
        ),
        returncode=1,
    )