def testIt(self): w = QGLWidget() w.makeCurrent() b = QGLBuffer() b.setUsagePattern(QGLBuffer.DynamicDraw) self.assertTrue(b.create()) self.assertTrue(b.bufferId() != 0) self.assertTrue(b.bind()) data = QByteArray(py3k.b("12345")) b.allocate(data) self.assertEqual(b.size(), data.size()) m = b.map(QGLBuffer.ReadOnly) if m: self.assertEqual(m, py3k.buffer(py3k.b(data.data()))) b.unmap() m = b.map(QGLBuffer.ReadWrite) m[3] = py3k.b('A')[0] b.unmap() result, rdata = b.read(3, 1) self.assertTrue(result) self.assertEqual(py3k.b('A'), rdata.data()) else: print(" memory mapping is not possible in this OpenGL implementation.") b.release()
def testIt(self): w = QGLWidget() w.makeCurrent() b = QGLBuffer() b.setUsagePattern(QGLBuffer.DynamicDraw) self.assertTrue(b.create()) self.assertTrue(b.bufferId() != 0) self.assertTrue(b.bind()) data = QByteArray("12345") b.allocate(data) self.assertEqual(b.size(), data.size()) m = b.map(QGLBuffer.ReadOnly) if m: self.assertEqual(m, py3k.buffer(py3k.b(data.data()))) b.unmap() m = b.map(QGLBuffer.ReadWrite) m[3] = py3k.b('A') b.unmap() result, rdata = b.read(3, 1) self.assertTrue(result) self.assertEqual(py3k.b('A'), rdata.data()) else: print(" memory mapping is not possible in this OpenGL implementation.") b.release()
def testInRangeReverse(self): #QByteArray[x] where x is a valid index (reverse order) string = 'abcdefgh' obj = QByteArray(py3k.b(string)) for i in range(len(string) - 1, 0, -1): self.assertEqual(obj[i], py3k.b(string[i]))
def testInRange(self): #QByteArray[x] where x is a valid index string = 'abcdefgh' obj = QByteArray(py3k.b(string)) for i in range(len(string)): self.assertEqual(obj[i], py3k.b(string[i]))
def testConcatPythonStringAndQByteArray(self): #Test concatenation of a Python bytes with a QByteArray, in this order concat_python_string_add_qbytearray_worked = True qba = QByteArray(py3k.b('foo')) result = py3k.b('bar\x00') + qba self.assertEqual(type(result), QByteArray) self.assertEqual(result, py3k.b('bar\x00foo'))
def testQByteArrayValid(self): '''QDataStream <<>> QByteArray - valid''' self.stream << QByteArray(py3k.b("hello")) res = QByteArray() self.read_stream >> res self.assertEqual(res, QByteArray(py3k.b("hello")))
def testIt(self): ba = QByteArray(py3k.b("32\"1\x00123")) self.assertEqual(str(ba), str(py3k.b("32\"1\x00123"))) if py3k.IS_PY3K: self.assertEqual(repr(ba), "PySide2.QtCore.QByteArray(b'32\"1\\x00123')") else: self.assertEqual(repr(ba), "PySide2.QtCore.QByteArray('32\"1\\x00123')")
def requestStarted(self, request): if request.requestUrl() == "testpy:hello": request.redirect("testpy:goodbye") return self.buffer = QBuffer() self.buffer.setData(py3k.b("Really nice goodbye text.")) self.buffer.aboutToClose.connect(self.buffer.deleteLater) request.reply(py3k.b("text/plain;charset=utf-8"), self.buffer)
def setUp(self): '''Acquire resources''' self.filename1 = FileChild1() self.assertTrue(self.filename1.open()) self.filename1.write(py3k.b('Test text for testing')) self.filename2 = FileChild2() self.assertTrue(self.filename2.open()) self.filename2.write(py3k.b('Test text for testing'))
def testIndexAssignment(self): a = QByteArray(py3k.b('abc')) a[0] = py3k.b('x') self.assertEqual(a[0], py3k.b('x')) def test_1(): a[0] = py3k.b('xy') self.assertRaises(ValueError, test_1)
def testQByteArrayEmpty(self): '''QDataStream <<>> QByteArray - empty''' self.stream << QByteArray(py3k.b("")) res = QByteArray() self.read_stream >> res self.assertEqual(res, QByteArray(py3k.b(""))) self.assertTrue(res.isEmpty()) self.assertFalse(res.isNull())
def testRawData(self): data = QDataStream() self.assertEqual(data.readRawData(4), None) ba = QByteArray() data = QDataStream(ba, QIODevice.WriteOnly) data.writeRawData('AB\x00C') self.assertEqual(ba.data(), py3k.b('AB\x00C')) data = QDataStream(ba) self.assertEqual(data.readRawData(4), py3k.b('AB\x00C'))
def testIt(self): # creates a temporary file handle, self.filename = tempfile.mkstemp() os.write(handle, py3k.b('a')) os.close(handle) engine = QAbstractFileEngine.create(self.filename) engine.open(QIODevice.ReadOnly) memory = engine.map(0, 1, QFile.NoOptions) self.assertEqual(len(memory), 1) self.assertEqual(memory[0], py3k.b('a')) engine.unmap(memory)
def setUp(self): self.dom = QDomDocument() self.goodXmlData = QByteArray(py3k.b(''' <typesystem package="PySide2.QtXml"> <value-type name="QDomDocument"/> <value-type name="QDomElement"/> </typesystem> ''')) self.badXmlData = QByteArray(py3k.b(''' <typesystem package="PySide2.QtXml"> <value-type name="QDomDocument"> </typesystem> '''))
def testTimeZone(self): id = py3k.b('Europe/Berlin') timeZone = QTimeZone(id) self.assertTrue(timeZone.isValid()) self.assertEqual(timeZone.id(), id) name = timeZone.displayName(QTimeZone.GenericTime, QTimeZone.DefaultName) self.assertTrue(name)
def testInRangeReverse(self): #QByteArray[x] where x is a valid index (reverse order) string = 'abcdefgh' obj = QByteArray(string) for i in range(len(string)-1, 0, -1): self.assertEqual(obj[i], py3k.b(string[i]))
def testInRange(self): #QByteArray[x] where x is a valid index string = 'abcdefgh' obj = QByteArray(string) for i in range(len(string)): self.assertEqual(obj[i], py3k.b(string[i]))
def testBug721(self): obj = QFile(self.filename) obj.open(QIODevice.ReadOnly) memory = obj.map(0, 1) self.assertEqual(len(memory), 1) self.assertEqual(memory[0], py3k.b('a')) obj.unmap(memory)
def testPythonStrAndNull(self): s1 = b("123\000321") ba = ByteArray(s1) s2 = ba.data() self.assertEqual(s1, s2) self.assertEqual(type(s1), type(s2)) self.assertEqual(s1, ba) self.assertNotEqual(type(s1), type(ba))
def testCorruptData(self): '''QDataStream reading corrupt data''' data = [] data.append((QByteArray(py3k.b('\x00\x00\x00\x01\x02')), QDataStream.ReadCorruptData, QBitArray())) self._check_bitarray(data)
def testPythonStrAndNull(self): s1 = b('123\000321') ba = ByteArray(s1) s2 = ba.data() self.assertEqual(s1, s2) self.assertEqual(type(s1), type(s2)) self.assertEqual(s1, ba) self.assertNotEqual(type(s1), type(ba))
def testPastEnd(self): '''QDataStream >> QBitArray reading past the end of the data''' data = [] data.append((QByteArray(), QDataStream.ReadPastEnd, QBitArray())) data.append( (QByteArray(py3k.b('\x00')), QDataStream.ReadPastEnd, QBitArray())) data.append((QByteArray(py3k.b('\x00\x00')), QDataStream.ReadPastEnd, QBitArray())) data.append( (QByteArray(py3k.b('\x00\x00\x00')), QDataStream.ReadPastEnd, QBitArray())) data.append( (QByteArray(py3k.b('\x00\x00\x00\x01')), QDataStream.ReadPastEnd, QBitArray())) data.append( (QByteArray(py3k.b('\x00\x00\x00\x02')), QDataStream.ReadPastEnd, QBitArray())) data.append( (QByteArray(py3k.b('\x00\x00\x00\x03')), QDataStream.ReadPastEnd, QBitArray())) data.append( (QByteArray(py3k.b('\x00\x00\x00\x04')), QDataStream.ReadPastEnd, QBitArray())) self._check_bitarray(data)
def testWrite(self): text = 'foobar' doc = QTextDocument(text) b = QBuffer() b.open(QBuffer.ReadWrite) writer = QTextDocumentWriter(b, py3k.b("plaintext")) writer.write(doc) b.close() self.assertEqual(b.buffer(), text)
def testQSaveFile(self): dir = QTemporaryDir(QDir.tempPath() + "/XXXXXX.dir") self.assertTrue(dir.isValid()) saveFile = QSaveFile(dir.path() + "/test.dat") self.assertTrue(saveFile.open(QIODevice.WriteOnly)) saveFile.write(py3k.b("Test")) self.assertTrue(saveFile.commit()) self.assertTrue( os.path.exists(QDir.toNativeSeparators(saveFile.fileName())))
def testIt(self): ba = QByteArray(py3k.b('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')
def test_SchemeHandlerRedirect(self): app = QApplication([]) handler = TestSchemeHandler() profile = QWebEngineProfile.defaultProfile() profile.installUrlSchemeHandler(py3k.b("testpy"), handler) view = QWebEngineView() view.loadFinished.connect(app.quit) QTimer.singleShot(5000, app.quit) view.show() view.load("testpy:hello") app.exec_() self.assertEqual(view.url(), "testpy:goodbye")
def testBug721(self): obj = QFile(self.filename) obj.open(QIODevice.ReadOnly) try: memory = obj.map(0, 1) self.assertEqual(len(memory), 1) if sys.version_info[0] >= 3: self.assertEqual(memory[0], ord('a')) else: self.assertEqual(memory[0], py3k.b('a')) # now memory points to wild bytes... :-) # uncommenting this must cause a segfault. # self.assertEqual(memory[0], 'a') finally: obj.unmap(memory) obj.close()
def testSchema(self): data = QByteArray( py3k.b('''<?xml version=\"1.0\" encoding=\"UTF-8\"?> <xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://qt.nokia.com/xmlschematest\" targetNamespace=\"http://qt.nokia.com/xmlschematest\" version=\"1.0\" elementFormDefault=\"qualified\"> </xsd:schema>''')) buf = QBuffer(data) buf.open(QIODevice.ReadOnly) schema = QXmlSchema() schema.load(buf) self.assertTrue(schema.isValid())
def testLatin1(self): '''QTextStream readLine for simple Latin1 strings''' data = [] data.append((QByteArray(), [])) data.append((QByteArray(py3k.b('\n')), [''])) data.append((QByteArray(py3k.b('\r\n')), [''])) data.append((QByteArray(py3k.b('ole')), ['ole'])) data.append((QByteArray(py3k.b('ole\n')), ['ole'])) data.append((QByteArray(py3k.b('ole\r\n')), ['ole'])) data.append((QByteArray(py3k.b('ole\r\ndole\r\ndoffen')), ['ole', 'dole', 'doffen'])) self._check_data(data)
class HttpSignalsCase(UsesQCoreApplication): '''Test case for launching QHttp signals''' DATA = py3k.b("PySide rocks") def onError(self): self.assertTrue(False) def onNewConnection(self): self.serverConnection = self.server.nextPendingConnection() self.serverConnection.error.connect(self.onError) self.serverConnection.write(HttpSignalsCase.DATA) self.server.close() def onReadReady(self): data = self.client.read(100) self.assertEqual(len(data), len(HttpSignalsCase.DATA)) self.assertEqual(data, HttpSignalsCase.DATA) self.done() def onClientConnect(self): self.client.readyRead.connect(self.onReadReady) def initServer(self): self.server = QTcpServer() self.server.newConnection.connect(self.onNewConnection) self.assertTrue(self.server.listen()) self.client = QTcpSocket() self.client.connected.connect(self.onClientConnect) self.client.connectToHost(QHostAddress(QHostAddress.LocalHost), self.server.serverPort()) def done(self): self.serverConnection.close() self.client.close() self.app.quit() def testRun(self): self.initServer() self.app.exec_()
def readData(self, amount): return py3k.b("\0a" * int(amount / 2))
def testNullStrings(self): ba = QByteArray('\x00') self.assertEqual(ba.at(0), '\x00') self.assertEqual(ba[0], py3k.b('\x00'))
def testDataWithZeros(self): s1 = "123\000321" ba = QByteArray(s1) s2 = ba.data() self.assertEqual(py3k.b(s1), s2) self.assertEqual(s1, ba)
def testNullStrings(self): ba = ByteArray("\x00") self.assertEqual(ba.at(0), "\x00") self.assertEqual(ba[0], b("\x00"))
def testEmptyStringAsBuffer(self): img = QImage(py3k.b(''), 100, 100, QImage.Format_ARGB32)
def testFromDataMethod(self): dataBits = py3k.b('\x38\x28\x38\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\xfe\xfe\x7c\x7c\x38\x38\x10\x10') bim = QBitmap.fromData(QSize(8, 48), dataBits, QImage.Format_Mono) # missing function
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 do_GET(self): self.send_head() self.wfile.write(py3k.b(TestHandler.DATA))
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 readLineData(self, maxSize): return py3k.b("\0b" * 4)
def testBufferArgument(self): overload = Overload() self.assertEqual(overload.strBufferOverloads(b(''), 0), Overload.Function1)
def testData(self): url = QByteArray("http://web.openbossa.org/") self.assertEqual(url.data(), py3k.b("http://web.openbossa.org/"))
def testIt(self): data = py3k.b("foobar") a = QByteArray.fromRawData(data) self.assertEqual(type(a), QByteArray) self.assertEqual(a.data(), data)
def setUp(self): '''Acquire resources''' handle, self.filename = tempfile.mkstemp() os.write(handle, py3k.b('a')) os.close(handle)
def readData(self, amount): return py3k.b("\0a" * int(amount/2))