Skip to content

Commit 3a5dfc3

Browse files
JayBazuzi4dsherwoodblade290GRWroboticssusanfung
committed
- B fix inline approvals with special unicode characters
fixes #216 Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com> Co-Authored-By: Joss Hufnagel <43077216+blade290@users.noreply.github.com> Co-Authored-By: Glen Warren <45516388+GRWrobotics@users.noreply.github.com> Co-Authored-By: Susan Fung <38925660+susanfung@users.noreply.github.com>
1 parent d9372ef commit 3a5dfc3

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

approvaltests/namer/inline_python_reporter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def get_test_source_file(self) -> str:
6060
return test_stack_frame.filename
6161

6262
def create_received_file(self, received_path: str, test_source_file: str) -> str:
63-
code = Path(test_source_file).read_text()
63+
code = Path(test_source_file).read_text(encoding="utf-8")
6464

65-
original_received_text = Path(received_path).read_text()[:-1]
65+
original_received_text = Path(received_path).read_text(encoding="utf-8")[:-1]
6666
received_text = original_received_text + self.footer
6767
# Handle preceding whitespace consistently across all lines.
6868
received_text = handle_preceeding_whitespace(received_text)
@@ -78,7 +78,7 @@ def create_received_file(self, received_path: str, test_source_file: str) -> str
7878
received_text, code, method_name, after_docstring_comment=trailing_comment
7979
)
8080
file = tempfile.NamedTemporaryFile(suffix=".received.txt", delete=False).name
81-
Path(file).write_text(new_code)
81+
Path(file).write_text(new_code, encoding="utf-8")
8282
return file
8383

8484
def swap(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/test_inline_approvals.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,25 @@ def test_escape_backslashes_mixed_sequences() -> None:
263263
assert escape_backslashes(text) == "a\\b\\c\\n".replace("\\", "\\\\")
264264

265265

266-
def test_unicode_and_special_characters_combining_acute() -> None:
266+
def test_unicode_and_special_characters__mismatch() -> None:
267+
# TODO: consider inspecting the exception
267268
"""
268-
e\u0301
269+
269270
"""
271+
text = "xe\u0301" # 'e' + COMBINING ACUTE (2 code points)
272+
with pytest.raises(ApprovalException):
273+
verify(text, options=Options().with_reporter(ReportQuietly()).inline())
274+
275+
276+
def test_unicode_and_special_characters__missing() -> None:
270277
text = "e\u0301" # 'e' + COMBINING ACUTE (2 code points)
271-
verify(text, options=Options().inline())
278+
with pytest.raises(ApprovalException):
279+
verify(text, options=Options().with_reporter(ReportQuietly()).inline())
280+
281+
282+
def test_unicode_and_special_characters__not_inline() -> None:
283+
text = "e\u0301" # 'e' + COMBINING ACUTE (2 code points)
284+
verify(text)
272285

273286

274287
def test_unicode_null_character() -> None:

0 commit comments

Comments
 (0)