File: test_external_location.py

package info (click to toggle)
python-inline-snapshot 0.31.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,708 kB
  • sloc: python: 9,261; makefile: 39; sh: 32
file content (71 lines) | stat: -rw-r--r-- 2,734 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
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"),
            "hash:a.b.txt": ExternalLocation(storage="hash", stem="a", suffix=".b.txt"),
            "hash:a": "ValueError: 'hash:a' is missing a suffix",
            "hash:.txt": ExternalLocation(storage="hash", stem="", suffix=".txt"),
            "hash:.b.txt": ExternalLocation(storage="hash", stem="", suffix=".b.txt"),
            "hash:": ExternalLocation(storage="hash", stem="", suffix=""),
            "a.txt": ExternalLocation(storage="uuid", stem="a", suffix=".txt"),
            "a.b.txt": ExternalLocation(storage="uuid", stem="a", suffix=".b.txt"),
            "a": "ValueError: 'a' is missing a suffix",
            ".txt": ExternalLocation(storage="uuid", stem="", suffix=".txt"),
            ".b.txt": ExternalLocation(storage="uuid", stem="", suffix=".b.txt"),
            """""": ExternalLocation(storage="uuid", stem="", suffix=""),
            "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,
    )