style: use Black everywhere (#2594)

* style: use Black everywhere

* style: minor touchup from review
This commit is contained in:
Henry Schreiner
2020-10-16 16:38:13 -04:00
committed by GitHub
parent 2e31e466dc
commit c50f90eca6
38 changed files with 1653 additions and 941 deletions

View File

@@ -37,79 +37,85 @@ def test_unicode_conversion():
with pytest.raises(UnicodeDecodeError):
m.bad_utf8_u8string()
assert m.u8_Z() == 'Z'
assert m.u8_eacute() == u'é'
assert m.u16_ibang() == u''
assert m.u32_mathbfA() == u'𝐀'
assert m.wchar_heart() == u''
assert m.u8_Z() == "Z"
assert m.u8_eacute() == u"é"
assert m.u16_ibang() == u""
assert m.u32_mathbfA() == u"𝐀"
assert m.wchar_heart() == u""
if hasattr(m, "has_u8string"):
assert m.u8_char8_Z() == 'Z'
assert m.u8_char8_Z() == "Z"
def test_single_char_arguments():
"""Tests failures for passing invalid inputs to char-accepting functions"""
def toobig_message(r):
return "Character code point not in range({0:#x})".format(r)
toolong_message = "Expected a character, but multi-character string found"
assert m.ord_char(u'a') == 0x61 # simple ASCII
assert m.ord_char_lv(u'b') == 0x62
assert m.ord_char(u'é') == 0xE9 # requires 2 bytes in utf-8, but can be stuffed in a char
assert m.ord_char(u"a") == 0x61 # simple ASCII
assert m.ord_char_lv(u"b") == 0x62
assert (
m.ord_char(u"é") == 0xE9
) # requires 2 bytes in utf-8, but can be stuffed in a char
with pytest.raises(ValueError) as excinfo:
assert m.ord_char(u'Ā') == 0x100 # requires 2 bytes, doesn't fit in a char
assert m.ord_char(u"Ā") == 0x100 # requires 2 bytes, doesn't fit in a char
assert str(excinfo.value) == toobig_message(0x100)
with pytest.raises(ValueError) as excinfo:
assert m.ord_char(u'ab')
assert m.ord_char(u"ab")
assert str(excinfo.value) == toolong_message
assert m.ord_char16(u'a') == 0x61
assert m.ord_char16(u'é') == 0xE9
assert m.ord_char16_lv(u'ê') == 0xEA
assert m.ord_char16(u'Ā') == 0x100
assert m.ord_char16(u'') == 0x203d
assert m.ord_char16(u'') == 0x2665
assert m.ord_char16_lv(u'') == 0x2661
assert m.ord_char16(u"a") == 0x61
assert m.ord_char16(u"é") == 0xE9
assert m.ord_char16_lv(u"ê") == 0xEA
assert m.ord_char16(u"Ā") == 0x100
assert m.ord_char16(u"") == 0x203D
assert m.ord_char16(u"") == 0x2665
assert m.ord_char16_lv(u"") == 0x2661
with pytest.raises(ValueError) as excinfo:
assert m.ord_char16(u'🎂') == 0x1F382 # requires surrogate pair
assert m.ord_char16(u"🎂") == 0x1F382 # requires surrogate pair
assert str(excinfo.value) == toobig_message(0x10000)
with pytest.raises(ValueError) as excinfo:
assert m.ord_char16(u'aa')
assert m.ord_char16(u"aa")
assert str(excinfo.value) == toolong_message
assert m.ord_char32(u'a') == 0x61
assert m.ord_char32(u'é') == 0xE9
assert m.ord_char32(u'Ā') == 0x100
assert m.ord_char32(u'') == 0x203d
assert m.ord_char32(u'') == 0x2665
assert m.ord_char32(u'🎂') == 0x1F382
assert m.ord_char32(u"a") == 0x61
assert m.ord_char32(u"é") == 0xE9
assert m.ord_char32(u"Ā") == 0x100
assert m.ord_char32(u"") == 0x203D
assert m.ord_char32(u"") == 0x2665
assert m.ord_char32(u"🎂") == 0x1F382
with pytest.raises(ValueError) as excinfo:
assert m.ord_char32(u'aa')
assert m.ord_char32(u"aa")
assert str(excinfo.value) == toolong_message
assert m.ord_wchar(u'a') == 0x61
assert m.ord_wchar(u'é') == 0xE9
assert m.ord_wchar(u'Ā') == 0x100
assert m.ord_wchar(u'') == 0x203d
assert m.ord_wchar(u'') == 0x2665
assert m.ord_wchar(u"a") == 0x61
assert m.ord_wchar(u"é") == 0xE9
assert m.ord_wchar(u"Ā") == 0x100
assert m.ord_wchar(u"") == 0x203D
assert m.ord_wchar(u"") == 0x2665
if m.wchar_size == 2:
with pytest.raises(ValueError) as excinfo:
assert m.ord_wchar(u'🎂') == 0x1F382 # requires surrogate pair
assert m.ord_wchar(u"🎂") == 0x1F382 # requires surrogate pair
assert str(excinfo.value) == toobig_message(0x10000)
else:
assert m.ord_wchar(u'🎂') == 0x1F382
assert m.ord_wchar(u"🎂") == 0x1F382
with pytest.raises(ValueError) as excinfo:
assert m.ord_wchar(u'aa')
assert m.ord_wchar(u"aa")
assert str(excinfo.value) == toolong_message
if hasattr(m, "has_u8string"):
assert m.ord_char8(u'a') == 0x61 # simple ASCII
assert m.ord_char8_lv(u'b') == 0x62
assert m.ord_char8(u'é') == 0xE9 # requires 2 bytes in utf-8, but can be stuffed in a char
assert m.ord_char8(u"a") == 0x61 # simple ASCII
assert m.ord_char8_lv(u"b") == 0x62
assert (
m.ord_char8(u"é") == 0xE9
) # requires 2 bytes in utf-8, but can be stuffed in a char
with pytest.raises(ValueError) as excinfo:
assert m.ord_char8(u'Ā') == 0x100 # requires 2 bytes, doesn't fit in a char
assert m.ord_char8(u"Ā") == 0x100 # requires 2 bytes, doesn't fit in a char
assert str(excinfo.value) == toobig_message(0x100)
with pytest.raises(ValueError) as excinfo:
assert m.ord_char8(u'ab')
assert m.ord_char8(u"ab")
assert str(excinfo.value) == toolong_message
@@ -129,19 +135,19 @@ def test_bytes_to_string():
assert m.strlen(to_bytes("a\x00b")) == 1 # C-string limitation
# passing in a utf8 encoded string should work
assert m.string_length(u'💩'.encode("utf8")) == 4
assert m.string_length(u"💩".encode("utf8")) == 4
@pytest.mark.skipif(not hasattr(m, "has_string_view"), reason="no <string_view>")
def test_string_view(capture):
"""Tests support for C++17 string_view arguments and return values"""
assert m.string_view_chars("Hi") == [72, 105]
assert m.string_view_chars("Hi 🎂") == [72, 105, 32, 0xf0, 0x9f, 0x8e, 0x82]
assert m.string_view16_chars(u"Hi 🎂") == [72, 105, 32, 0xd83c, 0xdf82]
assert m.string_view_chars("Hi 🎂") == [72, 105, 32, 0xF0, 0x9F, 0x8E, 0x82]
assert m.string_view16_chars(u"Hi 🎂") == [72, 105, 32, 0xD83C, 0xDF82]
assert m.string_view32_chars(u"Hi 🎂") == [72, 105, 32, 127874]
if hasattr(m, "has_u8string"):
assert m.string_view8_chars("Hi") == [72, 105]
assert m.string_view8_chars(u"Hi 🎂") == [72, 105, 32, 0xf0, 0x9f, 0x8e, 0x82]
assert m.string_view8_chars(u"Hi 🎂") == [72, 105, 32, 0xF0, 0x9F, 0x8E, 0x82]
assert m.string_view_return() == u"utf8 secret 🎂"
assert m.string_view16_return() == u"utf16 secret 🎂"
@@ -154,40 +160,52 @@ def test_string_view(capture):
m.string_view_print("utf8 🎂")
m.string_view16_print(u"utf16 🎂")
m.string_view32_print(u"utf32 🎂")
assert capture == u"""
assert (
capture
== u"""
Hi 2
utf8 🎂 9
utf16 🎂 8
utf32 🎂 7
"""
)
if hasattr(m, "has_u8string"):
with capture:
m.string_view8_print("Hi")
m.string_view8_print(u"utf8 🎂")
assert capture == u"""
assert (
capture
== u"""
Hi 2
utf8 🎂 9
"""
)
with capture:
m.string_view_print("Hi, ascii")
m.string_view_print("Hi, utf8 🎂")
m.string_view16_print(u"Hi, utf16 🎂")
m.string_view32_print(u"Hi, utf32 🎂")
assert capture == u"""
assert (
capture
== u"""
Hi, ascii 9
Hi, utf8 🎂 13
Hi, utf16 🎂 12
Hi, utf32 🎂 11
"""
)
if hasattr(m, "has_u8string"):
with capture:
m.string_view8_print("Hi, ascii")
m.string_view8_print(u"Hi, utf8 🎂")
assert capture == u"""
assert (
capture
== u"""
Hi, ascii 9
Hi, utf8 🎂 13
"""
)
def test_integer_casting():
@@ -199,8 +217,14 @@ def test_integer_casting():
if env.PY2:
assert m.i32_str(long(-1)) == "-1" # noqa: F821 undefined name 'long'
assert m.i64_str(long(-1)) == "-1" # noqa: F821 undefined name 'long'
assert m.i64_str(long(-999999999999)) == "-999999999999" # noqa: F821 undefined name
assert m.u64_str(long(999999999999)) == "999999999999" # noqa: F821 undefined name 'long'
assert (
m.i64_str(long(-999999999999)) # noqa: F821 undefined name 'long'
== "-999999999999"
)
assert (
m.u64_str(long(999999999999)) # noqa: F821 undefined name 'long'
== "999999999999"
)
else:
assert m.i64_str(-999999999999) == "-999999999999"
assert m.u64_str(999999999999) == "999999999999"
@@ -236,16 +260,22 @@ def test_tuple(doc):
assert m.tuple_passthrough([True, "test", 5]) == (5, "test", True)
assert m.empty_tuple() == ()
assert doc(m.pair_passthrough) == """
assert (
doc(m.pair_passthrough)
== """
pair_passthrough(arg0: Tuple[bool, str]) -> Tuple[str, bool]
Return a pair in reversed order
"""
assert doc(m.tuple_passthrough) == """
)
assert (
doc(m.tuple_passthrough)
== """
tuple_passthrough(arg0: Tuple[bool, str, int]) -> Tuple[int, str, bool]
Return a triple in reversed order
"""
)
assert m.rvalue_pair() == ("rvalue", "rvalue")
assert m.lvalue_pair() == ("lvalue", "lvalue")
@@ -372,7 +402,7 @@ def test_numpy_bool():
assert convert(np.bool_(False)) is False
assert noconvert(np.bool_(True)) is True
assert noconvert(np.bool_(False)) is False
cant_convert(np.zeros(2, dtype='int'))
cant_convert(np.zeros(2, dtype="int"))
def test_int_long():
@@ -382,7 +412,8 @@ def test_int_long():
long."""
import sys
must_be_long = type(getattr(sys, 'maxint', 1) + 1)
must_be_long = type(getattr(sys, "maxint", 1) + 1)
assert isinstance(m.int_cast(), int)
assert isinstance(m.long_cast(), int)
assert isinstance(m.longlong_cast(), must_be_long)