def testTypeSystemVariableReplacementInFunctionModification(self):
     ba = ByteArray('12345')
     self.assertEqual(self.mods.getSize(ba), len(ba))
     self.assertEqual(self.mods.getSize(ba, 20), 20)
 def testNullStrings(self):
     ba = ByteArray('\x00')
     self.assertEqual(ba.at(0), '\x00')
     self.assertEqual(ba[0], b('\x00'))
 def testInRange(self):
     # ByteArray[x] where x is a valid index.
     string = 'abcdefgh'
     obj = ByteArray(string)
     for i in range(len(string)):
         self.assertEqual(obj[i], b(string[i]))
 def testInRangeReverse(self):
     # ByteArray[x] where x is a valid index (reverse order).
     string = 'abcdefgh'
     obj = ByteArray(string)
     for i in range(len(string) - 1, 0, -1):
         self.assertEqual(obj[i], b(string[i]))
 def testPyString(self):
     # ByteArray(string) == string
     string = 'my test string'
     self.assertEqual(ByteArray(string), string)
 def testQString(self):
     # ByteArray(string) == string
     string = 'another test string'
     self.assertEqual(ByteArray(string), string)
 def testDefault(self):
     # ByteArray() == ByteArray()
     obj1 = ByteArray()
     obj2 = ByteArray()
     self.assertEqual(obj1, obj2)
 def testSimple(self):
     # ByteArray(some_string) == ByteArray(some_string)
     string = 'egg snakes'
     self.assertEqual(ByteArray(string), ByteArray(string))
 def testConcatByteArrayAndPythonString(self):
     # Test concatenation of a ByteArray with a Python string, in this order.
     ba = ByteArray('foo')
     result = ba + '\x00bar'
     self.assertEqual(type(result), ByteArray)
     self.assertEqual(result, 'foo\x00bar')
 def testByteArrayBufferProtocol(self):
     # Tests ByteArray implementation of Python buffer protocol using the os.path.isdir
     # function which an unicode object or other object implementing the Python buffer protocol.
     isdir(str(ByteArray('/tmp')))
 def testStrOperator(self):
     '''ByteArray __str__'''
     self.assertEqual(ByteArray().__str__(), '')
     self.assertEqual(ByteArray('').__str__(), '')
     self.assertEqual(ByteArray('aaa').__str__(), 'aaa')
 def testBasic(self):
     '''ByteArray __len__'''
     self.assertEqual(len(ByteArray()), 0)
     self.assertEqual(len(ByteArray('')), 0)
     self.assertEqual(len(ByteArray(' ')), 1)
     self.assertEqual(len(ByteArray('yabadaba')), 8)
 def testOutOfRange(self):
     # ByteArray[x] where x is out of index.
     string = '1234567'
     obj = ByteArray(string)
     self.assertRaises(IndexError, lambda: obj[len(string)])