FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131357: Add tests for zero-sized bytes objects in test_bytes.py by abstractedfox · Pull Request #134234 · python/cpython · GitHub

Repository navigation

Next Next commit
Add tests for zero-sized bytes objects in test_bytes.py
  • Loading branch information
abstractedfox committed May 19, 2025
commit 0bdb82d45662bdfecfab410483d5bb4026dee418
11 changes: 8 additions & 3 deletions Lib/test/test_capi/test_bytes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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''))
Comment thread
vstinner marked this conversation as resolved.
Resolved

# 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''))
Comment thread
vstinner marked this conversation as resolved.
Resolved

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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)
Comment thread
abstractedfox marked this conversation as resolved.
Resolved

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

Back | FazBrowse Home | New Git URL