Skip to content

Commit bd6fe9f

Browse files
committed
Add test for bytes.__init__ with encoding keyword
1 parent dad3015 commit bd6fe9f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_bytes.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -693,35 +693,38 @@ def test_add_mv_to_bytearray():
693693
mv = memoryview(b'world')
694694
ba += mv
695695
assert ba == b'hello world'
696-
696+
697697
def test_bytearray_init():
698698
ba = bytearray(b'abc')
699699
assert_raises(TypeError, bytearray.__init__, ba, encoding='latin1')
700700
assert_raises(TypeError, bytearray.__init__, ba, errors='replace', encoding='latin1')
701701
assert_raises(TypeError, bytearray.__init__, ba, errors='replace')
702-
702+
703703
bytearray.__init__(ba, b'xxx')
704704
assert ba == bytearray(b'xxx')
705705
bytearray.__init__(ba, 'zzz', encoding='latin1')
706706
assert ba == bytearray(b'zzz')
707707
bytearray.__init__(ba, 1)
708708
assert ba == bytearray(b'\x00')
709-
709+
710710
def test_bytes_init():
711711
ba = bytes(b'abc')
712-
712+
713713
bytes.__init__(ba, b'zzz')
714714
assert ba == bytes(b'abc')
715-
715+
716+
ba = bytes('abc', encoding='utf-8')
717+
assert ba == b'abc'
718+
716719
def test_bytes_mod():
717720
assert b'%s' % (b'a') == b'a'
718721
raised = False
719722
try:
720-
b'%s' % (b'a', b'b')
723+
b'%s' % (b'a', b'b')
721724
except TypeError:
722725
raised = True
723726
assert raised
724-
727+
725728
def test__bytes__():
726729
class C: pass
727730
setattr(C, "__bytes__", bytes)
@@ -731,14 +734,14 @@ class C(int): pass
731734
setattr(C, "__bytes__", bytes)
732735
assert bytes(C()) == b''
733736
assert bytes(C(1)) == b''
734-
737+
735738
setattr(C, "__bytes__", complex)
736739
raised = False
737740
try:
738741
bytes(C(1))
739742
except(TypeError):
740743
raised = True
741-
assert raised
744+
assert raised
742745

743746
def b(o):
744747
return b'abc'
@@ -749,7 +752,7 @@ class BA(bytearray): pass
749752

750753
class BAA(BA): pass
751754
assert bytes(BAA(b'cde')) == b'abc'
752-
755+
753756
class BaseLikeBytes:
754757

755758
def test_maketrans(self):
@@ -792,7 +795,7 @@ def test_translate(self):
792795
self.assertEqual(c, b'hee')
793796
c = b.translate(None, delete=b'e')
794797
self.assertEqual(c, b'hllo')
795-
798+
796799
t = bytearray(range(256))
797800
self.assertEqual(b'\xff'.translate(t), b'\xff')
798801
self.assertEqual(b'\xff'.translate(t, t), b'')

0 commit comments

Comments
 (0)