Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Lib/test/test_capi/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def test_check(self):
self.assertFalse(check(3))
self.assertFalse(check([]))
self.assertFalse(check(object()))
self.assertTrue(check(b''))

# CRASHES check(NULL)
# CRASHES check(NULL) #PyBytes_Check() expects PyObject*

def test_checkexact(self):
# Test PyBytes_CheckExact()
Expand All @@ -43,8 +44,9 @@ def test_checkexact(self):
self.assertFalse(check(3))
self.assertFalse(check([]))
self.assertFalse(check(object()))
self.assertTrue(check(b''))

# CRASHES check(NULL)
# CRASHES check(NULL) #PyBytes_CheckExact() expects PyObject*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are these comments related? They should probably be on two lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies; that was meant to explain why it crashes (it felt a little vague whether or not it was expected behavior). Would it be better on the next line, or in parenthesis or similar?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain why it crashes

Then it should be on the same line, but without the #, as that makes it seem like 2 different notes.


def test_fromstringandsize(self):
# Test PyBytes_FromStringAndSize()
Expand Down Expand Up @@ -73,7 +75,7 @@ def test_fromstring(self):
self.assertEqual(fromstring(b'abc\0def'), b'abc')
self.assertEqual(fromstring(b''), b'')

# CRASHES fromstring(NULL)
# CRASHES fromstring(NULL)

def test_fromobject(self):
# Test PyBytes_FromObject()
Expand Down Expand Up @@ -108,6 +110,7 @@ def test_asstring(self):

self.assertEqual(asstring(b'abc', 4), b'abc\0')
self.assertEqual(asstring(b'abc\0def', 8), b'abc\0def\0')
self.assertEqual(asstring(b'', 1), b'\0')
self.assertRaises(TypeError, asstring, 'abc', 0)
self.assertRaises(TypeError, asstring, object(), 0)

Expand All @@ -120,6 +123,7 @@ def test_asstringandsize(self):

self.assertEqual(asstringandsize(b'abc', 4), (b'abc\0', 3))
self.assertEqual(asstringandsize(b'abc\0def', 8), (b'abc\0def\0', 7))
self.assertEqual(asstringandsize(b'', 1), (b'\0', 0))
self.assertEqual(asstringandsize_null(b'abc', 4), b'abc\0')
self.assertRaises(ValueError, asstringandsize_null, b'abc\0def', 8)
self.assertRaises(TypeError, asstringandsize, 'abc', 0)
Expand Down Expand Up @@ -163,6 +167,7 @@ def test_concat(self, concat=None):
self.assertEqual(concat(b'', bytearray(b'def')), b'def')
self.assertEqual(concat(memoryview(b'xabcy')[1:4], b'def'), b'abcdef')
self.assertEqual(concat(b'abc', memoryview(b'xdefy')[1:4]), b'abcdef')
self.assertEqual(concat(b'', b''), b'')

self.assertEqual(concat(b'abc', b'def', True), b'abcdef')
self.assertEqual(concat(b'abc', bytearray(b'def'), True), b'abcdef')
Expand Down
Loading