Skip to content

Commit

Permalink
tests: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Sep 10, 2016
1 parent 3ffba27 commit db69a2f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import contextlib
import ctypes
import shutil
import codecs

import pytest

Expand All @@ -31,7 +32,7 @@
del_windows_env_var
from senf._winansi import ansi_parse, ansi_split
from senf._stdlib import _get_userdir
from senf._fsnative import _encoding, is_unix, _surrogatepass
from senf._fsnative import _encoding, is_unix, _surrogatepass, _get_encoding
from senf._print import _encode_codepage, _decode_codepage
from senf import _winapi as winapi

Expand Down Expand Up @@ -118,6 +119,15 @@ def capture_output(data=None):
sys.stdout = old_out


def test__get_encoding():
orig = sys.getfilesystemencoding
sys.getfilesystemencoding = lambda: None
try:
codecs.lookup(_get_encoding())
finally:
sys.getfilesystemencoding = orig


def test_getuserdir():
userdir = _get_userdir()
assert isinstance(userdir, fsnative)
Expand Down Expand Up @@ -482,6 +492,14 @@ def test_surrogates():
assert bytes2fsn(b"=\xd8=\xd8", "utf-16-le") == u"\ud83d\ud83d"
assert bytes2fsn(b"=\xd8\x00\x00", "utf-16-le") == u"\ud83d\x00"

# 4 byte code point
assert fsn2bytes(u"\U0001f600", "utf-16-le") == b"=\xd8\x00\xde"
assert bytes2fsn(b"=\xd8\x00\xde", "utf-16-le") == u"\U0001f600"

# 4 byte codepoint + lone surrogate
assert bytes2fsn(b"=\xd8\x00\xde=\xd8", "utf-16-le") == \
u"\U0001f600\ud83d"

with pytest.raises(UnicodeDecodeError):
bytes2fsn(b"a", "utf-16-le")

Expand Down

0 comments on commit db69a2f

Please sign in to comment.