Fixing several tests
Using isinstance instead of comparing classes names Removing unnecessary tuple check, treated by the return value unpacking Adding missing inject code tests Adding qfile.getchar test Fixing QLocale.to* methods fixing __setitem__ in qbytearray
This commit is contained in:
parent
76529055ff
commit
74351882b5
13 changed files with 291 additions and 45 deletions
|
|
@ -10,17 +10,21 @@ from PySide.QtCore import QByteArray
|
|||
class QByteArrayTestToNumber(unittest.TestCase):
|
||||
def testToNumberInt(self):
|
||||
obj = QByteArray('37')
|
||||
self.assertEqual(37, obj.toInt()[0])
|
||||
self.assertEqual((37, True), obj.toInt())
|
||||
|
||||
def testToNumberUShort(self):
|
||||
obj = QByteArray('37')
|
||||
self.assertEqual((37, True), obj.toUShort())
|
||||
|
||||
def testToNumberFloat(self):
|
||||
obj = QByteArray('37.109')
|
||||
self.assertEqual(ctypes.c_float(37.109).value,
|
||||
obj.toFloat()[0])
|
||||
self.assertEqual((ctypes.c_float(37.109).value, True),
|
||||
obj.toFloat())
|
||||
|
||||
def testToNumberDouble(self):
|
||||
obj = QByteArray('37.109')
|
||||
self.assertEqual(ctypes.c_double(37.109).value,
|
||||
obj.toDouble()[0])
|
||||
self.assertEqual((ctypes.c_double(37.109).value, True),
|
||||
obj.toDouble())
|
||||
|
||||
class QByteArraySplit(unittest.TestCase):
|
||||
'''Test case for QByteArray.split'''
|
||||
|
|
@ -38,6 +42,57 @@ class QByteArrayData(unittest.TestCase):
|
|||
url = QByteArray("http://web.openbossa.org/")
|
||||
self.assertEqual(url.data(), "http://web.openbossa.org/")
|
||||
|
||||
class QByteArrayOperatorAtSetter(unittest.TestCase):
|
||||
'''Test case for operator QByteArray[] - __setitem__'''
|
||||
|
||||
def testSetterString(self):
|
||||
'''QByteArray[x] = pythonstring'''
|
||||
obj = QByteArray('123456')
|
||||
obj[1] = '0'
|
||||
self.assertEqual(obj, QByteArray('103456'))
|
||||
|
||||
def testSetterStringLarge(self):
|
||||
'''QByteArray[x] = pythonstring (larget than 1 char)'''
|
||||
obj = QByteArray('123456')
|
||||
obj[3] = 'abba'
|
||||
self.assertEqual(obj, QByteArray('123abba56'))
|
||||
|
||||
def testSetterQByteArray(self):
|
||||
'''QByteArray[x] = qbytearray'''
|
||||
obj = QByteArray('123456')
|
||||
obj[3] = QByteArray('array')
|
||||
self.assertEqual(obj, QByteArray('123array56'))
|
||||
|
||||
|
||||
class QByteArrayOperatorAtSetterNegativeIndex(unittest.TestCase):
|
||||
'''Test case for QByteArray[] - __setitem__ - for negative index'''
|
||||
|
||||
def testSetterNegativeIndex(self):
|
||||
'''QByteArray[x] = string - negative index'''
|
||||
obj = QByteArray('123456')
|
||||
obj[-3] = 'array'
|
||||
self.assertEqual(obj, QByteArray('123array56'))
|
||||
|
||||
|
||||
class QByteArrayOperatorAtSetterLargeIndex(unittest.TestCase):
|
||||
'''Test case for QByteArray[] - __setitem__ - for 'overflown' index'''
|
||||
|
||||
def testSetterLargeIndexEmpty(self):
|
||||
'''QByteArray[x] = somestring - Overflow index on empty string'''
|
||||
# should pad with spaces if the index is larger
|
||||
obj = QByteArray('')
|
||||
obj[2] = 'a'
|
||||
self.assertEqual(obj, QByteArray(' a'))
|
||||
|
||||
def testSetterLargeIndexNormal(self):
|
||||
'''QByteArray[x] = somestring - Overflow index on normal string'''
|
||||
# should pad with spaces if the index is larger
|
||||
obj = QByteArray('mystring')
|
||||
obj[10] = 'normal'
|
||||
self.assertEqual(obj, QByteArray('mystring normal'))
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue