From e39bfefde9edda662f51eeaf9a482f209c7f1217 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Thu, 3 Jun 2010 15:34:17 -0300 Subject: Remove wrapper for classes: QString, QStringRef, QLatin1String, QStringMatcher, QChar and QLatin1Char. --- PySide/QtCore/CMakeLists.txt | 7 - PySide/QtCore/glue/qstring_bufferprotocol.cpp | 43 --- PySide/QtCore/glue/qstring_hashfunc.cpp | 6 - PySide/QtCore/qchar_conversions.h | 42 +-- PySide/QtCore/qstring_conversions.h | 124 +++++---- PySide/QtCore/qstringlist_conversions.h | 16 +- PySide/QtCore/qstringref_conversions.h | 19 ++ PySide/QtCore/typesystem_core.xml | 371 +++----------------------- tests/QtCore/CMakeLists.txt | 6 - tests/QtCore/buffer_test.py | 13 - tests/QtCore/qbytearray_operator_iadd_test.py | 11 +- tests/QtCore/qbytearray_operator_test.py | 6 +- tests/QtCore/qchar_test.py | 59 ---- tests/QtCore/qdatastream_test.py | 3 +- tests/QtCore/qenum_test.py | 4 +- tests/QtCore/qlatin1string_test.py | 21 -- tests/QtCore/qobject_property_test.py | 8 +- tests/QtCore/qstring_buffer_protocol_test.py | 20 -- tests/QtCore/qstring_operator_test.py | 161 ----------- tests/QtCore/qstring_test.py | 176 +----------- tests/QtCore/qstringlist_test.py | 171 ------------ tests/QtCore/qtextstream_test.py | 16 +- tests/QtCore/qvariant_pyobject_test.py | 7 +- tests/QtCore/qvariant_test.py | 19 +- tests/QtCore/translation_test.py | 4 +- tests/QtGui/qinputdialog_get_test.py | 2 +- tests/QtGui/qpixmap_test.py | 2 +- tests/QtGui/qstring_qkeysequence_test.py | 15 +- tests/QtSql/qsqldatabaseandqueries_test.py | 4 +- tests/phonon/capabilities_test.py | 4 +- tests/signals/decorators_test.py | 4 +- tests/signals/signal_object_test.py | 8 +- 32 files changed, 185 insertions(+), 1187 deletions(-) delete mode 100644 PySide/QtCore/glue/qstring_bufferprotocol.cpp delete mode 100644 PySide/QtCore/glue/qstring_hashfunc.cpp create mode 100644 PySide/QtCore/qstringref_conversions.h delete mode 100644 tests/QtCore/buffer_test.py delete mode 100644 tests/QtCore/qchar_test.py delete mode 100644 tests/QtCore/qlatin1string_test.py delete mode 100755 tests/QtCore/qstring_buffer_protocol_test.py delete mode 100644 tests/QtCore/qstring_operator_test.py delete mode 100644 tests/QtCore/qstringlist_test.py diff --git a/PySide/QtCore/CMakeLists.txt b/PySide/QtCore/CMakeLists.txt index 757251919..bbe8ba7b5 100644 --- a/PySide/QtCore/CMakeLists.txt +++ b/PySide/QtCore/CMakeLists.txt @@ -49,7 +49,6 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qbitarray_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qbuffer_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qbytearray_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qbytearraymatcher_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qchar_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qchildevent_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qcoreapplication_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qcryptographichash_wrapper.cpp @@ -69,8 +68,6 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfsfileengine_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qgenericargument_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qgenericreturnargument_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qiodevice_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qlatin1char_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qlatin1string_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qlibraryinfo_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qline_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qlinef_wrapper.cpp @@ -101,10 +98,6 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qsignalmapper_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qsize_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qsizef_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qsocketnotifier_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qstring_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qstringlist_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qstringmatcher_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qstringref_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qsysinfo_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qsystemlocale_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qsystemsemaphore_wrapper.cpp diff --git a/PySide/QtCore/glue/qstring_bufferprotocol.cpp b/PySide/QtCore/glue/qstring_bufferprotocol.cpp deleted file mode 100644 index 02ca32c6f..000000000 --- a/PySide/QtCore/glue/qstring_bufferprotocol.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -#if PY_VERSION_HEX < 0x03000000 - -// QByteArray buffer protocol functions -// see: http://www.python.org/dev/peps/pep-3118/ - -extern "C" { - -static Py_ssize_t SbkQString_segcountproc(PyObject* self, Py_ssize_t* lenp) -{ - if (lenp) - *lenp = self->ob_type->tp_as_sequence->sq_length(self); - return 1; -} - -static Py_ssize_t SbkQString_readbufferproc(PyObject* self, Py_ssize_t segment, char** ptrptr) -{ - if (segment || Shiboken::cppObjectIsInvalid(self)) - return -1; - - QString* cppSelf = Converter::toCpp(self); - QByteArray decodedData = cppSelf->toLocal8Bit(); - Shiboken::AutoDecRef decodedString(PyString_FromStringAndSize(decodedData.constData(), decodedData.size())); - - // delete __encodedStr attr if it exists - Shiboken::AutoDecRef attrName(PyString_FromStringAndSize("__encodedStr", sizeof("__encodedStr")-1)); - if (PyObject_HasAttr(self, attrName)) - PyObject_DelAttr(self, attrName); - PyObject_SetAttr(self, attrName, decodedString); - *ptrptr = PyString_AS_STRING(decodedString.object()); - return decodedData.size(); -} - -PyBufferProcs SbkQStringBufferProc = { - /*bf_getreadbuffer*/ 0, - /*bf_getwritebuffer*/ 0, - /*bf_getsegcount*/ &SbkQString_segcountproc, - /*bf_getcharbuffer*/ &SbkQString_readbufferproc -}; - -} - -#endif diff --git a/PySide/QtCore/glue/qstring_hashfunc.cpp b/PySide/QtCore/glue/qstring_hashfunc.cpp deleted file mode 100644 index b2fb6a1c9..000000000 --- a/PySide/QtCore/glue/qstring_hashfunc.cpp +++ /dev/null @@ -1,6 +0,0 @@ -static long QStringCustomHashFunction(const QString& str) -{ - QByteArray data = str.toUtf8(); - Shiboken::AutoDecRef unicodeObj(PyUnicode_DecodeUTF8(data.constData(), data.length(), 0)); - return unicodeObj->ob_type->tp_hash(unicodeObj); -} diff --git a/PySide/QtCore/qchar_conversions.h b/PySide/QtCore/qchar_conversions.h index 6347c9311..ab477efc8 100644 --- a/PySide/QtCore/qchar_conversions.h +++ b/PySide/QtCore/qchar_conversions.h @@ -1,30 +1,30 @@ namespace Shiboken { -inline bool Shiboken::Converter::isConvertible(PyObject* pyObj) -{ - return PyObject_TypeCheck(pyObj, SbkType()) - || SbkPySide_QtCore_QChar_SpecialCharacter_Check(pyObj) - || SbkQLatin1Char_Check(pyObj) - || (PyString_Check(pyObj) && (PyString_Size(pyObj) == 1)) - || PyInt_Check(pyObj); -} -inline QChar Shiboken::Converter::toCpp(PyObject* pyObj) +template<> +class Converter { - if (!Shiboken_TypeCheck(pyObj, QChar)) { - if (SbkPySide_QtCore_QChar_SpecialCharacter_Check(pyObj)) - return QChar(Shiboken::Converter::toCpp(pyObj)); - else if (SbkQLatin1Char_Check(pyObj)) - return QChar(Shiboken::Converter::toCpp(pyObj)); - else if (PyString_Check(pyObj) && PyString_Size(pyObj) == 1) +public: + static bool isConvertible(PyObject* pyObj) + { + return (PyString_Check(pyObj) && (PyString_Size(pyObj) == 1)) + || PyInt_Check(pyObj); + } + + static QChar toCpp(PyObject* pyObj) + { + if (PyString_Check(pyObj) && PyString_Size(pyObj) == 1) return QChar(Shiboken::Converter::toCpp(pyObj)); else if (PyInt_Check(pyObj)) return QChar(Shiboken::Converter::toCpp(pyObj)); + return QChar(); } - return *Converter::toCpp(pyObj); -} -inline PyObject* Converter::toPython(const QChar& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} + static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } + static PyObject* toPython(const QChar& cppObj) + { + wchar_t c = (wchar_t)cppObj.unicode(); + PyObject* pyObj = PyUnicode_FromWideChar(&c, 1); + return pyObj; + } +}; } diff --git a/PySide/QtCore/qstring_conversions.h b/PySide/QtCore/qstring_conversions.h index 2c59928dd..392f0e7b7 100644 --- a/PySide/QtCore/qstring_conversions.h +++ b/PySide/QtCore/qstring_conversions.h @@ -1,72 +1,70 @@ namespace Shiboken { -inline bool Converter::isConvertible(PyObject* pyObj) -{ - SbkBaseWrapperType* shiboType = reinterpret_cast(SbkType()); - return PyString_Check(pyObj) - || PyObject_TypeCheck(pyObj, SbkType()) - || PyUnicode_Check(pyObj) - || SbkQByteArray_Check(pyObj) - || SbkQLatin1String_Check(pyObj) - || pyObj == Py_None -#if PY_VERSION_HEX < 0x03000000 - || (pyObj->ob_type->tp_as_buffer - && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER) - && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) -#endif - || SbkQChar_Check(pyObj) - || (shiboType->ext_isconvertible && shiboType->ext_isconvertible(pyObj)); -} -inline QString Converter::toCpp(PyObject* pyObj) +template<> +class Converter { - SbkBaseWrapperType* shiboType = reinterpret_cast(SbkType()); - if (SbkQChar_Check(pyObj)) { - return QString(Converter< QChar >::toCpp(pyObj)); - } else if (SbkQByteArray_Check(pyObj)) { - return QString(Converter< QByteArray >::toCpp(pyObj)); - } else if (SbkQLatin1String_Check(pyObj)) { - return QString(Converter< QLatin1String >::toCpp(pyObj)); - } else if (PyUnicode_Check(pyObj)) { - Py_UNICODE* unicode = PyUnicode_AS_UNICODE(pyObj); -#if defined(Py_UNICODE_WIDE) - // cast as Py_UNICODE can be a different type - return QString::fromUcs4(reinterpret_cast(unicode)); -#else - return QString::fromUtf16(unicode, PyUnicode_GET_SIZE(pyObj)); -#endif - } else if (PyString_Check(pyObj)) { - return QString(Converter< char * >::toCpp(pyObj)); - } else if (pyObj == Py_None) { - return QString(); +public: + static bool isConvertible(PyObject* pyObj) + { + return PyString_Check(pyObj) + || PyUnicode_Check(pyObj) + || SbkQByteArray_Check(pyObj) + || pyObj == Py_None + #if PY_VERSION_HEX < 0x03000000 + || (pyObj->ob_type->tp_as_buffer + && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER) + && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) + #endif + ; } + + static QString toCpp(PyObject* pyObj) + { + if (PyUnicode_Check(pyObj)) { + Py_UNICODE* unicode = PyUnicode_AS_UNICODE(pyObj); + #if defined(Py_UNICODE_WIDE) + // cast as Py_UNICODE can be a different type + return QString::fromUcs4(reinterpret_cast(unicode)); + #else + return QString::fromUtf16(unicode, PyUnicode_GET_SIZE(pyObj)); + #endif + } else if (PyString_Check(pyObj)) { + return QString(Converter< char * >::toCpp(pyObj)); + } else if (pyObj == Py_None) { + return QString(); + } else if (SbkQByteArray_Check(pyObj)) { + return QString(Converter< QByteArray >::toCpp(pyObj)); + } #if PY_VERSION_HEX < 0x03000000 - // Support for buffer objects on QString constructor - else if (pyObj->ob_type->tp_as_buffer - && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER) - && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) { - QByteArray data; - PyBufferProcs* bufferProcs = pyObj->ob_type->tp_as_buffer; - int segments = bufferProcs->bf_getsegcount(pyObj, 0); - for (int i = 0; i < segments; ++i) { - char* segmentData; - int length = bufferProcs->bf_getcharbuffer(pyObj, i, &segmentData); - if (length == -1) - break; - data.append(segmentData, length); + // Support for buffer objects on QString constructor + else if (pyObj->ob_type->tp_as_buffer + && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER) + && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) { + QByteArray data; + PyBufferProcs* bufferProcs = pyObj->ob_type->tp_as_buffer; + int segments = bufferProcs->bf_getsegcount(pyObj, 0); + for (int i = 0; i < segments; ++i) { + char* segmentData; + int length = bufferProcs->bf_getcharbuffer(pyObj, i, &segmentData); + if (length == -1) + break; + data.append(segmentData, length); + } + return QString(data); } - return QString(data); - } -#endif - else if (shiboType->ext_isconvertible && shiboType->ext_tocpp && shiboType->ext_isconvertible(pyObj)) { - QString* cptr = reinterpret_cast(shiboType->ext_tocpp(pyObj)); - std::auto_ptr cptr_auto_ptr(cptr); - return *cptr; + #endif + return QString(); } - return *Converter::toCpp(pyObj); -} -inline PyObject* Converter::toPython(const QString& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} + static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } + static PyObject* toPython(const QString& cppObj) + { + const int N = cppObj.length(); + wchar_t* str = new wchar_t[N]; + cppObj.toWCharArray(str); + PyObject* pyObj = PyUnicode_FromWideChar(str, N); + delete[] str; + return pyObj; + } +}; } diff --git a/PySide/QtCore/qstringlist_conversions.h b/PySide/QtCore/qstringlist_conversions.h index 9a5ec5f0b..6075c1672 100644 --- a/PySide/QtCore/qstringlist_conversions.h +++ b/PySide/QtCore/qstringlist_conversions.h @@ -1,17 +1,5 @@ namespace Shiboken { -inline bool Converter::isConvertible(PyObject* pyObj) -{ - return StdListConverter::isConvertible(pyObj); -} - -inline QStringList Converter::toCpp(PyObject* pyObj) -{ - return StdListConverter::toCpp(pyObj); -} - -inline PyObject* Converter::toPython(const QStringList& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} +template<> +struct Converter : StdListConverter {}; } diff --git a/PySide/QtCore/qstringref_conversions.h b/PySide/QtCore/qstringref_conversions.h new file mode 100644 index 000000000..11e1b9c62 --- /dev/null +++ b/PySide/QtCore/qstringref_conversions.h @@ -0,0 +1,19 @@ +namespace Shiboken { + +template<> +struct Converter : public Converter +{ + static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } + + static PyObject* toPython(const QStringRef& cppObj) + { + const QString* str = cppObj.string(); + return Converter::toPython(*str); + } + + static QStringRef toCpp(PyObject* pyObj) + { + return QStringRef(); + } +}; +} diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml index 8924fa4fb..56c8b3097 100644 --- a/PySide/QtCore/typesystem_core.xml +++ b/PySide/QtCore/typesystem_core.xml @@ -39,8 +39,15 @@ + + + + + + + @@ -66,15 +73,6 @@ - - - - - - - - - @@ -111,8 +109,6 @@ - - @@ -134,8 +130,7 @@ - - + @@ -145,9 +140,20 @@ - - - + + + + + + + + + + + + + + @@ -242,7 +248,6 @@ - @@ -542,20 +547,6 @@ - - - - - - - - - - - - - - @@ -699,7 +690,6 @@ - @@ -722,6 +712,8 @@ + Shiboken::TypeResolver::createValueTypeResolver<QString>("unicode"); + Shiboken::TypeResolver::createValueTypeResolver<QString>("str"); PySide::init(module); @@ -772,224 +764,6 @@ - - - - - - - - - - - - - #if PY_VERSION_HEX < 0x03000000 - Shiboken::SbkType<QString>()->tp_as_buffer = &SbkQStringBufferProc; - Shiboken::SbkType<QString>()->tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER; - #endif - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - QByteArray utf8 = %CPPSELF.toUtf8(); - %PYARG_0 = PyUnicode_DecodeUTF8(utf8.data(), utf8.count(), 0); - - - - - return %CPPSELF.count(); - - - - - if (_i < 0 || _i >= %CPPSELF.size()) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - return 0; - } - return %CONVERTTOPYTHON[%TYPE](%CPPSELF.at(_i)); - - - - - %CPPSELF.remove(_i, 1); - PyObject* args = Py_BuildValue("(nO)", _i, _value); - PyObject* result = SbkQStringFunc_insert(self, args); - Py_DECREF(args); - Py_XDECREF(result); - return !result ? -1 : 0; - - - - - - - - - - - - - - - - - - - - - - - Implementation note: This constructor is a replacement for - QChar(char), as the char type check also catches numbers, - conflicting with QChar(int). - - - if (PyString_Size(%PYARG_1) == 1) { - char value = %CONVERTTOCPP[char](%PYARG_1); - %0 = new %TYPE(value); - } else { - PyErr_SetString(PyExc_TypeError, "expected string of size 1"); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1062,7 +836,6 @@ - @@ -1493,7 +1266,6 @@ - @@ -1635,75 +1407,6 @@ - - - - - - return %CPPSELF.count(); - - - - - if (_i < 0 || _i >= %CPPSELF.size()) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - return 0; - } - return %CONVERTTOPYTHON[QString](%CPPSELF.at(_i)); - - - - - PyObject* args = Py_BuildValue("(nO)", _i, _value); - PyObject* result = SbkQStringListFunc_replace(self, args); - Py_DECREF(args); - Py_XDECREF(result); - return !result ? -1 : 0; - - - - - - - - - - - return 0; - - - @@ -1759,9 +1462,7 @@ - - @@ -2134,15 +1835,12 @@ - - - - + + + - - - + @@ -2506,7 +2204,10 @@ + + + @@ -2526,6 +2227,11 @@ + + + + + @@ -2553,10 +2259,6 @@ - - - - @@ -2566,6 +2268,7 @@ + diff --git a/tests/QtCore/CMakeLists.txt b/tests/QtCore/CMakeLists.txt index eef6ffe17..4a78bf6ae 100644 --- a/tests/QtCore/CMakeLists.txt +++ b/tests/QtCore/CMakeLists.txt @@ -1,5 +1,4 @@ PYSIDE_TEST(blocking_signals_test.py) -PYSIDE_TEST(buffer_test.py) PYSIDE_TEST(child_event_test.py) PYSIDE_TEST(deletelater_test.py) PYSIDE_TEST(duck_punching_test.py) @@ -14,7 +13,6 @@ PYSIDE_TEST(qbytearray_concatenation_operator_test.py) PYSIDE_TEST(qbytearray_operator_iadd_test.py) PYSIDE_TEST(qbytearray_operator_test.py) PYSIDE_TEST(qbytearray_test.py) -PYSIDE_TEST(qchar_test.py) PYSIDE_TEST(qcoreapplication_instance_test.py) PYSIDE_TEST(qdatastream_test.py) PYSIDE_TEST(qdate_test.py) @@ -24,7 +22,6 @@ PYSIDE_TEST(qfileinfo_test.py) PYSIDE_TEST(qfile_test.py) PYSIDE_TEST(qflags_test.py) PYSIDE_TEST(qhandle_test.py) -PYSIDE_TEST(qlatin1string_test.py) PYSIDE_TEST(qlinef_test.py) PYSIDE_TEST(qlocale_test.py) PYSIDE_TEST(qmetaobject_test.py) @@ -48,9 +45,6 @@ PYSIDE_TEST(qslot_object_test.py) PYSIDE_TEST(qsrand_test.py) PYSIDE_TEST(qstatemachine_test.py) PYSIDE_TEST(qstate_test.py) -PYSIDE_TEST(qstring_buffer_protocol_test.py) -PYSIDE_TEST(qstringlist_test.py) -PYSIDE_TEST(qstring_operator_test.py) PYSIDE_TEST(qstring_test.py) PYSIDE_TEST(qtext_codec_test.py) PYSIDE_TEST(qtextstream_test.py) diff --git a/tests/QtCore/buffer_test.py b/tests/QtCore/buffer_test.py deleted file mode 100644 index 2917232a1..000000000 --- a/tests/QtCore/buffer_test.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/python - -import unittest -from PySide.QtCore import QString - -class BufferTest(unittest.TestCase): - def testQByteArray(self): - data = buffer("PySide") - str = QString(data) - self.assertEqual(data, str) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/QtCore/qbytearray_operator_iadd_test.py b/tests/QtCore/qbytearray_operator_iadd_test.py index 168f22de9..f92fc1964 100644 --- a/tests/QtCore/qbytearray_operator_iadd_test.py +++ b/tests/QtCore/qbytearray_operator_iadd_test.py @@ -2,12 +2,12 @@ import unittest import new -from PySide.QtCore import QByteArray, QString +from PySide.QtCore import * from helper.docmodifier import DocModifier class BaseQByteArrayOperatorIAdd(object): '''Base class for QByteArray += operator tests. - + Implementing classes should inherit from unittest.TestCase and implement setUp, setting self.obj and self.orig_obj to the target QByteArray and original one, respectively''' @@ -41,13 +41,6 @@ class BaseQByteArrayOperatorIAdd(object): self.assertEqual(self.obj, self.orig_obj + s) self.assertEqual(self.obj.size(), self.orig_obj.size() + 1) - def testQString(self): - '''QByteArray += QString''' - s = QString('dummy') - self.obj += s - self.assertEqual(self.obj, self.orig_obj + s) - self.assertEqual(self.obj.size(), self.orig_obj.size() + s.size()) - class NullQByteArrayOperatorIAdd(unittest.TestCase, BaseQByteArrayOperatorIAdd): '''Test case for operator QByteArray += on null QByteArrays''' diff --git a/tests/QtCore/qbytearray_operator_test.py b/tests/QtCore/qbytearray_operator_test.py index 4a20c04c5..662bc6e0c 100644 --- a/tests/QtCore/qbytearray_operator_test.py +++ b/tests/QtCore/qbytearray_operator_test.py @@ -4,7 +4,7 @@ import unittest -from PySide.QtCore import QByteArray, QString +from PySide.QtCore import * class QByteArrayOperatorEqual(unittest.TestCase): '''TestCase for operator QByteArray == QByteArray''' @@ -26,9 +26,9 @@ class QByteArrayOperatorEqual(unittest.TestCase): self.assertEqual(QByteArray(string), string) def testQString(self): - #QByteArray(string) == QString(string) + #QByteArray(string) == string string = 'another test string' - self.assertEqual(QByteArray(string), QString(string)) + self.assertEqual(QByteArray(string), string) class QByteArrayOperatorAt(unittest.TestCase): '''TestCase for operator QByteArray[]''' diff --git a/tests/QtCore/qchar_test.py b/tests/QtCore/qchar_test.py deleted file mode 100644 index a40724b0e..000000000 --- a/tests/QtCore/qchar_test.py +++ /dev/null @@ -1,59 +0,0 @@ - -'''Test cases for QChar''' - -import unittest - -from PySide.QtCore import QString, QChar, QTextStream, QLatin1Char - - -class EqualTest(unittest.TestCase): - '''Tests for '__equal__''' - - def testEqualQChar(self): - '''QChar == QChar''' - self.assertEqual(QChar('a'), QChar('a')) - - def testEqualPyString(self): - '''QChar == Python string''' - self.assertEqual(QChar('a'), 'a') - - -class ImplicitConvQLatin1Char(unittest.TestCase): - '''Tests for implicit conversion from QLatin1Char to QChar''' - - def testQLatin1CharToChar(self): - '''QLatin1Char implicitly convertible to QChar''' - stream = QTextStream() - stream.setPadChar(QLatin1Char('-')) - self.assertEqual(QChar('-'), stream.padChar()) - - -class QCharCtorBigNumber(unittest.TestCase): - '''QChar constructors receiving ints''' - - def testInt(self): - '''QChar(int)''' - codepoint = 512 - qchar = QChar(codepoint) - reference = unichr(codepoint) - self.assertEqual(qchar.unicode(), codepoint) - - -class QCharCtorString(unittest.TestCase): - '''QChar constructor receiving strings''' - - def testBasic(self): - '''QChar(char)''' - reference = 'a' - qchar = QChar(reference) - self.assertEqual(ord(reference), ord(qchar.toAscii())) - - def testError(self): - '''QChar(char)''' - reference = 'aaaaaa' - self.assertRaises(TypeError, QChar, reference) - - -if __name__ == '__main__': - unittest.main() - diff --git a/tests/QtCore/qdatastream_test.py b/tests/QtCore/qdatastream_test.py index d71ed2f24..e80918597 100644 --- a/tests/QtCore/qdatastream_test.py +++ b/tests/QtCore/qdatastream_test.py @@ -3,8 +3,7 @@ import unittest -from PySide.QtCore import QDataStream, QString, QIODevice, QByteArray -from PySide.QtCore import QBitArray, QDate, QTime, QDateTime, QLine, QChar +from PySide.QtCore import * def create_bitarray(string): array = QBitArray(len(string)) diff --git a/tests/QtCore/qenum_test.py b/tests/QtCore/qenum_test.py index e3f963869..d896ae65a 100644 --- a/tests/QtCore/qenum_test.py +++ b/tests/QtCore/qenum_test.py @@ -3,7 +3,7 @@ import unittest -from PySide.QtCore import QIODevice, QString, Qt, QVariant +from PySide.QtCore import * class TestEnum(unittest.TestCase): @@ -18,7 +18,7 @@ class TestEnum(unittest.TestCase): self.assertEqual(QIODevice.Unbuffered, 32) def testToIntInFunction(self): - self.assertEqual(QString.number(QIODevice.WriteOnly), "2") + self.assertEqual(str(int(QIODevice.WriteOnly)), "2") class TestQFlags(unittest.TestCase): def testToItn(self): diff --git a/tests/QtCore/qlatin1string_test.py b/tests/QtCore/qlatin1string_test.py deleted file mode 100644 index fdcf6ec98..000000000 --- a/tests/QtCore/qlatin1string_test.py +++ /dev/null @@ -1,21 +0,0 @@ - -'''Test cases for QLatin1String''' - -import unittest - -from PySide.QtCore import QString, QLatin1String, QObject - - -class ImplicitConvQLatin1String(unittest.TestCase): - '''Tests for implicit conversion from QLatin1String to QString''' - - def testQLatin1String(self): - '''QString implicit convertion from QLatin1String''' - obj = QObject() - obj.setObjectName(QLatin1String('dummy')) - - self.assertEqual(QString('dummy'), obj.objectName()) - -if __name__ == '__main__': - unittest.main() - diff --git a/tests/QtCore/qobject_property_test.py b/tests/QtCore/qobject_property_test.py index 33df2ac9b..d1f12b343 100644 --- a/tests/QtCore/qobject_property_test.py +++ b/tests/QtCore/qobject_property_test.py @@ -3,7 +3,7 @@ import unittest -from PySide.QtCore import QObject, QVariant, QString +from PySide.QtCore import * class PropertyCase(unittest.TestCase): '''Test case for QObject properties''' @@ -41,14 +41,14 @@ class PropertyCase(unittest.TestCase): # QVariant.toInt has a bool* arg in C++, so returns a tuple self.assertEqual(obj.property('dummy').toInt(), (42, True)) - def testQStringProperty(self): + def testStringProperty(self): obj = QObject() - self.assert_(not obj.setProperty('dummy', QString('data'))) + self.assert_(not obj.setProperty('dummy', 'data')) prop = obj.property('dummy') self.assert_(isinstance(prop, QVariant)) self.assert_(prop.isValid()) - self.assertEqual(obj.property('dummy').toString(), QString('data')) + self.assertEqual(obj.property('dummy').toString(), 'data') def testImplicitQVariantProperty(self): obj = QObject() diff --git a/tests/QtCore/qstring_buffer_protocol_test.py b/tests/QtCore/qstring_buffer_protocol_test.py deleted file mode 100755 index f8475d093..000000000 --- a/tests/QtCore/qstring_buffer_protocol_test.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -'''Tests QString implementation of Python buffer protocol''' - -import unittest - -from os.path import isdir -from PySide.QtCore import QString - -class QStringBufferProtocolTest(unittest.TestCase): - '''Tests QString implementation of Python buffer protocol''' - - def testQStringBufferProtocol(self): - #Tests QString implementation of Python buffer protocol using the os.path.isdir - #function which an unicode object or other object implementing the Python buffer protocol - isdir(QString('/tmp')) - -if __name__ == '__main__': - unittest.main() - diff --git a/tests/QtCore/qstring_operator_test.py b/tests/QtCore/qstring_operator_test.py deleted file mode 100644 index 6d7ae314d..000000000 --- a/tests/QtCore/qstring_operator_test.py +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -'''Test cases for QString operators''' - -import unittest - -from PySide.QtCore import QString, QByteArray - -class QStringOperatorEqual(unittest.TestCase): - '''TestCase for operator QString == QString''' - - def testDefault(self): - #QString() == QString() - obj1 = QString() - obj2 = QString() - self.assertEqual(obj1, obj2) - - def testSimple(self): - #QString(some_string) == QString(some_string) - string = 'egg snakes' - self.assertEqual(QString(string), QString(string)) - - def testUnicode(self): - #QString(unicode) == QString(unicode) - string = u'àâãá' - self.assertEqual(QString(string), QString(string)) - - def testPyString(self): - #QString(string) == string - string = 'my test string' - self.assertEqual(QString(string), string) - self.assertEqual(string, QString(string)) - - def testPyUnicodeString(self): - #QString(unicode) == unicode - string = u'àâãá' - self.assertEqual(QString(string), string) - self.assertEqual(string, unicode(QString(string))) - - def testQByteArray(self): - #QString(string) == QByteArray(string) - string = 'another test string' - self.assertEqual(QString(string), QByteArray(string)) - - -class QStringOperatorAtSetter(unittest.TestCase): - '''Test case for operator QString[] - __setitem__''' - - def testSetterString(self): - '''QString[x] = pythonstring''' - obj = QString('123456') - obj[1] = '0' - self.assertEqual(obj, QString('103456')) - - def testSetterStringLarge(self): - '''QString[x] = pythonstring (larget than 1 char)''' - obj = QString('123456') - obj[3] = 'abba' - self.assertEqual(obj, QString('123abba56')) - - def testSetterQString(self): - '''QString[x] = QString''' - obj = QString('123456') - obj[3] = QString('string') - self.assertEqual(obj, QString('123string56')) - - def testSetterQByteArray(self): - '''QString[x] = qbytearray''' - obj = QString('123456') - obj[3] = QByteArray('array') - self.assertEqual(obj, QString('123array56')) - - -class QStringOperatorAtSetterNegativeIndex(unittest.TestCase): - '''Test case for QString[] - __setitem__ - for negative index''' - - def testSetterNegativeIndex(self): - '''QString[x] = string - negative index''' - obj = QString('123456') - obj[-3] = 'array' - self.assertEqual(obj, QString('123array56')) - - -class QStringOperatorAtSetterLargeIndex(unittest.TestCase): - '''Test case for QString[] - __setitem__ - for 'overflown' index''' - - def testSetterLargeIndexEmpty(self): - '''QString[x] = somestring - Overflow index on empty string''' - # should pad with spaces if the index is larger - obj = QString('') - obj[2] = 'a' - self.assertEqual(obj, QString(' a')) - - def testSetterLargeIndexNormal(self): - '''QString[x] = somestring - Overflow index on normal string''' - # should pad with spaces if the index is larger - obj = QString('mystring') - obj[10] = 'normal' - self.assertEqual(obj, QString('mystring normal')) - - -class QStringOperatorAt(unittest.TestCase): - '''TestCase for operator QString[] - __getitem__''' - - def testInRange(self): - #QString[x] where x is a valid index - string = 'abcdefgh' - obj = QString(string) - - for i in range(len(string)): - self.assertEqual(obj[i], string[i]) - - def testInRangeReverse(self): - #QString[x] where x is a valid index (reverse order) - string = 'abcdefgh' - obj = QString(string) - - for i in range(len(string)-1, 0, -1): - self.assertEqual(obj[i], string[i]) - - - def testInRangeUnicode(self): - #QString[x] where x is a valid index (unicode) - string = u'àâãá' - obj = QString(string) - - for i in range(len(string)): - self.assertEqual(obj[i], string[i]) - - def testInRangeUnicodeReverse(self): - #QString[x] where x is a valid index (unicode) (reverse order) - string = u'àâãá' - obj = QString(string) - - for i in range(len(string)-1, 0, -1): - self.assertEqual(obj[i], string[i]) - - def testOutOfRange(self): - #QString[x] where x is out of index - string = '1234567' - obj = QString(string) - self.assertRaises(IndexError, lambda :obj[len(string)]) - - def testReturnQString(self): - #QString[x] must return a QString - string = QString('123456') - data = string[0] - self.assert_(isinstance(data, QString)) - -class QStringOperatorAdd(unittest.TestCase): - '''TestCase for operator QString[]''' - - def testOperatorAdd(self): - str1 = '123' - str2 = QString('456') - self.assertEquals('123456', str1 + str2) - self.assertEquals('456123', str2 + str1) - - -if __name__ == '__main__': - unittest.main() diff --git a/tests/QtCore/qstring_test.py b/tests/QtCore/qstring_test.py index 3f0fb4931..fbaa6d440 100644 --- a/tests/QtCore/qstring_test.py +++ b/tests/QtCore/qstring_test.py @@ -6,173 +6,19 @@ import unittest import ctypes import sys -from PySide.QtCore import QString, QByteArray, QObject - -class QStringToNumber(unittest.TestCase): - def testReturnValueTypes(self): - obj = QString('37') - val, ok = obj.toInt() - self.assertEqual(type(val), int) - self.assertEqual(type(ok), bool) - - def testToNumberInt(self): - obj = QString('37') - self.assertEqual((37, True), obj.toInt()) - - def testToNumberLong(self): - obj = QString('3700000') - self.assertEqual((3700000, True), obj.toInt()) - - def testToNumberShort(self): - obj = QString('33') - self.assertEqual((ctypes.c_short(33).value, True), obj.toShort()) - - def testToNumberShortNegative(self): - obj = QString('-4') - self.assertEqual((ctypes.c_short(-4).value, True), obj.toShort()) - - def testToNumberShortOverflow(self): - obj = QString('1000000') - self.assertEqual(False, obj.toShort()[1]) - - def testToNumberUInt(self): - obj = QString('33') - self.assertEqual((ctypes.c_uint(33).value, True), obj.toUInt()) - - def testToNumberUIntNegative(self): - obj = QString('-4') - self.assertEqual(False, obj.toUInt()[1]) - - def testToNumberUIntOverflow(self): - obj = QString('10000000000000') - self.assertEqual(False, obj.toUInt()[1]) - - def testToNumberULong(self): - obj = QString('33') - self.assertEqual((ctypes.c_ulong(33).value, True), obj.toULong()) - - def testToNumberULongNegative(self): - obj = QString('-4') - self.assertEqual(False, obj.toULong()[1]) - - def testToNumberUShort(self): - obj = QString('33') - self.assertEqual((ctypes.c_ushort(33).value, True), obj.toUShort()) - - def testToNumberUShortLarge(self): - obj = QString('128') - self.assertEqual((ctypes.c_ushort(128).value, True), obj.toUShort()) - - def testToNumberUShortOverflow(self): - obj = QString('205000') - self.assertEqual(False, obj.toUShort()[1]) - - def testToNumberUShortNegative(self): - obj = QString('-4') - self.assertEqual(False, obj.toUShort()[1]) - - def testToNumberIntUsingHex(self): - obj = QString('2A') - self.assertEquals((0, False), obj.toInt()) - self.assertEqual((int(str(obj), 16), True), obj.toInt(16)) - - def testToNumberIntUsingHex(self): - obj = QString('101010') - self.assertEqual((int(str(obj), 2), True), obj.toInt(2)) - - def testToNumberFloat(self): - obj = QString('37.109') - self.assertEqual(ctypes.c_float(37.109).value, - obj.toFloat()[0]) - - def testToNumberDouble(self): - obj = QString('37.109') - self.assertEqual(ctypes.c_double(37.109).value, - obj.toDouble()[0]) - - def testToULongLong(self): - obj = QString('37109') - self.assertEqual(ctypes.c_ulong(37109).value, - obj.toULongLong()[0]) +from PySide.QtCore import * class QStringConstructor(unittest.TestCase): '''Test case for QString constructors''' def testQStringDefault(self): - #QString() - obj1 = QString() - obj2 = QString() - - self.assertEqual(obj1, obj2) - - def testNullQString(self): - s = QString(None) - self.assertTrue(s.isNull()) - - def testQStringFromPy(self): - #QString(const char*) - sample = 'a new string' - obj1 = QString(sample) - obj2 = QString(sample) - self.assertEqual(obj1, obj2) - - def testQStringFromUnicode(self): - sample = u'áâãà' - obj1 = QString(sample) - obj2 = QString(sample) - self.assertEqual(obj1, obj2) - self.assertEqual(obj1, sample) - self.assertEqual(obj2, sample) - - def testQStringFromByteArray(self): - # QByteArray(const char *) must be working - sample = QByteArray('foo') - obj1 = QString(sample) - obj2 = QString(sample) - self.assertEqual(obj1, obj2) - - def testQStringArg(self): - a = QString("%1 %2 %3").arg(1).arg("two").arg(3.14) - self.assertEquals("1 two 3.14", str(a)) - - def testQStringArgNegative(self): - a = QString("%1").arg(-20) - self.assertEquals("-20", str(a)) - - -class QStringComparison(unittest.TestCase): - '''Test case for comparison to python strings''' - - def testComparePyString(self): - #Compare QStrings and Python strings. - py = '' - qstr = QString() - self.assertEqual(py, qstr) - - py = 'The quick brown fox jumps over the lazy dog' - qstr = QString(py) - self.assertEqual(py, qstr) - -class QStringRange(unittest.TestCase): - '''Test case for ranges in python strings''' - - def testSimpleRange(self): - #Test open start and open end intervals - py = 'The quick brown fox jumps over the lazy dog' - qstr = QString(py) - self.assertEqual(py[5:], qstr[5:]) - self.assertEqual(py[:7], qstr[:7]) - -class QStringIndexOf(unittest.TestCase): - def testEmpty(self): - string = QString() - self.assertEqual(string.indexOf(QString("aaa")), -1) - self.assertEqual(string.indexOf(QString()), 0) - - def testString(self): - string = QString("the quick brown fox") - self.assertEqual(string.indexOf("quick", 0), 4) - + obj = QObject() + obj.setObjectName('foo') + self.assertEqual(obj.objectName(), u'foo') + obj.setObjectName(u'áâãà') + self.assertEqual(obj.objectName(), u'áâãà') + obj.setObjectName(None) + self.assertEqual(obj.objectName(), u'') class QStringImplicitConvertion(unittest.TestCase): '''Implicit conversions for QString''' @@ -181,12 +27,8 @@ class QStringImplicitConvertion(unittest.TestCase): '''QString implicitly conversion: QByteArray''' obj = QObject() obj.setObjectName(QByteArray('foobar')) - self.assertEqual(obj.objectName(), QString('foobar')) + self.assertEqual(obj.objectName(), u'foobar') -class QStringHash(unittest.TestCase): - def testHash(self): - self.assertEqual(hash("key"), hash(QString("key"))) - self.assertEqual(hash(u"aéióu"), hash(QString(u"aéióu"))) if __name__ == '__main__': unittest.main() diff --git a/tests/QtCore/qstringlist_test.py b/tests/QtCore/qstringlist_test.py deleted file mode 100644 index 031051684..000000000 --- a/tests/QtCore/qstringlist_test.py +++ /dev/null @@ -1,171 +0,0 @@ - -# -*- coding: utf-8 -*- - -'''Test cases for QStringList''' - -import unittest -from random import shuffle - -from PySide.QtCore import QStringList, QString - -from helper import random_string - -class UsesManyStrings(unittest.TestCase): - '''Helper class to setup a list of strings and QStrings''' - def setUp(self): - #Creates a list of strings and python strings - self.size = 10 - # List of Python strings - self.samples = [random_string() for x in range(self.size)] - # List of QStrings - self.strings = map(QString, self.samples) - - self.obj = QStringList(self.strings) - - -class TestConstructorBasic(unittest.TestCase): - '''Basic constructor test''' - - def testEmpty(self): - #QStringList() - default constructor - obj = QStringList() - self.assert_(isinstance(obj, QStringList)) - - def testQString(self): - #QStringList(QString) - qstr = QString('aaaa') - obj = QStringList(qstr) - self.assert_(isinstance(obj, QStringList)) - - def testPyString(self): - #QStringList(python_string) constructor - string = 'forty two' - obj = QStringList(string) - self.assert_(isinstance(obj, QStringList)) - - def testPyStringUnicode(self): - #QStringList(unicode python_string) constructor - string = 'Nação Zumbi' - obj = QStringList(string) - self.assert_(isinstance(obj, QStringList)) - - -class TestConstructorList(UsesManyStrings): - '''Test case for QStringList(List) constructor''' - - def testListQString(self): - #QStringList([QString]) constructor - obj = QStringList(self.strings) - self.assert_(isinstance(obj, QStringList)) - - def testListPyString(self): - #QStringList([python_string]) constructor - obj = QStringList(self.samples) - self.assert_(isinstance(obj, QStringList)) - - def testListMixed(self): - #QStringList([python_string and QString]) mixed constructor - mixed = self.samples + self.strings - shuffle(mixed) - obj = QStringList(mixed) - self.assert_(isinstance(obj, QStringList)) - - def testCopyList(self): - #QStringList(QStringList(list)) - copy constructor - obj = QStringList(self.strings) - obj2 = QStringList(obj) - self.assert_(isinstance(obj2, QStringList)) - self.assertEqual(obj, obj2) - - -class TestComparison(unittest.TestCase): - '''Test case for comparison of QStringLists''' - - def testEqual(self): - #QStringList == QStringList - string = QString('aaaabvbbcccedde') - obj1 = QStringList(string) - obj2 = QStringList(string) - self.assertEqual(obj1, obj2) - - -class TestIndexing(unittest.TestCase): - '''Test case for indexing through []''' - def testInvalidIndexEmpty(self): - #QStringList[x] for empty list - obj = QStringList() - self.assertRaises(IndexError, lambda:obj[0]) - - def testInvalidIndexQString(self): - #QStringList[1] raising IndexError for QStringList(QString) - obj = QStringList(QString('aaaaa')) - self.assertRaises(IndexError, lambda:obj[1]) - - def testValidIndexQString(self): - #QStringList[0] not raising IndexError for QStringList(QString) - string = QString('abcdefg') - obj = QStringList(string) - self.assertEqual(obj[0], string) - - def testNegativeIndexing(self): - #QStringList[-1] not raising IndexError for QStringList(QString) - string = QString('abcdefg') - obj = QStringList(string) - self.assertEqual(obj[-1], string) - - -class TestListIndexing(UsesManyStrings): - '''Test case for indexing QStringList longer than 1 string''' - - def testValid(self): - #QStringList[] for valid indexes - for i in range(self.size): - self.assertEqual(self.strings[i], self.obj[i]) - - def testNegativeValid(self): - #QStringList[] for valid indexes - for i in range(-1, -self.size, -1): - self.assertEqual(self.strings[i], self.obj[i]) - - def testInvalid(self): - #QStringList[] for invalid negative indexes - self.assertRaises(IndexError, lambda : self.obj[self.size]) - self.assertRaises(IndexError, lambda : self.obj[-(self.size+1)]) - - -class TestSlicing(UsesManyStrings): - '''Test case for slicing a QStringList''' - - def testSlicing(self): - #QStringList slicing - for i in range(self.size): - self.assertEqual(self.obj[i:], self.strings[i:]) - self.assertEqual(self.obj[:i], self.strings[:i]) - for j in range(i): - self.assertEqual(self.obj[j:i], self.strings[j:i]) - - for i in range(-1, -self.size, -1): - self.assertEqual(self.obj[:i], self.strings[:i]) - - -class TestShiftOperator(UsesManyStrings): - '''Test case for QStringList lshift operator''' - - def testShiftOperator(self): - #QStringList lshift - a = QStringList() - a << "a" << "b" << "c"; - self.assertEquals(3, a.count()) - b = ["1", "2", "3"] - c = ["4", "5", "6"] - a << b << c - self.assertEquals(9, a.count()) - - def testShiftOperator(self): - #QStringList lshift - a = QStringList() - b = ["1", 2, "3"] - self.assertRaises(TypeError, a.__lshift__, b) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/QtCore/qtextstream_test.py b/tests/QtCore/qtextstream_test.py index 13dc6516c..a8f561c04 100644 --- a/tests/QtCore/qtextstream_test.py +++ b/tests/QtCore/qtextstream_test.py @@ -3,8 +3,7 @@ import unittest -from PySide.QtCore import QTextStream, QIODevice, QString, QByteArray -from PySide.QtCore import QTextCodec, QFile +from PySide.QtCore import * class QTextStreamShiftTest(unittest.TestCase): @@ -16,18 +15,11 @@ class QTextStreamShiftTest(unittest.TestCase): def testNumber(self): '''QTextStream << number''' - self.write << QString('4') + self.write << '4' self.write.flush() res = self.read.readLine() - self.assert_(isinstance(res, QString)) - self.assertEqual(res, QString('4')) - - def testString(self): - self.write << QString('Test_it!') - self.write.flush() - res = QString() - self.read >> res - self.assertEqual(res, QString('Test_it!')) + self.assert_(isinstance(res, unicode)) + self.assertEqual(res, '4') class QTextStreamGetSet(unittest.TestCase): diff --git a/tests/QtCore/qvariant_pyobject_test.py b/tests/QtCore/qvariant_pyobject_test.py index 82da5556f..2000a0199 100644 --- a/tests/QtCore/qvariant_pyobject_test.py +++ b/tests/QtCore/qvariant_pyobject_test.py @@ -3,19 +3,17 @@ import unittest -from PySide.QtCore import QSize, QVariant, QString +from PySide.QtCore import * class Dummy(object): '''Pure python sample class''' pass - class MySize(QSize): '''Extended class''' pass - class QVariantPurePython(unittest.TestCase): '''QVariant + pure python classes''' @@ -26,7 +24,6 @@ class QVariantPurePython(unittest.TestCase): # inherited type name from other binding self.assertEqual('PyQt_PyObject', obj.typeName()) - class QVariantInheritedPython(unittest.TestCase): '''QVariant + classes inherited from C++''' @@ -63,7 +60,7 @@ class QVariantToPyObject(unittest.TestCase): '''QVariant(python string).toPyObject() return an equal QString''' d = 'abc' obj = QVariant('abc') - self.assert_(isinstance(obj.toPyObject(), QString)) + self.assert_(isinstance(obj.toPyObject(), unicode)) self.assertEqual(d, obj.toPyObject()) diff --git a/tests/QtCore/qvariant_test.py b/tests/QtCore/qvariant_test.py index 5c23b4049..6be7b8102 100644 --- a/tests/QtCore/qvariant_test.py +++ b/tests/QtCore/qvariant_test.py @@ -5,7 +5,7 @@ import unittest import sys -from PySide.QtCore import QSize, QVariant, QByteArray, QStringList, QString +from PySide.QtCore import * class QVariantToNumber(unittest.TestCase): @@ -50,11 +50,6 @@ class QVariantToNumber(unittest.TestCase): class QVariantTypeName(unittest.TestCase): '''QVariant.typeName()''' - def testTypeNameQString(self): - '''QVariant(QString).typeName()''' - obj = QVariant(QString('aaaa')) - self.assertEqual('QString', obj.typeName()) - def testTypeNameString(self): '''QVariant(PyString).typeName()''' obj = QVariant('aaaa') @@ -96,18 +91,6 @@ class QVariantTypeName(unittest.TestCase): obj = QVariant(['aaa', 'bbb', 'ccc', 'dddd']) self.assertEqual('QVariantList', obj.typeName()) - obj = QVariant([QString('aaa'), QString('bbb'), - QString('ccc'), QString('dddd')]) - self.assertEqual('QVariantList', obj.typeName()) - - def testTypeNameQStringList(self): - '''QVariant(QStringList).typeName()''' - obj = QVariant(QStringList()) - self.assertEqual('QStringList', obj.typeName()) - obj = QVariant(QStringList(['aaa', 'bbb', 'ccc'])) - self.assertEqual('QStringList', obj.typeName()) - - class QVariantConstructor(unittest.TestCase): '''More qvariant constructions''' diff --git a/tests/QtCore/translation_test.py b/tests/QtCore/translation_test.py index 870c8c50f..6b75bee36 100644 --- a/tests/QtCore/translation_test.py +++ b/tests/QtCore/translation_test.py @@ -5,7 +5,7 @@ import os import unittest -from PySide.QtCore import QObject, QTranslator, QCoreApplication, QString +from PySide.QtCore import * from helper import UsesQCoreApplication @@ -54,7 +54,7 @@ class TranslationTest(UsesQCoreApplication): def testTranslateWithNoneDisambiguation(self): value = 'String here' obj = QCoreApplication.translate('context', value, None, QCoreApplication.UnicodeUTF8) - self.assert_(isinstance(obj, QString)) + self.assert_(isinstance(obj, unicode)) self.assertEqual(obj, value) if __name__ == '__main__': diff --git a/tests/QtGui/qinputdialog_get_test.py b/tests/QtGui/qinputdialog_get_test.py index c75f71251..ce3a60dfa 100644 --- a/tests/QtGui/qinputdialog_get_test.py +++ b/tests/QtGui/qinputdialog_get_test.py @@ -15,7 +15,7 @@ class TestInputDialog(TimedQApplication): self.assertEquals(QtGui.QInputDialog.getInteger(None, "title", "label"), (0, False)) def testGetItem(self): - (item, bool) = QtGui.QInputDialog.getItem(None, "title", "label", QtCore.QStringList(["1", "2", "3"])) + (item, bool) = QtGui.QInputDialog.getItem(None, "title", "label", ["1", "2", "3"]) self.assertEquals(str(item), "1") def testGetText(self): diff --git a/tests/QtGui/qpixmap_test.py b/tests/QtGui/qpixmap_test.py index 481409462..7ba7454d4 100644 --- a/tests/QtGui/qpixmap_test.py +++ b/tests/QtGui/qpixmap_test.py @@ -16,7 +16,7 @@ class QPixmapTest(UsesQApplication): self.assert_(pixmap.size().height(), 20) def testQStringConstructor(self): - pixmap = QPixmap(QString("Testing!")) + pixmap = QPixmap("Testing!") def testQVariantConstructor2(self): v = QVariant(QPixmap()) diff --git a/tests/QtGui/qstring_qkeysequence_test.py b/tests/QtGui/qstring_qkeysequence_test.py index 1f435e6ee..15db935af 100644 --- a/tests/QtGui/qstring_qkeysequence_test.py +++ b/tests/QtGui/qstring_qkeysequence_test.py @@ -5,7 +5,7 @@ import unittest from helper import UsesQApplication -from PySide.QtCore import QString +from PySide.QtCore import * from PySide.QtGui import QKeySequence, QAction class QStringQKeySequenceTest(UsesQApplication): @@ -14,21 +14,12 @@ class QStringQKeySequenceTest(UsesQApplication): def testQStringFromQKeySequence(self): '''Creates a QString from a QKeySequence.''' keyseq = 'Ctrl+A' - a = QString(QKeySequence(keyseq)) + a = QKeySequence(keyseq) self.assertEqual(a, keyseq) - def testQStringAsQKeySequence(self): - '''Passes a QString to an argument expecting a QKeySequence.''' - keyseq = QString('Ctrl+A') - action = QAction(None) - action.setShortcut(keyseq) - shortcut = action.shortcut() - self.assert_(isinstance(shortcut, QKeySequence)) - self.assertEqual(shortcut.toString(), keyseq) - def testPythonStringAsQKeySequence(self): '''Passes a Python string to an argument expecting a QKeySequence.''' - keyseq = 'Ctrl+A' + keyseq = u'Ctrl+A' action = QAction(None) action.setShortcut(keyseq) shortcut = action.shortcut() diff --git a/tests/QtSql/qsqldatabaseandqueries_test.py b/tests/QtSql/qsqldatabaseandqueries_test.py index 49f220937..2d5a0a3e8 100755 --- a/tests/QtSql/qsqldatabaseandqueries_test.py +++ b/tests/QtSql/qsqldatabaseandqueries_test.py @@ -5,14 +5,14 @@ import sys import unittest from PySide import QtSql -from PySide.QtCore import QVariant, QString +from PySide.QtCore import * class SqlDatabaseCreationDestructionAndQueries(unittest.TestCase): '''Test cases for QtSql database creation, destruction and queries''' def setUp(self): #Acquire resources - self.assertFalse(QtSql.QSqlDatabase.drivers().isEmpty(), "installed Qt has no DB drivers") + self.assertFalse(not QtSql.QSqlDatabase.drivers(), "installed Qt has no DB drivers") self.assertTrue("QSQLITE" in QtSql.QSqlDatabase.drivers(), "\"QSQLITE\" driver not available in this Qt version") self.db = QtSql.QSqlDatabase.addDatabase("QSQLITE") self.db.setDatabaseName(":memory:") diff --git a/tests/phonon/capabilities_test.py b/tests/phonon/capabilities_test.py index 5f4b7da83..99c647373 100644 --- a/tests/phonon/capabilities_test.py +++ b/tests/phonon/capabilities_test.py @@ -1,7 +1,7 @@ import unittest -from PySide.QtCore import QString +from PySide.QtCore import * from PySide import phonon from helper import UsesQCoreApplication @@ -36,7 +36,7 @@ class CapabilitiesTest(UsesQCoreApplication): # TODO Improve this test mimeTypes = phonon.Phonon.BackendCapabilities.availableMimeTypes() for mime in mimeTypes: - self.assert_(isinstance(mime, QString)) + self.assert_(isinstance(mime, unicode)) def testAudioEffects(self): # TODO Improve this test diff --git a/tests/signals/decorators_test.py b/tests/signals/decorators_test.py index db068d009..db32ec9b0 100755 --- a/tests/signals/decorators_test.py +++ b/tests/signals/decorators_test.py @@ -24,7 +24,7 @@ class MyObject(QObject): def foo(self): self._slotCalledCount = self._slotCalledCount + 1 - @Slot(QString, int) + @Slot(unicode, int) def mySlot4(self, a, b): self._slotCalledCount = self._slotCalledCount + 1 @@ -41,7 +41,7 @@ class StaticMetaObjectTest(unittest.TestCase): self.assert_(m.indexOfSlot('mySlot2(int)') > 0) self.assert_(m.indexOfSlot('mySlot2(QString)') > 0) self.assert_(m.indexOfSlot('mySlot3()') > 0) - self.assert_(m.indexOfSlot('mySlot4(QString,int)') > 0) + self.assert_(m.indexOfSlot('mySlot4(unicode,int)') > 0) def testEmission(self): o = MyObject() diff --git a/tests/signals/signal_object_test.py b/tests/signals/signal_object_test.py index 614c0e602..d36665cf6 100755 --- a/tests/signals/signal_object_test.py +++ b/tests/signals/signal_object_test.py @@ -11,8 +11,8 @@ class MyObject(QTimer): sig1 = Signal() sig2 = Signal(int, name='rangeChanged') sig3 = Signal(int) - sig4 = Signal((int,), (QString,)) - sig5 = Signal((QString,), (int,)) + sig4 = Signal((int,), (unicode,)) + sig5 = Signal((unicode,), (int,)) @Slot(int) @@ -50,8 +50,8 @@ class SignalObjectTest(UsesQCoreApplication): def testDictOperator(self): o = MyObject() - o.sig4[QString].connect(o.slotString) - o.sig4[QString].emit("PySide") + o.sig4[unicode].connect(o.slotString) + o.sig4[unicode].emit("PySide") self.assertEqual(o._s, "PySide") def testGeneretedSignal(self): -- cgit v1.2.3