File: test_encoding.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 (159 lines) | stat: -rw-r--r-- 8,399 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import pytest

from inline_snapshot._inline_snapshot import snapshot
from inline_snapshot.testing._example import Example


@pytest.mark.parametrize(
    "encoding", ["utf-8", "windows-1251", "cp1252", "latin-1", "ascii"]
)
@pytest.mark.parametrize("newline", ["\n", "\r\n"])
def test_encoding(encoding, newline):

    special = ""
    for c in "aéЯÂþ":
        try:
            c.encode(encoding)
            special += c
        except UnicodeEncodeError:
            pass

    code = f"""\
# -*- coding: {encoding} -*-

from inline_snapshot import snapshot

def test_a():
    assert "{special}"==snapshot()
"""

    fixed_code = code.replace("snapshot()", f'snapshot("{special}")').replace(
        "\n", newline
    )

    if encoding not in ("utf-8", "ascii"):
        fixed_code = fixed_code.encode(encoding)

    Example(code.replace("\n", newline).encode(encoding)).run_inline(
        ["--inline-snapshot=create"],
        changed_files={"tests/test_something.py": fixed_code},
        report=snapshot(
            {
                "utf-8": """\
FAIL: your snapshot is missing one value.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.
FAIL: some snapshots in this test have incorrect values.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.


═══════════════════════════════ inline-snapshot ════════════════════════════════
------------------------------- Create snapshots -------------------------------
+-------------------------- tests/test_something.py ---------------------------+
| @@ -3,4 +3,4 @@                                                              |
|                                                                              |
|  from inline_snapshot import snapshot                                        |
|                                                                              |
|  def test_a():                                                               |
| -    assert "aéЯÂþ"==snapshot()                                              |
| +    assert "aéЯÂþ"==snapshot("aéЯÂþ")                                       |
+------------------------------------------------------------------------------+
These changes will be applied, because you used create

""",
                "windows-1251": """\
FAIL: your snapshot is missing one value.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.
FAIL: some snapshots in this test have incorrect values.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.


═══════════════════════════════ inline-snapshot ════════════════════════════════
------------------------------- Create snapshots -------------------------------
+-------------------------- tests/test_something.py ---------------------------+
| @@ -3,4 +3,4 @@                                                              |
|                                                                              |
|  from inline_snapshot import snapshot                                        |
|                                                                              |
|  def test_a():                                                               |
| -    assert "aЯ"==snapshot()                                                 |
| +    assert "aЯ"==snapshot("aЯ")                                             |
+------------------------------------------------------------------------------+
These changes will be applied, because you used create

""",
                "cp1252": """\
FAIL: your snapshot is missing one value.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.
FAIL: some snapshots in this test have incorrect values.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.


═══════════════════════════════ inline-snapshot ════════════════════════════════
------------------------------- Create snapshots -------------------------------
+-------------------------- tests/test_something.py ---------------------------+
| @@ -3,4 +3,4 @@                                                              |
|                                                                              |
|  from inline_snapshot import snapshot                                        |
|                                                                              |
|  def test_a():                                                               |
| -    assert "aéÂþ"==snapshot()                                               |
| +    assert "aéÂþ"==snapshot("aéÂþ")                                         |
+------------------------------------------------------------------------------+
These changes will be applied, because you used create

""",
                "latin-1": """\
FAIL: your snapshot is missing one value.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.
FAIL: some snapshots in this test have incorrect values.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.


═══════════════════════════════ inline-snapshot ════════════════════════════════
------------------------------- Create snapshots -------------------------------
+-------------------------- tests/test_something.py ---------------------------+
| @@ -3,4 +3,4 @@                                                              |
|                                                                              |
|  from inline_snapshot import snapshot                                        |
|                                                                              |
|  def test_a():                                                               |
| -    assert "aéÂþ"==snapshot()                                               |
| +    assert "aéÂþ"==snapshot("aéÂþ")                                         |
+------------------------------------------------------------------------------+
These changes will be applied, because you used create

""",
                "ascii": """\
FAIL: your snapshot is missing one value.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.
FAIL: some snapshots in this test have incorrect values.
If you just created this value with --inline-snapshot=create, the value is now \n\
created and you can ignore this message.


═══════════════════════════════ inline-snapshot ════════════════════════════════
------------------------------- Create snapshots -------------------------------
+-------------------------- tests/test_something.py ---------------------------+
| @@ -3,4 +3,4 @@                                                              |
|                                                                              |
|  from inline_snapshot import snapshot                                        |
|                                                                              |
|  def test_a():                                                               |
| -    assert "a"==snapshot()                                                  |
| +    assert "a"==snapshot("a")                                               |
+------------------------------------------------------------------------------+
These changes will be applied, because you used create

""",
            }
        )[encoding],
    )