aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorBoxiang Sun <daetalusun@gmail.com>2018-04-28 10:29:30 +0800
committerBoxiang Sun <daetalusun@gmail.com>2018-04-30 11:09:09 +0000
commitaadfb8afc9d7f9ae00bdb53b72e39ff0b2bebe6d (patch)
tree10efa772dd6d4814279b97c9f0dc3349fd9a9fcb /sources/pyside2/tests
parenta245785dd9d0f1088aa95ca8890eaeab4bdc1432 (diff)
Implement Python slicing support for QByteArray
PySide2 for Python 3 didn't support get item by slice, e.g. ``` >>> from PySide2.QtCore import QByteArray >>> ba = QByteArray('1234567890') >>> ba[2:4] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sequence index must be integer, not 'slice' ``` This is because get item by slice is supported by mp_subscript. But current PySide2 doesn't implemented it. So I added __mgetitem__ in QByteArray. And we also need to keep __getitem__ to support iterate over QByteArray. Also removed the __getslice__ from QByteArray. Task-number: PYSIDE-567 Change-Id: I01f79cc2ab8700da92155cfad96be2e98bb8b331 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtCore/qbytearray_test.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/sources/pyside2/tests/QtCore/qbytearray_test.py b/sources/pyside2/tests/QtCore/qbytearray_test.py
index c6008cf1..0be972c0 100644
--- a/sources/pyside2/tests/QtCore/qbytearray_test.py
+++ b/sources/pyside2/tests/QtCore/qbytearray_test.py
@@ -152,15 +152,20 @@ class QByteArrayOnQVariant(unittest.TestCase):
a = QSettings().value("some_prop", QByteArray())
self.assertEqual(type(a), QByteArray)
-class TestBug666(unittest.TestCase):
- '''QByteArray does not support slices'''
+class TestBug567(unittest.TestCase):
+ '''
+ QByteArray should support slices
+ '''
def testIt(self):
- if not py3k.IS_PY3K:
- ba = QByteArray('1234567890')
- self.assertEqual(ba[2:4], '34')
- self.assertEqual(ba[:4], '1234')
- self.assertEqual(ba[4:], '567890')
- self.assertEqual(len(ba[4:1]), 0)
+ ba = QByteArray('1234567890')
+ self.assertEqual(ba[2:4], '34')
+ self.assertEqual(ba[:4], '1234')
+ self.assertEqual(ba[4:], '567890')
+ self.assertEqual(len(ba[4:1]), 0)
+ self.assertEqual(ba[::-1], '0987654321')
+ self.assertEqual(ba[::2], '13579')
+ self.assertEqual(ba[::-2], '08642')
+ self.assertEqual(ba[2:8:3], '36')
class QByteArrayBug514(unittest.TestCase):
def testIt(self):