diff options
Diffstat (limited to 'sources/shiboken2/tests')
156 files changed, 1551 insertions, 243 deletions
diff --git a/sources/shiboken2/tests/CMakeLists.txt b/sources/shiboken2/tests/CMakeLists.txt index 464707a9a..375215369 100644 --- a/sources/shiboken2/tests/CMakeLists.txt +++ b/sources/shiboken2/tests/CMakeLists.txt @@ -45,25 +45,15 @@ endif() if(CMAKE_VERSION VERSION_LESS 2.8) message("CMake version greater than 2.8 necessary to run tests") else() - if(WIN32) - set(TEST_PYTHONPATH "${smart_BINARY_DIR};${minimal_BINARY_DIR};${sample_BINARY_DIR};${other_BINARY_DIR};${shibokenmodule_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}") - set(TEST_LIBRARY_PATH "$ENV{PATH};${libminimal_BINARY_DIR};${libsample_BINARY_DIR};${libother_BINARY_DIR};${libsmart_BINARY_DIR};${libshiboken_BINARY_DIR}") - set(LIBRARY_PATH_VAR "PATH") - string(REPLACE "\\" "/" TEST_PYTHONPATH "${TEST_PYTHONPATH}") - string(REPLACE "\\" "/" TEST_LIBRARY_PATH "${TEST_LIBRARY_PATH}") - string(REPLACE ";" "\\;" TEST_PYTHONPATH "${TEST_PYTHONPATH}") - string(REPLACE ";" "\\;" TEST_LIBRARY_PATH "${TEST_LIBRARY_PATH}") - else() - set(TEST_PYTHONPATH "${smart_BINARY_DIR}:${minimal_BINARY_DIR}:${sample_BINARY_DIR}:${other_BINARY_DIR}:${shibokenmodule_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR}") - set(TEST_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}:${libminimal_BINARY_DIR}:${libsample_BINARY_DIR}:${libother_BINARY_DIR}:${libsmart_BINARY_DIR}:${libshiboken_BINARY_DIR}") - set(LIBRARY_PATH_VAR "LD_LIBRARY_PATH") - endif() + get_filename_component(BUILD_DIR "${libminimal_BINARY_DIR}" DIRECTORY) + get_filename_component(BUILD_DIR "${BUILD_DIR}" DIRECTORY) + get_filename_component(BUILD_DIR "${BUILD_DIR}" DIRECTORY) foreach(test_file ${TEST_FILES}) string(REGEX MATCH "/([^/]+)(binding|module)/([^/]+)_test.py" tmp ${test_file}) set(test_name "${CMAKE_MATCH_1}_${CMAKE_MATCH_3}") list(FIND test_blacklist ${test_name} expect_fail) add_test(${test_name} ${PYTHON_EXECUTABLE} ${test_file}) - set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "PYTHONPATH=${TEST_PYTHONPATH};${LIBRARY_PATH_VAR}=${TEST_LIBRARY_PATH}") + set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "BUILD_DIR=${BUILD_DIR}") set_tests_properties(${test_name} PROPERTIES TIMEOUT ${CTEST_TESTING_TIMEOUT}) if (${expect_fail} GREATER -1) set_tests_properties(${test_name} PROPERTIES WILL_FAIL TRUE) diff --git a/sources/shiboken2/tests/dumpcodemodel/main.cpp b/sources/shiboken2/tests/dumpcodemodel/main.cpp index e132c97b3..52d64be94 100644 --- a/sources/shiboken2/tests/dumpcodemodel/main.cpp +++ b/sources/shiboken2/tests/dumpcodemodel/main.cpp @@ -33,9 +33,11 @@ #include <QtCore/QCoreApplication> #include <QtCore/QCommandLineOption> #include <QtCore/QCommandLineParser> +#include <QtCore/QDateTime> #include <QtCore/QDebug> #include <QtCore/QDir> #include <QtCore/QFile> +#include <QtCore/QXmlStreamWriter> #include <iostream> #include <algorithm> @@ -48,23 +50,146 @@ static inline QString languageLevelDescription() + QLatin1Char(')'); } +static void formatDebugOutput(const FileModelItem &dom, bool verbose) +{ + QString output; + { + QDebug debug(&output); + if (verbose) + debug.setVerbosity(3); + debug << dom.data(); + } + std::cout << qPrintable(output) << '\n'; +} + +static const char *primitiveTypes[] = { + "int", "unsigned", "short", "unsigned short", "long", "unsigned long", + "float", "double" +}; + +static inline QString nameAttribute() { return QStringLiteral("name"); } + +static void formatXmlNamespace(QXmlStreamWriter &writer, const NamespaceModelItem &nsp); +static void formatXmlClass(QXmlStreamWriter &writer, const ClassModelItem &klass); + +static void formatXmlEnum(QXmlStreamWriter &writer, const EnumModelItem &en) +{ + writer.writeStartElement(QStringLiteral("enum-type")); + writer.writeAttribute(nameAttribute(), en->name()); + writer.writeEndElement(); +} + +static void formatXmlScopeMembers(QXmlStreamWriter &writer, const ScopeModelItem &nsp) +{ + for (const auto &klass : nsp->classes()) { + if (klass->classType() != CodeModel::Union && klass->templateParameters().isEmpty()) + formatXmlClass(writer, klass); + } + for (const auto &en : nsp->enums()) + formatXmlEnum(writer, en); +} + +static bool isPublicCopyConstructor(const FunctionModelItem &f) +{ + return f->functionType() == CodeModel::CopyConstructor + && f->accessPolicy() == CodeModel::Public && !f->isDeleted(); +} + +static void formatXmlClass(QXmlStreamWriter &writer, const ClassModelItem &klass) +{ + // Heuristics for value types: check on public copy constructors. + const auto functions = klass->functions(); + const bool isValueType = std::any_of(functions.cbegin(), functions.cend(), + isPublicCopyConstructor); + writer.writeStartElement(isValueType ? QStringLiteral("value-type") + : QStringLiteral("object-type")); + writer.writeAttribute(nameAttribute(), klass->name()); + formatXmlScopeMembers(writer, klass); + writer.writeEndElement(); +} + +static void formatXmlNamespaceMembers(QXmlStreamWriter &writer, const NamespaceModelItem &nsp) +{ + for (const auto &nested : nsp->namespaces()) + formatXmlNamespace(writer, nested); + for (auto func : nsp->functions()) { + const QString signature = func->typeSystemSignature(); + if (!signature.contains(QLatin1String("operator"))) { // Skip free operators + writer.writeStartElement(QStringLiteral("function")); + writer.writeAttribute(QStringLiteral("signature"), signature); + writer.writeEndElement(); + } + } + formatXmlScopeMembers(writer, nsp); +} + +static void formatXmlNamespace(QXmlStreamWriter &writer, const NamespaceModelItem &nsp) +{ + writer.writeStartElement(QStringLiteral("namespace-type")); + writer.writeAttribute(nameAttribute(), nsp->name()); + formatXmlNamespaceMembers(writer, nsp); + writer.writeEndElement(); +} + +static void formatXmlOutput(const FileModelItem &dom) +{ + QString output; + QXmlStreamWriter writer(&output); + writer.setAutoFormatting(true); + writer.writeStartDocument(); + writer.writeStartElement(QStringLiteral("typesystem")); + writer.writeAttribute(QStringLiteral("package"), QStringLiteral("insert_name")); + writer.writeComment(QStringLiteral("Auto-generated ") + + QDateTime::currentDateTime().toString(Qt::ISODate)); + for (auto p : primitiveTypes) { + writer.writeStartElement(QStringLiteral("primitive-type")); + writer.writeAttribute(nameAttribute(), QLatin1String(p)); + writer.writeEndElement(); + } + formatXmlNamespaceMembers(writer, dom); + writer.writeEndElement(); + writer.writeEndDocument(); + std::cout << qPrintable(output) << '\n'; +} + +static const char descriptionFormat[] = R"( +Type system dumper + +Parses a C++ header and dumps out the classes found in typesystem XML syntax. +Arguments are arguments to the compiler the last of which should be the header +or source file. +It is recommended to create a .hh include file including the desired headers +and pass that along with the required include paths. + +Based on Qt %1 and LibClang v%2.)"; + int main(int argc, char **argv) { QCoreApplication app(argc, argv); QCommandLineParser parser; parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); - parser.setApplicationDescription(QStringLiteral("Code model tester")); + parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments); + const QString description = + QString::fromLatin1(descriptionFormat).arg(QLatin1String(qVersion()), + clang::libClangVersion().toString()); + parser.setApplicationDescription(description); parser.addHelpOption(); parser.addVersionOption(); - QCommandLineOption verboseOption(QStringLiteral("d"), + QCommandLineOption verboseOption(QStringLiteral("verbose"), QStringLiteral("Display verbose output about types")); parser.addOption(verboseOption); + QCommandLineOption debugOption(QStringLiteral("debug"), + QStringLiteral("Display debug output")); + parser.addOption(debugOption); + QCommandLineOption languageLevelOption(QStringLiteral("std"), languageLevelDescription(), QStringLiteral("level")); parser.addOption(languageLevelOption); - parser.addPositionalArgument(QStringLiteral("file"), QStringLiteral("C++ source file")); + parser.addPositionalArgument(QStringLiteral("argument"), + QStringLiteral("C++ compiler argument"), + QStringLiteral("argument(s)")); parser.process(app); const QStringList &positionalArguments = parser.positionalArguments(); @@ -93,14 +218,10 @@ int main(int argc, char **argv) return -2; } - QString output; - { - QDebug debug(&output); - if (parser.isSet(verboseOption)) - debug.setVerbosity(3); - debug << dom.data(); - } - std::cout << qPrintable(output) << '\n'; + if (parser.isSet(debugOption)) + formatDebugOutput(dom, parser.isSet(verboseOption)); + else + formatXmlOutput(dom); return 0; } diff --git a/sources/shiboken2/tests/libsample/modifications.cpp b/sources/shiboken2/tests/libsample/modifications.cpp index 98b22f09b..56ba81875 100644 --- a/sources/shiboken2/tests/libsample/modifications.cpp +++ b/sources/shiboken2/tests/libsample/modifications.cpp @@ -149,3 +149,19 @@ Modifications::nonConversionRuleForArgumentWithDefaultValue(ObjectType** object) *object = m_object; return true; } + +void Modifications::setEnumValue(TestEnum e) +{ + m_enumValue = e; +} + +Modifications::TestEnum Modifications::enumValue() const +{ + return m_enumValue; +} + +Modifications::TestEnum Modifications::defaultEnumValue() const +{ + return TestEnumValue2; +} + diff --git a/sources/shiboken2/tests/libsample/modifications.h b/sources/shiboken2/tests/libsample/modifications.h index fa32bdec3..674a05f27 100644 --- a/sources/shiboken2/tests/libsample/modifications.h +++ b/sources/shiboken2/tests/libsample/modifications.h @@ -51,6 +51,11 @@ public: Overloaded_ibPP }; + enum TestEnum { + TestEnumValue1, + TestEnumValue2 + }; + // those overloaded methods should be heavily modified // to push the overload decisor to its limits inline OverloadedModFunc overloaded(int a0, bool b0, int c0, double d0) { return Overloaded_ibid; } @@ -123,8 +128,13 @@ public: // Inject code with a %CONVERTTOPYTHON that receives an user's primitive type. static inline OddBool passOddBool(OddBool ob) { return ob; } + void setEnumValue(TestEnum e = TestEnumValue1); + TestEnum enumValue() const; + TestEnum defaultEnumValue() const; + private: ObjectType* m_object; + TestEnum m_enumValue = TestEnumValue1; }; class LIBSAMPLE_API AbstractModifications : public Modifications diff --git a/sources/shiboken2/tests/libsample/pen.cpp b/sources/shiboken2/tests/libsample/pen.cpp index d30071f49..b08721f79 100644 --- a/sources/shiboken2/tests/libsample/pen.cpp +++ b/sources/shiboken2/tests/libsample/pen.cpp @@ -65,3 +65,7 @@ int Pen::ctorType() { return m_ctor; } + +void Pen::drawLine(int x1, int y1, int x2, int y2, RenderHints renderHints) +{ +} diff --git a/sources/shiboken2/tests/libsample/pen.h b/sources/shiboken2/tests/libsample/pen.h index ca079198b..6b3bf9f1a 100644 --- a/sources/shiboken2/tests/libsample/pen.h +++ b/sources/shiboken2/tests/libsample/pen.h @@ -49,11 +49,16 @@ class LIBSAMPLE_API Pen public: enum { EmptyCtor, EnumCtor, ColorCtor, CopyCtor }; + enum RenderHints { None = 0, Antialiasing = 0x1, TextAntialiasing = 0x2 }; + Pen(); Pen(SampleNamespace::Option option); Pen(const Color& color); Pen(const Pen& pen); + // PYSIDE-1325, default initializer + void drawLine(int x1, int y1, int x2, int y2, RenderHints renderHints = {}); + int ctorType(); private: int m_ctor; diff --git a/sources/shiboken2/tests/libsmart/smart.cpp b/sources/shiboken2/tests/libsmart/smart.cpp index 8d85d67a1..6a4deb50a 100644 --- a/sources/shiboken2/tests/libsmart/smart.cpp +++ b/sources/shiboken2/tests/libsmart/smart.cpp @@ -28,10 +28,52 @@ #include "smart.h" -bool shouldPrint() { +#include <algorithm> +#include <iostream> + +static inline bool shouldPrint() +{ return Registry::getInstance()->shouldPrint(); } +void SharedPtrBase::logDefaultConstructor(const void *t) +{ + if (shouldPrint()) + std::cout << "shared_ptr default constructor " << t << '\n'; +} + +void SharedPtrBase::logConstructor(const void *t, const void *pointee) +{ + if (shouldPrint()) { + std::cout << "shared_ptr constructor " << t << " with pointer " + << pointee << '\n'; + } +} + +void SharedPtrBase::logCopyConstructor(const void *t, const void *refData) +{ + if (shouldPrint()) { + std::cout << "shared_ptr copy constructor " << t << " with pointer " + << refData << '\n'; + } +} + +void SharedPtrBase::logAssignment(const void *t, const void *refData) +{ + if (shouldPrint()) { + std::cout << "shared_ptr assignment operator " << t << " with pointer " + << refData << "\n"; + } +} + +void SharedPtrBase::logDestructor(const void *t, int remainingRefCount) +{ + if (shouldPrint()) { + std::cout << "shared_ptr destructor " << t << " remaining refcount " + << remainingRefCount << '\n'; + } +} + Obj::Obj() : m_integer(123), m_internalInteger(new Integer) { Registry::getInstance()->add(this); @@ -143,10 +185,9 @@ Registry *Registry::getInstance() return ®istry; } -Registry::Registry() : m_printStuff(false) -{ +Registry::Registry() = default; -} +Registry::~Registry() = default; void Registry::add(Obj *p) { diff --git a/sources/shiboken2/tests/libsmart/smart.h b/sources/shiboken2/tests/libsmart/smart.h index 3347b22c1..6238f27d5 100644 --- a/sources/shiboken2/tests/libsmart/smart.h +++ b/sources/shiboken2/tests/libsmart/smart.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of Qt for Python. @@ -29,193 +29,9 @@ #ifndef SMART_H #define SMART_H -#include <algorithm> -#include <iostream> -#include <vector> - -#include "libsmartmacros.h" - -// Forward declarations. -template <class T> -class SharedPtr; -class Integer; -class Obj; - -LIB_SMART_API bool shouldPrint(); - -// Used to track which C++ objects are alive. -class LIB_SMART_API Registry { -public: - static Registry *getInstance(); - - void add(Obj *p); - void add(Integer *p); - void remove(Obj *p); - void remove(Integer *p); - int countObjects() const; - int countIntegers() const; - bool shouldPrint() const; - void setShouldPrint(bool flag); - -protected: - Registry(); - -private: - bool m_printStuff; - std::vector<Obj *> m_objects; - std::vector<Integer *> m_integers; -}; - -template <class T> -class RefData { -public: - RefData(T *ptr) : m_refCount(1), m_heldPtr(ptr) {} - ~RefData() { delete m_heldPtr; } - int inc() { return ++m_refCount; } - int dec() { return --m_refCount; } - int useCount() { return m_refCount; } - int m_refCount; - T *m_heldPtr; -}; - -template <class T> -class SharedPtr { -public: - SharedPtr() : m_refData(nullptr) { - if (shouldPrint()) - std::cout << "shared_ptr default constructor " << this << "\n"; - } - - SharedPtr(T *v) - { - if (shouldPrint()) - std::cout << "shared_ptr constructor " << this << " with pointer " << v << "\n"; - if (v) - m_refData = new RefData<T>(v); - } - - SharedPtr(const SharedPtr<T> &other) : m_refData(other.m_refData) - { - if (shouldPrint()) - std::cout << "shared_ptr copy constructor " << this << " with pointer " - << other.m_refData << "\n"; - if (m_refData) - m_refData->inc(); - } - - SharedPtr<T> &operator=(const SharedPtr<T>& other) - { - if (this != &other) { - if (shouldPrint()) - std::cout << "shared_ptr assignment operator " << this << " with pointer " - << other.m_refData << "\n"; - if (m_refData && m_refData->dec() == 0) - delete m_refData; - m_refData = other.m_refData; - if (m_refData) - m_refData->inc(); - } - return *this; - } - - T *data() const - { - if (m_refData) - return m_refData->m_heldPtr; - return nullptr; - } - - int useCount() const - { - if (m_refData) - return m_refData->useCount(); - return 0; - } - - void dummyMethod1() - { - - } - - T& operator*() const - { - // Crashes if smart pointer is empty (just like std::shared_ptr). - return *(m_refData->m_heldPtr); - } - - T *operator->() const - { - if (m_refData) - return m_refData->m_heldPtr; - return nullptr; - } - - bool operator!() const - { - return !m_refData || !m_refData->m_heldPtr; - } - - bool isNull() const - { - return !m_refData || !m_refData->m_heldPtr; - } - - operator bool() const - { - return m_refData && m_refData->m_heldPtr; - } - - ~SharedPtr() - { - if (m_refData) { - if (shouldPrint()) - std::cout << "shared_ptr destructor " << this << " remaining refcount " - << m_refData->useCount() - 1 << "\n"; - } - if (m_refData && m_refData->dec() == 0) - delete m_refData; - } - - RefData<T> *m_refData; -}; - -class LIB_SMART_API Integer { -public: - Integer(); - Integer(const Integer &other); - Integer &operator=(const Integer &other); - ~Integer(); - void printInteger(); - int m_int; -}; - -namespace Smart { -class LIB_SMART_API Integer2 : public Integer { -public: - Integer2(); - Integer2(const Integer2 &other); -}; -} - - -// Couldn't name it Object because it caused some namespace clashes. -class LIB_SMART_API Obj { -public: - Obj(); - virtual ~Obj(); - - void printObj(); - Integer takeInteger(Integer val); - SharedPtr<Obj> giveSharedPtrToObj(); - std::vector<SharedPtr<Obj> > giveSharedPtrToObjList(int size); - SharedPtr<Integer> giveSharedPtrToInteger(); - SharedPtr<Smart::Integer2> giveSharedPtrToInteger2(); - int takeSharedPtrToObj(SharedPtr<Obj> pObj); - int takeSharedPtrToInteger(SharedPtr<Integer> pInt); - - int m_integer; - Integer *m_internalInteger; -}; +#include "smart_sharedptr.h" +#include "smart_integer.h" +#include "smart_obj.h" +#include "smart_registry.h" #endif // SMART_H - diff --git a/sources/shiboken2/tests/libsmart/smart_integer.h b/sources/shiboken2/tests/libsmart/smart_integer.h new file mode 100644 index 000000000..3756f68b0 --- /dev/null +++ b/sources/shiboken2/tests/libsmart/smart_integer.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SMART_INTEGER_H +#define SMART_INTEGER_H + +#include "libsmartmacros.h" + +class LIB_SMART_API Integer { +public: + Integer(); + Integer(const Integer &other); + Integer &operator=(const Integer &other); + ~Integer(); + void printInteger(); + int m_int; +}; + +namespace Smart { +class LIB_SMART_API Integer2 : public Integer { +public: + Integer2(); + Integer2(const Integer2 &other); +}; +} // namespace Smart + +#endif // SMART_INTEGER_H diff --git a/sources/shiboken2/tests/libsmart/smart_obj.h b/sources/shiboken2/tests/libsmart/smart_obj.h new file mode 100644 index 000000000..12425366e --- /dev/null +++ b/sources/shiboken2/tests/libsmart/smart_obj.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SMART_OBJ_H +#define SMART_OBJ_H + +#include "libsmartmacros.h" +#include "smart_sharedptr.h" + +#include <vector> + +class Integer; +class Obj; +namespace Smart { class Integer2; } + +// Couldn't name it Object because it caused some namespace clashes. +class LIB_SMART_API Obj { +public: + Obj(); + virtual ~Obj(); + + void printObj(); + Integer takeInteger(Integer val); + SharedPtr<Obj> giveSharedPtrToObj(); + std::vector<SharedPtr<Obj> > giveSharedPtrToObjList(int size); + SharedPtr<Integer> giveSharedPtrToInteger(); + SharedPtr<Smart::Integer2> giveSharedPtrToInteger2(); + int takeSharedPtrToObj(SharedPtr<Obj> pObj); + int takeSharedPtrToInteger(SharedPtr<Integer> pInt); + + int m_integer; + Integer *m_internalInteger; +}; + +#endif // SMART_OBJ_H diff --git a/sources/shiboken2/tests/libsmart/smart_registry.h b/sources/shiboken2/tests/libsmart/smart_registry.h new file mode 100644 index 000000000..6171ddb59 --- /dev/null +++ b/sources/shiboken2/tests/libsmart/smart_registry.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SMART_REGISTRY_H +#define SMART_REGISTRY_H + +#include <vector> + +#include "libsmartmacros.h" + +class Obj; +class Integer; + +// Used to track which C++ objects are alive. +class LIB_SMART_API Registry { +public: + static Registry *getInstance(); + ~Registry(); + + Registry(const Registry &) = delete; + Registry &operator=(const Registry &) = delete; + Registry(Registry &&) = delete; + Registry &operator=(Registry &&) = delete; + + void add(Obj *p); + void add(Integer *p); + void remove(Obj *p); + void remove(Integer *p); + int countObjects() const; + int countIntegers() const; + bool shouldPrint() const; + void setShouldPrint(bool flag); + +protected: + Registry(); + +private: + std::vector<Obj *> m_objects; + std::vector<Integer *> m_integers; + bool m_printStuff = false; +}; + +#endif // SMART_REGISTRY_H diff --git a/sources/shiboken2/tests/libsmart/smart_sharedptr.h b/sources/shiboken2/tests/libsmart/smart_sharedptr.h new file mode 100644 index 000000000..84184e1f8 --- /dev/null +++ b/sources/shiboken2/tests/libsmart/smart_sharedptr.h @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SMART_SHARED_PTR_H +#define SMART_SHARED_PTR_H + +#include "libsmartmacros.h" + +template <class T> +class RefData { +public: + RefData(T *ptr) : m_refCount(1), m_heldPtr(ptr) {} + ~RefData() { delete m_heldPtr; } + int inc() { return ++m_refCount; } + int dec() { return --m_refCount; } + int useCount() { return m_refCount; } + int m_refCount; + T *m_heldPtr; +}; + +struct SharedPtrBase +{ + LIB_SMART_API static void logDefaultConstructor(const void *t); + LIB_SMART_API static void logConstructor(const void *t, const void *pointee); + LIB_SMART_API static void logCopyConstructor(const void *t, const void *refData); + LIB_SMART_API static void logAssignment(const void *t, const void *refData); + LIB_SMART_API static void logDestructor(const void *t, int remainingRefCount); +}; + +template <class T> +class SharedPtr : public SharedPtrBase { +public: + SharedPtr() { logDefaultConstructor(this); } + + SharedPtr(T *v) + { + logConstructor(this, v); + if (v) + m_refData = new RefData<T>(v); + } + + SharedPtr(const SharedPtr<T> &other) : m_refData(other.m_refData) + { + logCopyConstructor(this, other.m_refData); + if (m_refData) + m_refData->inc(); + } + + SharedPtr<T> &operator=(const SharedPtr<T>& other) + { + if (this != &other) { + logAssignment(this, other.m_refData); + if (m_refData && m_refData->dec() == 0) + delete m_refData; + m_refData = other.m_refData; + if (m_refData) + m_refData->inc(); + } + return *this; + } + + T *data() const + { + return m_refData ? m_refData->m_heldPtr : nullptr; + } + + int useCount() const + { + return m_refData ? m_refData->useCount() : 0; + } + + void dummyMethod1() + { + + } + + T& operator*() const + { + // Crashes if smart pointer is empty (just like std::shared_ptr). + return *(m_refData->m_heldPtr); + } + + T *operator->() const + { + return m_refData ? m_refData->m_heldPtr : nullptr; + } + + bool operator!() const + { + return !m_refData || !m_refData->m_heldPtr; + } + + bool isNull() const + { + return !m_refData || !m_refData->m_heldPtr; + } + + operator bool() const + { + return m_refData && m_refData->m_heldPtr; + } + + ~SharedPtr() + { + if (m_refData) + logDestructor(this, m_refData->useCount() - 1); + if (m_refData && m_refData->dec() == 0) + delete m_refData; + } + +private: + RefData<T> *m_refData = nullptr; +}; + +#endif // SMART_SHARED_PTR_H diff --git a/sources/shiboken2/tests/minimalbinding/brace_pattern_test.py b/sources/shiboken2/tests/minimalbinding/brace_pattern_test.py index 89df998e8..e48027d2a 100644 --- a/sources/shiboken2/tests/minimalbinding/brace_pattern_test.py +++ b/sources/shiboken2/tests/minimalbinding/brace_pattern_test.py @@ -39,15 +39,19 @@ from __future__ import absolute_import, print_function +import os import re import sys -import os +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import shiboken2 type.__signature__ # trigger bootstrap from shibokensupport.signature.lib.tool import build_brace_pattern -import unittest """ This test tests the brace pattern from signature.lib.tool diff --git a/sources/shiboken2/tests/minimalbinding/listuser_test.py b/sources/shiboken2/tests/minimalbinding/listuser_test.py index 52ba9781f..e69bce346 100644 --- a/sources/shiboken2/tests/minimalbinding/listuser_test.py +++ b/sources/shiboken2/tests/minimalbinding/listuser_test.py @@ -29,7 +29,14 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from minimal import ListUser, Val, Obj from py3kcompat import IS_PY3K diff --git a/sources/shiboken2/tests/minimalbinding/minbool_test.py b/sources/shiboken2/tests/minimalbinding/minbool_test.py index 020e9a41f..adc0929fd 100644 --- a/sources/shiboken2/tests/minimalbinding/minbool_test.py +++ b/sources/shiboken2/tests/minimalbinding/minbool_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from minimal import MinBoolUser class DerivedMinBoolUser (MinBoolUser): diff --git a/sources/shiboken2/tests/minimalbinding/obj_test.py b/sources/shiboken2/tests/minimalbinding/obj_test.py index b97f8b1d2..a0869a67b 100644 --- a/sources/shiboken2/tests/minimalbinding/obj_test.py +++ b/sources/shiboken2/tests/minimalbinding/obj_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from minimal import Obj class ExtObj(Obj): diff --git a/sources/shiboken2/tests/minimalbinding/typedef_test.py b/sources/shiboken2/tests/minimalbinding/typedef_test.py index e58337060..6595d0467 100644 --- a/sources/shiboken2/tests/minimalbinding/typedef_test.py +++ b/sources/shiboken2/tests/minimalbinding/typedef_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from minimal import * from py3kcompat import IS_PY3K diff --git a/sources/shiboken2/tests/minimalbinding/val_test.py b/sources/shiboken2/tests/minimalbinding/val_test.py index 7a10f29a1..f97e9487d 100644 --- a/sources/shiboken2/tests/minimalbinding/val_test.py +++ b/sources/shiboken2/tests/minimalbinding/val_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from minimal import Val diff --git a/sources/shiboken2/tests/otherbinding/collector_external_operator_test.py b/sources/shiboken2/tests/otherbinding/collector_external_operator_test.py index b65663f9d..6014b8a59 100644 --- a/sources/shiboken2/tests/otherbinding/collector_external_operator_test.py +++ b/sources/shiboken2/tests/otherbinding/collector_external_operator_test.py @@ -31,8 +31,14 @@ '''Test cases for Collector shift operators defined in other modules.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Collector, ObjectType from other import OtherObjectType diff --git a/sources/shiboken2/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py b/sources/shiboken2/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py index 2aba4bd09..1e992ebc8 100755..100644 --- a/sources/shiboken2/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py +++ b/sources/shiboken2/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py @@ -33,8 +33,14 @@ being that the latter defines a new conversion operator for the former, and this one has no implicit conversions.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import NoImplicitConversion from other import ExtendsNoImplicitConversion diff --git a/sources/shiboken2/tests/otherbinding/extended_multiply_operator_test.py b/sources/shiboken2/tests/otherbinding/extended_multiply_operator_test.py index 0c58fbf5b..5ad4763b7 100755..100644 --- a/sources/shiboken2/tests/otherbinding/extended_multiply_operator_test.py +++ b/sources/shiboken2/tests/otherbinding/extended_multiply_operator_test.py @@ -31,8 +31,14 @@ '''Test cases for libsample's Point multiply operator defined in libother module.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Point from other import Number diff --git a/sources/shiboken2/tests/otherbinding/module_reload_test.py b/sources/shiboken2/tests/otherbinding/module_reload_test.py index 0010130f9..368425cd0 100644 --- a/sources/shiboken2/tests/otherbinding/module_reload_test.py +++ b/sources/shiboken2/tests/otherbinding/module_reload_test.py @@ -30,10 +30,14 @@ ############################################################################# import os -import sys import shutil +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from py3kcompat import IS_PY3K if IS_PY3K: diff --git a/sources/shiboken2/tests/otherbinding/new_ctor_operator_test.py b/sources/shiboken2/tests/otherbinding/new_ctor_operator_test.py index 09988496a..84dfe9839 100755..100644 --- a/sources/shiboken2/tests/otherbinding/new_ctor_operator_test.py +++ b/sources/shiboken2/tests/otherbinding/new_ctor_operator_test.py @@ -31,8 +31,14 @@ '''Tests calling Str constructor using a Number parameter, being that number defines a cast operator to Str.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Str from other import Number diff --git a/sources/shiboken2/tests/otherbinding/objtypehashes_test.py b/sources/shiboken2/tests/otherbinding/objtypehashes_test.py index a52957481..92f93a090 100644 --- a/sources/shiboken2/tests/otherbinding/objtypehashes_test.py +++ b/sources/shiboken2/tests/otherbinding/objtypehashes_test.py @@ -26,7 +26,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import * from other import * import shiboken2 as shiboken diff --git a/sources/shiboken2/tests/otherbinding/otherderived_test.py b/sources/shiboken2/tests/otherbinding/otherderived_test.py index e6ed761b4..d8dc9b686 100644 --- a/sources/shiboken2/tests/otherbinding/otherderived_test.py +++ b/sources/shiboken2/tests/otherbinding/otherderived_test.py @@ -31,9 +31,14 @@ '''Test cases for OtherDerived class''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Abstract, Derived from other import OtherDerived, Number diff --git a/sources/shiboken2/tests/otherbinding/typediscovery_test.py b/sources/shiboken2/tests/otherbinding/typediscovery_test.py index a9eb88d80..200d091b0 100644 --- a/sources/shiboken2/tests/otherbinding/typediscovery_test.py +++ b/sources/shiboken2/tests/otherbinding/typediscovery_test.py @@ -31,8 +31,14 @@ '''Test cases for type discovery''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Abstract, Base1, Derived, MDerived1, MDerived3, SonOfMDerived1 from other import OtherMultipleDerived diff --git a/sources/shiboken2/tests/otherbinding/usersprimitivefromothermodule_test.py b/sources/shiboken2/tests/otherbinding/usersprimitivefromothermodule_test.py index fe13cf601..a69ee23f0 100755..100644 --- a/sources/shiboken2/tests/otherbinding/usersprimitivefromothermodule_test.py +++ b/sources/shiboken2/tests/otherbinding/usersprimitivefromothermodule_test.py @@ -31,7 +31,13 @@ '''Tests user defined primitive type from a required module.''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from other import Number class UserDefinedPrimitiveTypeFromRequiredModuleTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/otherbinding/wrongctor_test.py b/sources/shiboken2/tests/otherbinding/wrongctor_test.py index 15f43d0ca..29d085315 100644 --- a/sources/shiboken2/tests/otherbinding/wrongctor_test.py +++ b/sources/shiboken2/tests/otherbinding/wrongctor_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import * from other import * diff --git a/sources/shiboken2/tests/py3kcompat.py b/sources/shiboken2/tests/py3kcompat.py index 065208994..357ea4fba 100644 --- a/sources/shiboken2/tests/py3kcompat.py +++ b/sources/shiboken2/tests/py3kcompat.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# + ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -28,21 +28,39 @@ ## ############################################################################# +# Copy of ../../pyside2/tests/util/py3kcompat.py + import sys IS_PY3K = sys.version_info[0] == 3 if IS_PY3K: - def unicode(s): - return s - def b(s): + if type(s) == bytes: + return s return bytes(s, "UTF8") + def buffer_(s): + if s == None: + return None + elif type(s) == str: + return bytes(s, "UTF8") + elif type(s) == bytes: + return s + else: + memoryview(s) + def l(n): return n + def unicode_(s): + return s + + unicode = str + unichr = chr long = int + unichr = chr + buffer = buffer_ else: def b(s): return s @@ -50,5 +68,15 @@ else: def l(n): return long(n) + def unicode_(s): + if type(s) == str: + import codecs + c = codecs.lookup('utf-8') + s2 = c.decode(s, 'ignore') + return s2[0] + return u'%s' % s + unicode = unicode + unichr = unichr long = long + buffer = buffer diff --git a/sources/shiboken2/tests/samplebinding/__del___test.py b/sources/shiboken2/tests/samplebinding/__del___test.py index 0f34ebb27..eba837eb8 100644 --- a/sources/shiboken2/tests/samplebinding/__del___test.py +++ b/sources/shiboken2/tests/samplebinding/__del___test.py @@ -29,7 +29,14 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + import sample delCalled = False diff --git a/sources/shiboken2/tests/samplebinding/abstract_test.py b/sources/shiboken2/tests/samplebinding/abstract_test.py index 33358ad2a..23a984870 100644 --- a/sources/shiboken2/tests/samplebinding/abstract_test.py +++ b/sources/shiboken2/tests/samplebinding/abstract_test.py @@ -31,9 +31,14 @@ '''Test cases for Abstract class''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Abstract class Incomplete(Abstract): diff --git a/sources/shiboken2/tests/samplebinding/addedfunction_test.py b/sources/shiboken2/tests/samplebinding/addedfunction_test.py index 57cebbb3a..d7f5f3994 100644 --- a/sources/shiboken2/tests/samplebinding/addedfunction_test.py +++ b/sources/shiboken2/tests/samplebinding/addedfunction_test.py @@ -31,7 +31,13 @@ '''Test cases for added functions.''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import SampleNamespace, ObjectType, Point class TestAddedFunctionsWithSimilarTypes(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/addedfunction_with_container_args_test.py b/sources/shiboken2/tests/samplebinding/addedfunction_with_container_args_test.py index 0954ba470..9666b251c 100644 --- a/sources/shiboken2/tests/samplebinding/addedfunction_with_container_args_test.py +++ b/sources/shiboken2/tests/samplebinding/addedfunction_with_container_args_test.py @@ -31,7 +31,13 @@ '''Test cases for added functions with nested and multi-argument container types.''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import sum2d, sumproduct class TestAddedFunctionsWithContainerArgs(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/argumentmodifications_test.py b/sources/shiboken2/tests/samplebinding/argumentmodifications_test.py index aa27de331..8a2775db3 100644 --- a/sources/shiboken2/tests/samplebinding/argumentmodifications_test.py +++ b/sources/shiboken2/tests/samplebinding/argumentmodifications_test.py @@ -31,9 +31,14 @@ '''Test cases for method arguments modifications performed as described on typesystem.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Modifications, Point class ArgumentModificationsTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/array_numpy_test.py b/sources/shiboken2/tests/samplebinding/array_numpy_test.py index 37536930d..2c2a2852a 100644 --- a/sources/shiboken2/tests/samplebinding/array_numpy_test.py +++ b/sources/shiboken2/tests/samplebinding/array_numpy_test.py @@ -30,7 +30,13 @@ '''Test case for NumPy Array types.''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import sample hasNumPy = False diff --git a/sources/shiboken2/tests/samplebinding/array_sequence_test.py b/sources/shiboken2/tests/samplebinding/array_sequence_test.py index ac8217054..520a5f928 100644 --- a/sources/shiboken2/tests/samplebinding/array_sequence_test.py +++ b/sources/shiboken2/tests/samplebinding/array_sequence_test.py @@ -30,7 +30,13 @@ '''Test case for Array types (PySequence).''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import sample class ArrayTester(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/bug_554_test.py b/sources/shiboken2/tests/samplebinding/bug_554_test.py index 85848fc39..c1c06a17f 100644 --- a/sources/shiboken2/tests/samplebinding/bug_554_test.py +++ b/sources/shiboken2/tests/samplebinding/bug_554_test.py @@ -31,6 +31,12 @@ '''Unit test for bug#554''' +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class Bug554: diff --git a/sources/shiboken2/tests/samplebinding/bug_704_test.py b/sources/shiboken2/tests/samplebinding/bug_704_test.py index 9aa865327..28c90aba4 100644 --- a/sources/shiboken2/tests/samplebinding/bug_704_test.py +++ b/sources/shiboken2/tests/samplebinding/bug_704_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from py3kcompat import IS_PY3K from sample import ObjectType diff --git a/sources/shiboken2/tests/samplebinding/bytearray_test.py b/sources/shiboken2/tests/samplebinding/bytearray_test.py index e19271ca9..f1094e54e 100644 --- a/sources/shiboken2/tests/samplebinding/bytearray_test.py +++ b/sources/shiboken2/tests/samplebinding/bytearray_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from os.path import isdir from sample import ByteArray from py3kcompat import b diff --git a/sources/shiboken2/tests/samplebinding/child_return_test.py b/sources/shiboken2/tests/samplebinding/child_return_test.py index 49c843160..28fde4926 100644 --- a/sources/shiboken2/tests/samplebinding/child_return_test.py +++ b/sources/shiboken2/tests/samplebinding/child_return_test.py @@ -31,9 +31,14 @@ '''The BlackBox class has cases of ownership transference between C++ and Python.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class ReturnOfChildTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/class_fields_test.py b/sources/shiboken2/tests/samplebinding/class_fields_test.py index 6dbacbd97..202efcafb 100644 --- a/sources/shiboken2/tests/samplebinding/class_fields_test.py +++ b/sources/shiboken2/tests/samplebinding/class_fields_test.py @@ -31,9 +31,15 @@ '''Simple test case for accessing the exposed C++ class fields.''' +import os +import sys from sys import getrefcount import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Derived, Point, ObjectType class TestAccessingCppFields(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/collector_test.py b/sources/shiboken2/tests/samplebinding/collector_test.py index f0b184a90..d6d10165e 100644 --- a/sources/shiboken2/tests/samplebinding/collector_test.py +++ b/sources/shiboken2/tests/samplebinding/collector_test.py @@ -31,9 +31,14 @@ '''Test cases for Collector class' shift operators.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Collector, IntWrapper, ObjectType diff --git a/sources/shiboken2/tests/samplebinding/complex_test.py b/sources/shiboken2/tests/samplebinding/complex_test.py index e14b07b91..bff7b5828 100644 --- a/sources/shiboken2/tests/samplebinding/complex_test.py +++ b/sources/shiboken2/tests/samplebinding/complex_test.py @@ -31,9 +31,14 @@ '''Test cases for Complex class''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + import sample from sample import Point diff --git a/sources/shiboken2/tests/samplebinding/conversion_operator_test.py b/sources/shiboken2/tests/samplebinding/conversion_operator_test.py index 5faaaa4db..a18d27a0c 100644 --- a/sources/shiboken2/tests/samplebinding/conversion_operator_test.py +++ b/sources/shiboken2/tests/samplebinding/conversion_operator_test.py @@ -31,8 +31,14 @@ '''Test cases for implicit conversion generated by conversion operator.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Time, StrList class ConversionOperatorTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/copy_test.py b/sources/shiboken2/tests/samplebinding/copy_test.py index 7505454a2..a8e02d979 100644 --- a/sources/shiboken2/tests/samplebinding/copy_test.py +++ b/sources/shiboken2/tests/samplebinding/copy_test.py @@ -32,8 +32,14 @@ '''Test cases for deep copy of objects''' import copy +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + try: import cPickle as pickle except ImportError: diff --git a/sources/shiboken2/tests/samplebinding/ctorconvrule_test.py b/sources/shiboken2/tests/samplebinding/ctorconvrule_test.py index b7efead63..7fd9b502c 100644 --- a/sources/shiboken2/tests/samplebinding/ctorconvrule_test.py +++ b/sources/shiboken2/tests/samplebinding/ctorconvrule_test.py @@ -31,8 +31,14 @@ '''Test cases for proper generation of constructor altered by conversion-rule tag.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import CtorConvRule class TestCtorConvRule(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/cyclic_test.py b/sources/shiboken2/tests/samplebinding/cyclic_test.py index 1940c8d2f..8fe029d59 100644 --- a/sources/shiboken2/tests/samplebinding/cyclic_test.py +++ b/sources/shiboken2/tests/samplebinding/cyclic_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectType from sample import ObjectView from sample import ObjectModel diff --git a/sources/shiboken2/tests/samplebinding/date_test.py b/sources/shiboken2/tests/samplebinding/date_test.py index fe7b9ac18..0a89db871 100644 --- a/sources/shiboken2/tests/samplebinding/date_test.py +++ b/sources/shiboken2/tests/samplebinding/date_test.py @@ -31,8 +31,13 @@ '''Test cases for python conversions types ''' +import os import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from datetime import date from sample import SbkDate diff --git a/sources/shiboken2/tests/samplebinding/decisor_test.py b/sources/shiboken2/tests/samplebinding/decisor_test.py index 734c43760..e98e45bfc 100644 --- a/sources/shiboken2/tests/samplebinding/decisor_test.py +++ b/sources/shiboken2/tests/samplebinding/decisor_test.py @@ -31,8 +31,14 @@ '''Test cases for the method overload decisor.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import SampleNamespace, Point, ObjectType, ObjectModel class DecisorTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/delete_test.py b/sources/shiboken2/tests/samplebinding/delete_test.py index 780da415c..b35bba4b0 100644 --- a/sources/shiboken2/tests/samplebinding/delete_test.py +++ b/sources/shiboken2/tests/samplebinding/delete_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import sample import shiboken2 as shiboken diff --git a/sources/shiboken2/tests/samplebinding/deprecated_test.py b/sources/shiboken2/tests/samplebinding/deprecated_test.py index b08f65271..d75490e17 100644 --- a/sources/shiboken2/tests/samplebinding/deprecated_test.py +++ b/sources/shiboken2/tests/samplebinding/deprecated_test.py @@ -29,8 +29,14 @@ ## ############################################################################# -import warnings +import os +import sys import unittest +import warnings + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectType diff --git a/sources/shiboken2/tests/samplebinding/derived_test.py b/sources/shiboken2/tests/samplebinding/derived_test.py index 05cd648f5..81f3a8034 100644 --- a/sources/shiboken2/tests/samplebinding/derived_test.py +++ b/sources/shiboken2/tests/samplebinding/derived_test.py @@ -31,9 +31,14 @@ '''Test cases for Derived class''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + import sample from sample import Abstract, Derived, OverloadedFuncEnum diff --git a/sources/shiboken2/tests/samplebinding/duck_punching_test.py b/sources/shiboken2/tests/samplebinding/duck_punching_test.py index efc8f344f..3f9d69b47 100644 --- a/sources/shiboken2/tests/samplebinding/duck_punching_test.py +++ b/sources/shiboken2/tests/samplebinding/duck_punching_test.py @@ -31,8 +31,14 @@ '''Test cases for virtual methods.''' +import os +import sys import types import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from py3kcompat import IS_PY3K from sample import VirtualMethods, SimpleFile, Point diff --git a/sources/shiboken2/tests/samplebinding/echo_test.py b/sources/shiboken2/tests/samplebinding/echo_test.py index b91394bb8..cd3fcc090 100644 --- a/sources/shiboken2/tests/samplebinding/echo_test.py +++ b/sources/shiboken2/tests/samplebinding/echo_test.py @@ -31,8 +31,14 @@ '''Test cases for <add-function> with const char* as argument''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Echo class TestEcho(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/enum_test.py b/sources/shiboken2/tests/samplebinding/enum_test.py index 7e1cac8c0..0beb72033 100644 --- a/sources/shiboken2/tests/samplebinding/enum_test.py +++ b/sources/shiboken2/tests/samplebinding/enum_test.py @@ -35,6 +35,13 @@ import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +import shiboken2 +# This is needed after the introduction of BUILD_DIR. + import sample from sample import SampleNamespace, ObjectType, Event from py3kcompat import IS_PY3K, b diff --git a/sources/shiboken2/tests/samplebinding/enumfromremovednamespace_test.py b/sources/shiboken2/tests/samplebinding/enumfromremovednamespace_test.py index 5803a9975..4b0866c4e 100644 --- a/sources/shiboken2/tests/samplebinding/enumfromremovednamespace_test.py +++ b/sources/shiboken2/tests/samplebinding/enumfromremovednamespace_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + import sample class TestEnumFromRemovedNamespace(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/event_loop_call_virtual_test.py b/sources/shiboken2/tests/samplebinding/event_loop_call_virtual_test.py index 63a5a8ab3..41b91ed70 100644 --- a/sources/shiboken2/tests/samplebinding/event_loop_call_virtual_test.py +++ b/sources/shiboken2/tests/samplebinding/event_loop_call_virtual_test.py @@ -30,8 +30,14 @@ '''Simple event loop dispatcher test.''' +import os +import sys import time import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from random import random from sample import ObjectType, Event diff --git a/sources/shiboken2/tests/samplebinding/event_loop_thread_test.py b/sources/shiboken2/tests/samplebinding/event_loop_thread_test.py index 1a1fe840d..4c63d0665 100644 --- a/sources/shiboken2/tests/samplebinding/event_loop_thread_test.py +++ b/sources/shiboken2/tests/samplebinding/event_loop_thread_test.py @@ -28,10 +28,16 @@ ## ############################################################################# +import os +from random import random +import sys import time import threading import unittest -from random import random + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectType, Event diff --git a/sources/shiboken2/tests/samplebinding/exception_test.py b/sources/shiboken2/tests/samplebinding/exception_test.py index d6c02433a..3224dfe17 100644 --- a/sources/shiboken2/tests/samplebinding/exception_test.py +++ b/sources/shiboken2/tests/samplebinding/exception_test.py @@ -28,8 +28,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ExceptionTest class CppExceptionTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/filter_test.py b/sources/shiboken2/tests/samplebinding/filter_test.py index 577a15bd2..b09d89980 100644 --- a/sources/shiboken2/tests/samplebinding/filter_test.py +++ b/sources/shiboken2/tests/samplebinding/filter_test.py @@ -26,8 +26,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Data, Intersection, Union class TestFilters(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/handleholder_test.py b/sources/shiboken2/tests/samplebinding/handleholder_test.py index c2504f4d2..a4cbd1c72 100644 --- a/sources/shiboken2/tests/samplebinding/handleholder_test.py +++ b/sources/shiboken2/tests/samplebinding/handleholder_test.py @@ -33,8 +33,14 @@ Test case for BUG #1105. ''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import HandleHolder class HandleHolderTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/hashabletype_test.py b/sources/shiboken2/tests/samplebinding/hashabletype_test.py index c628c1751..b985abaad 100644 --- a/sources/shiboken2/tests/samplebinding/hashabletype_test.py +++ b/sources/shiboken2/tests/samplebinding/hashabletype_test.py @@ -31,8 +31,14 @@ '''Test cases for __hash__''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class HashableTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/ignorederefop_test.py b/sources/shiboken2/tests/samplebinding/ignorederefop_test.py index c5f53a981..2237443b3 100644 --- a/sources/shiboken2/tests/samplebinding/ignorederefop_test.py +++ b/sources/shiboken2/tests/samplebinding/ignorederefop_test.py @@ -26,7 +26,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import * class TestLackOfDereferenceOperators (unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/implicitconv_numerical_test.py b/sources/shiboken2/tests/samplebinding/implicitconv_numerical_test.py index 6ebca790c..ebecf9ad8 100644 --- a/sources/shiboken2/tests/samplebinding/implicitconv_numerical_test.py +++ b/sources/shiboken2/tests/samplebinding/implicitconv_numerical_test.py @@ -31,7 +31,13 @@ '''Test case for inplicit converting C++ numeric types.''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import sys import sample from py3kcompat import IS_PY3K, l, long diff --git a/sources/shiboken2/tests/samplebinding/implicitconv_test.py b/sources/shiboken2/tests/samplebinding/implicitconv_test.py index 30986d576..a6b770c9b 100644 --- a/sources/shiboken2/tests/samplebinding/implicitconv_test.py +++ b/sources/shiboken2/tests/samplebinding/implicitconv_test.py @@ -31,8 +31,14 @@ '''Test cases for implicit conversions''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ImplicitConv, ObjectType class ImplicitConvTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/inheritanceandscope_test.py b/sources/shiboken2/tests/samplebinding/inheritanceandscope_test.py index 892a2bc93..6b8a91573 100755..100644 --- a/sources/shiboken2/tests/samplebinding/inheritanceandscope_test.py +++ b/sources/shiboken2/tests/samplebinding/inheritanceandscope_test.py @@ -31,8 +31,14 @@ '''Test cases for finding scope in cases involving inheritance.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import SampleNamespace class ScopeAndInheritanceTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/injectcode_test.py b/sources/shiboken2/tests/samplebinding/injectcode_test.py index d6b1d0686..8bdcdbe61 100644 --- a/sources/shiboken2/tests/samplebinding/injectcode_test.py +++ b/sources/shiboken2/tests/samplebinding/injectcode_test.py @@ -31,7 +31,13 @@ '''Test cases for std::list container conversions''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import InjectCode class MyInjectCode(InjectCode): diff --git a/sources/shiboken2/tests/samplebinding/innerclass_test.py b/sources/shiboken2/tests/samplebinding/innerclass_test.py index d76840f5c..287726587 100644 --- a/sources/shiboken2/tests/samplebinding/innerclass_test.py +++ b/sources/shiboken2/tests/samplebinding/innerclass_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Derived class TestInnerClass(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/intlist_test.py b/sources/shiboken2/tests/samplebinding/intlist_test.py index 3bf8fb0ef..19043b99c 100644 --- a/sources/shiboken2/tests/samplebinding/intlist_test.py +++ b/sources/shiboken2/tests/samplebinding/intlist_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import IntList class IntListTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/invalid_virtual_return_test.py b/sources/shiboken2/tests/samplebinding/invalid_virtual_return_test.py index 63384e737..36e583a4f 100644 --- a/sources/shiboken2/tests/samplebinding/invalid_virtual_return_test.py +++ b/sources/shiboken2/tests/samplebinding/invalid_virtual_return_test.py @@ -31,7 +31,13 @@ '''Test case for returning invalid types in a virtual function''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectModel, ObjectType, ObjectView import warnings diff --git a/sources/shiboken2/tests/samplebinding/keep_reference_test.py b/sources/shiboken2/tests/samplebinding/keep_reference_test.py index bcfc0db1b..db3ddc2d4 100644 --- a/sources/shiboken2/tests/samplebinding/keep_reference_test.py +++ b/sources/shiboken2/tests/samplebinding/keep_reference_test.py @@ -31,8 +31,14 @@ '''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' -import unittest +import os +import sys from sys import getrefcount +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectModel, ObjectView diff --git a/sources/shiboken2/tests/samplebinding/list_test.py b/sources/shiboken2/tests/samplebinding/list_test.py index a2761bee3..74091422c 100644 --- a/sources/shiboken2/tests/samplebinding/list_test.py +++ b/sources/shiboken2/tests/samplebinding/list_test.py @@ -31,8 +31,14 @@ '''Test cases for std::list container conversions''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ListUser, Point, PointF class ExtendedListUser(ListUser): diff --git a/sources/shiboken2/tests/samplebinding/lock_test.py b/sources/shiboken2/tests/samplebinding/lock_test.py index 9bb1f8789..93c632e34 100644 --- a/sources/shiboken2/tests/samplebinding/lock_test.py +++ b/sources/shiboken2/tests/samplebinding/lock_test.py @@ -31,8 +31,14 @@ '''Simple test with a blocking C++ method that should allow python threads to run.''' -import unittest +import os +import sys import threading +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import Bucket diff --git a/sources/shiboken2/tests/samplebinding/map_test.py b/sources/shiboken2/tests/samplebinding/map_test.py index 1d8d758d8..f6696c3d8 100644 --- a/sources/shiboken2/tests/samplebinding/map_test.py +++ b/sources/shiboken2/tests/samplebinding/map_test.py @@ -31,8 +31,14 @@ '''Test cases for std::map container conversions''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import MapUser class ExtendedMapUser(MapUser): diff --git a/sources/shiboken2/tests/samplebinding/metaclass_test.py b/sources/shiboken2/tests/samplebinding/metaclass_test.py index e5da496c5..ad4c08f0d 100644 --- a/sources/shiboken2/tests/samplebinding/metaclass_test.py +++ b/sources/shiboken2/tests/samplebinding/metaclass_test.py @@ -26,9 +26,16 @@ ## ############################################################################# -from sample import * +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +from sample import * + class MetaA(type): pass diff --git a/sources/shiboken2/tests/samplebinding/mi_virtual_methods_test.py b/sources/shiboken2/tests/samplebinding/mi_virtual_methods_test.py index 585a1a2df..aea8a4d46 100644 --- a/sources/shiboken2/tests/samplebinding/mi_virtual_methods_test.py +++ b/sources/shiboken2/tests/samplebinding/mi_virtual_methods_test.py @@ -31,8 +31,14 @@ '''Test cases for virtual methods in multiple inheritance scenarios''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import VirtualMethods, ObjectType, Event diff --git a/sources/shiboken2/tests/samplebinding/mixed_mi_test.py b/sources/shiboken2/tests/samplebinding/mixed_mi_test.py index dd557d4f6..d33d033ba 100644 --- a/sources/shiboken2/tests/samplebinding/mixed_mi_test.py +++ b/sources/shiboken2/tests/samplebinding/mixed_mi_test.py @@ -31,8 +31,14 @@ '''Test cases for multiple inheritance in mixed Python/C++ scenarios''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType diff --git a/sources/shiboken2/tests/samplebinding/modelindex_test.py b/sources/shiboken2/tests/samplebinding/modelindex_test.py index 251ee710a..905d14269 100644 --- a/sources/shiboken2/tests/samplebinding/modelindex_test.py +++ b/sources/shiboken2/tests/samplebinding/modelindex_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ModelIndex, ReferentModelIndex, PersistentModelIndex class TestCastOperator(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/modelview_test.py b/sources/shiboken2/tests/samplebinding/modelview_test.py index 3f86fe4ea..f421ca41d 100644 --- a/sources/shiboken2/tests/samplebinding/modelview_test.py +++ b/sources/shiboken2/tests/samplebinding/modelview_test.py @@ -31,7 +31,13 @@ '''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectModel, ObjectType, ObjectView diff --git a/sources/shiboken2/tests/samplebinding/modifications_test.py b/sources/shiboken2/tests/samplebinding/modifications_test.py index 1dcd50359..e6e9c5626 100644 --- a/sources/shiboken2/tests/samplebinding/modifications_test.py +++ b/sources/shiboken2/tests/samplebinding/modifications_test.py @@ -31,8 +31,14 @@ '''Test cases for method modifications performed as described on type system. ''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Modifications, Point, ByteArray class ExtModifications(Modifications): @@ -220,5 +226,15 @@ class ModificationsTest(unittest.TestCase): self.assertTrue(isinstance(res, float)) self.assertEqual(res, em.increment) + def testDefaultValueModifications(self): + # PSYIDE-1095: setEnumValue() has the default value modified to + # calling defaultEnumValue() which returns Modifications.TestEnumValue2. + # This used to generated broken code since defaultEnumValue() was + # qualified by the enum scope. + modifications = Modifications() + modifications.setEnumValue() + self.assertEqual(modifications.enumValue(), Modifications.TestEnumValue2) + + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/modified_constructor_test.py b/sources/shiboken2/tests/samplebinding/modified_constructor_test.py index 3352cd277..11d931c5f 100644 --- a/sources/shiboken2/tests/samplebinding/modified_constructor_test.py +++ b/sources/shiboken2/tests/samplebinding/modified_constructor_test.py @@ -32,8 +32,14 @@ '''Tests cases for ConstructorWithModifiedArgument class.''' import sys +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * diff --git a/sources/shiboken2/tests/samplebinding/modifiedvirtualmethods_test.py b/sources/shiboken2/tests/samplebinding/modifiedvirtualmethods_test.py index 53b854530..c15a0db08 100644 --- a/sources/shiboken2/tests/samplebinding/modifiedvirtualmethods_test.py +++ b/sources/shiboken2/tests/samplebinding/modifiedvirtualmethods_test.py @@ -31,8 +31,14 @@ '''Test cases for modified virtual methods.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import VirtualMethods, Str class ExtendedVirtualMethods(VirtualMethods): diff --git a/sources/shiboken2/tests/samplebinding/multi_cpp_inheritance_test.py b/sources/shiboken2/tests/samplebinding/multi_cpp_inheritance_test.py index 5223f316a..c64a29e8e 100644 --- a/sources/shiboken2/tests/samplebinding/multi_cpp_inheritance_test.py +++ b/sources/shiboken2/tests/samplebinding/multi_cpp_inheritance_test.py @@ -31,9 +31,14 @@ '''Test cases for multiple inheritance''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class SimpleUseCase(ObjectType, Str): diff --git a/sources/shiboken2/tests/samplebinding/multiple_derived_test.py b/sources/shiboken2/tests/samplebinding/multiple_derived_test.py index 9ac206db3..650af8602 100644 --- a/sources/shiboken2/tests/samplebinding/multiple_derived_test.py +++ b/sources/shiboken2/tests/samplebinding/multiple_derived_test.py @@ -31,9 +31,14 @@ '''Test cases for multiple inheritance''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Base1, Base2, Base3, Base4, Base5, Base6 from sample import MDerived1, MDerived2, MDerived3, MDerived4, MDerived5, SonOfMDerived1 diff --git a/sources/shiboken2/tests/samplebinding/namespace_test.py b/sources/shiboken2/tests/samplebinding/namespace_test.py index 5fcdab974..aeaf81cff 100644 --- a/sources/shiboken2/tests/samplebinding/namespace_test.py +++ b/sources/shiboken2/tests/samplebinding/namespace_test.py @@ -31,7 +31,14 @@ '''Test cases for std::map container conversions''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * diff --git a/sources/shiboken2/tests/samplebinding/newdivision_test.py b/sources/shiboken2/tests/samplebinding/newdivision_test.py index 331d7b365..d352c1b91 100644 --- a/sources/shiboken2/tests/samplebinding/newdivision_test.py +++ b/sources/shiboken2/tests/samplebinding/newdivision_test.py @@ -27,9 +27,17 @@ ############################################################################# from __future__ import division -from sample import * +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +from sample import * + + class TestNewDivision(unittest.TestCase): def testIt(self): diff --git a/sources/shiboken2/tests/samplebinding/nondefaultctor_test.py b/sources/shiboken2/tests/samplebinding/nondefaultctor_test.py index 86a05fd78..68d083136 100644 --- a/sources/shiboken2/tests/samplebinding/nondefaultctor_test.py +++ b/sources/shiboken2/tests/samplebinding/nondefaultctor_test.py @@ -31,9 +31,14 @@ '''Test cases for ...''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import NonDefaultCtor class DerivedNonDefaultCtor (NonDefaultCtor): diff --git a/sources/shiboken2/tests/samplebinding/nontypetemplate_test.py b/sources/shiboken2/tests/samplebinding/nontypetemplate_test.py index a7a4da72b..7c4729b4f 100644 --- a/sources/shiboken2/tests/samplebinding/nontypetemplate_test.py +++ b/sources/shiboken2/tests/samplebinding/nontypetemplate_test.py @@ -36,8 +36,14 @@ try: except ImportError: pass +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import IntArray2, IntArray3 class NonTypeTemplateTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/nonzero_test.py b/sources/shiboken2/tests/samplebinding/nonzero_test.py index 138a92264..214b2f7bd 100644 --- a/sources/shiboken2/tests/samplebinding/nonzero_test.py +++ b/sources/shiboken2/tests/samplebinding/nonzero_test.py @@ -29,7 +29,14 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class TestNonZeroOperator(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/numericaltypedef_test.py b/sources/shiboken2/tests/samplebinding/numericaltypedef_test.py index f82e23424..de9128cbc 100644 --- a/sources/shiboken2/tests/samplebinding/numericaltypedef_test.py +++ b/sources/shiboken2/tests/samplebinding/numericaltypedef_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import SizeF class NumericalTypedefTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/numpy_test.py b/sources/shiboken2/tests/samplebinding/numpy_test.py index 90b97992a..3f67f59e4 100644 --- a/sources/shiboken2/tests/samplebinding/numpy_test.py +++ b/sources/shiboken2/tests/samplebinding/numpy_test.py @@ -36,7 +36,13 @@ try: except: sys.exit(0) +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import PointF class TestNumpyTypes(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/objecttype_test.py b/sources/shiboken2/tests/samplebinding/objecttype_test.py index f1a06c2b1..1d7f70722 100644 --- a/sources/shiboken2/tests/samplebinding/objecttype_test.py +++ b/sources/shiboken2/tests/samplebinding/objecttype_test.py @@ -31,7 +31,13 @@ '''Tests ObjectType class of object-type with privates copy constructor and = operator.''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import sys from sample import ObjectType, Str diff --git a/sources/shiboken2/tests/samplebinding/objecttype_with_named_args_test.py b/sources/shiboken2/tests/samplebinding/objecttype_with_named_args_test.py index 846ae5108..ce7874c23 100755..100644 --- a/sources/shiboken2/tests/samplebinding/objecttype_with_named_args_test.py +++ b/sources/shiboken2/tests/samplebinding/objecttype_with_named_args_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType class NamedArgsTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/objecttypebyvalue_test.py b/sources/shiboken2/tests/samplebinding/objecttypebyvalue_test.py index 31cbe29cc..080a51ce5 100644 --- a/sources/shiboken2/tests/samplebinding/objecttypebyvalue_test.py +++ b/sources/shiboken2/tests/samplebinding/objecttypebyvalue_test.py @@ -26,9 +26,17 @@ ## ############################################################################# -from sample import * +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +from sample import * + + class ObjectTypeByValueTest (unittest.TestCase): def testIt(self): factory = ObjectTypeByValue() diff --git a/sources/shiboken2/tests/samplebinding/objecttypelayout_test.py b/sources/shiboken2/tests/samplebinding/objecttypelayout_test.py index 62f6ce731..bcf30eb43 100644 --- a/sources/shiboken2/tests/samplebinding/objecttypelayout_test.py +++ b/sources/shiboken2/tests/samplebinding/objecttypelayout_test.py @@ -31,9 +31,14 @@ '''Tests cases for ObjectTypeLayout class.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * diff --git a/sources/shiboken2/tests/samplebinding/objecttypeoperators_test.py b/sources/shiboken2/tests/samplebinding/objecttypeoperators_test.py index fa6c2f5b0..fb0d52319 100644 --- a/sources/shiboken2/tests/samplebinding/objecttypeoperators_test.py +++ b/sources/shiboken2/tests/samplebinding/objecttypeoperators_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import * class ObjectTypeOperatorsTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py b/sources/shiboken2/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py index b9ab554dc..40adb94ed 100644 --- a/sources/shiboken2/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py +++ b/sources/shiboken2/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectTypeHolder class TestObjectTypeReferenceAsVirtualMethodArgument(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/oddbool_test.py b/sources/shiboken2/tests/samplebinding/oddbool_test.py index f99645bc6..de1429604 100644 --- a/sources/shiboken2/tests/samplebinding/oddbool_test.py +++ b/sources/shiboken2/tests/samplebinding/oddbool_test.py @@ -31,8 +31,14 @@ '''Test cases for OddBool user's primitive type conversion.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import OddBoolUser class DerivedOddBoolUser (OddBoolUser): diff --git a/sources/shiboken2/tests/samplebinding/oldstyleclass_as_number_test.py b/sources/shiboken2/tests/samplebinding/oldstyleclass_as_number_test.py index 8852e152d..e0f864636 100644 --- a/sources/shiboken2/tests/samplebinding/oldstyleclass_as_number_test.py +++ b/sources/shiboken2/tests/samplebinding/oldstyleclass_as_number_test.py @@ -29,7 +29,14 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + import sample from py3kcompat import IS_PY3K diff --git a/sources/shiboken2/tests/samplebinding/onlycopyclass_test.py b/sources/shiboken2/tests/samplebinding/onlycopyclass_test.py index 43a095137..ccf71f4f8 100644 --- a/sources/shiboken2/tests/samplebinding/onlycopyclass_test.py +++ b/sources/shiboken2/tests/samplebinding/onlycopyclass_test.py @@ -29,7 +29,14 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import OnlyCopy, FriendOfOnlyCopy class ClassWithOnlyCopyCtorTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/overflow_test.py b/sources/shiboken2/tests/samplebinding/overflow_test.py index b7a1006fe..56a5d98c7 100644 --- a/sources/shiboken2/tests/samplebinding/overflow_test.py +++ b/sources/shiboken2/tests/samplebinding/overflow_test.py @@ -31,9 +31,14 @@ '''Test case for overflowing C++ numeric types.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * from py3kcompat import IS_PY3K, long diff --git a/sources/shiboken2/tests/samplebinding/overload_sorting_test.py b/sources/shiboken2/tests/samplebinding/overload_sorting_test.py index b3b0f7c43..8132e4e3d 100644 --- a/sources/shiboken2/tests/samplebinding/overload_sorting_test.py +++ b/sources/shiboken2/tests/samplebinding/overload_sorting_test.py @@ -31,8 +31,14 @@ '''Test cases for overload sorting''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class Dummy(object): diff --git a/sources/shiboken2/tests/samplebinding/overload_test.py b/sources/shiboken2/tests/samplebinding/overload_test.py index 0cc9e4250..ab5230990 100644 --- a/sources/shiboken2/tests/samplebinding/overload_test.py +++ b/sources/shiboken2/tests/samplebinding/overload_test.py @@ -31,7 +31,13 @@ '''Test cases for Overload class''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import Echo, Overload, Point, PointF, Polygon, Rect, RectF, Size, Str diff --git a/sources/shiboken2/tests/samplebinding/overloadwithdefault_test.py b/sources/shiboken2/tests/samplebinding/overloadwithdefault_test.py index 8db9726c8..dbd318091 100644 --- a/sources/shiboken2/tests/samplebinding/overloadwithdefault_test.py +++ b/sources/shiboken2/tests/samplebinding/overloadwithdefault_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Overload, Str from py3kcompat import b diff --git a/sources/shiboken2/tests/samplebinding/ownership_argument_invalidation_test.py b/sources/shiboken2/tests/samplebinding/ownership_argument_invalidation_test.py index e0b79daa7..d96236c2c 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_argument_invalidation_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_argument_invalidation_test.py @@ -31,9 +31,14 @@ '''Wrapper validity tests for arguments.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Polygon, Point class WrapperValidityOfArgumentsTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_cpp_test.py b/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_cpp_test.py index f0081385a..255f1fdb1 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_cpp_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_cpp_test.py @@ -31,8 +31,14 @@ '''Tests for destroy a child object in C++''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType diff --git a/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_python_test.py b/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_python_test.py index cac52113d..206a65ce9 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_python_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_delete_child_in_python_test.py @@ -31,9 +31,15 @@ '''Tests for deleting a child object in python''' -import unittest +import os import random import string +import sys +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectType from py3kcompat import IS_PY3K diff --git a/sources/shiboken2/tests/samplebinding/ownership_delete_parent_test.py b/sources/shiboken2/tests/samplebinding/ownership_delete_parent_test.py index cc317df19..1b7de5f2f 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_delete_parent_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_delete_parent_test.py @@ -31,9 +31,14 @@ '''Tests for destroying the parent''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType diff --git a/sources/shiboken2/tests/samplebinding/ownership_invalidate_after_use_test.py b/sources/shiboken2/tests/samplebinding/ownership_invalidate_after_use_test.py index e73b5a8ac..10f1cf9ee 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_invalidate_after_use_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_invalidate_after_use_test.py @@ -31,9 +31,14 @@ '''Ownership tests for cases of invalidation of Python wrapper after use.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType, ObjectTypeDerived, Event diff --git a/sources/shiboken2/tests/samplebinding/ownership_invalidate_child_test.py b/sources/shiboken2/tests/samplebinding/ownership_invalidate_child_test.py index 59bf3f3df..9e6423e50 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_invalidate_child_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_invalidate_child_test.py @@ -31,8 +31,14 @@ '''Tests for invalidating a C++ created child that was already on the care of a parent.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType, BlackBox diff --git a/sources/shiboken2/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py b/sources/shiboken2/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py index d64a2120c..18fce3809 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py @@ -31,9 +31,14 @@ '''The BlackBox class has cases of ownership transference between Python and C++.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Point, BlackBox class OwnershipInvalidateNonPolymorphicTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/ownership_invalidate_parent_test.py b/sources/shiboken2/tests/samplebinding/ownership_invalidate_parent_test.py index 42b516ff2..2d7e67deb 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_invalidate_parent_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_invalidate_parent_test.py @@ -31,8 +31,14 @@ '''Tests for invalidating a parent of other objects.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType, BlackBox diff --git a/sources/shiboken2/tests/samplebinding/ownership_reparenting_test.py b/sources/shiboken2/tests/samplebinding/ownership_reparenting_test.py index 1a7ea2379..217566996 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_reparenting_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_reparenting_test.py @@ -31,7 +31,13 @@ '''Tests for object reparenting.''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import sys from sample import ObjectType diff --git a/sources/shiboken2/tests/samplebinding/ownership_transference_test.py b/sources/shiboken2/tests/samplebinding/ownership_transference_test.py index 42b576a4d..1a783458e 100644 --- a/sources/shiboken2/tests/samplebinding/ownership_transference_test.py +++ b/sources/shiboken2/tests/samplebinding/ownership_transference_test.py @@ -31,9 +31,14 @@ '''The BlackBox class has cases of ownership transference between C++ and Python.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType, BlackBox class BlackBoxTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/pair_test.py b/sources/shiboken2/tests/samplebinding/pair_test.py index ac0653dbe..65fd9b99c 100644 --- a/sources/shiboken2/tests/samplebinding/pair_test.py +++ b/sources/shiboken2/tests/samplebinding/pair_test.py @@ -31,9 +31,14 @@ '''Test cases for std::pair container conversions''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import PairUser class ExtendedPairUser(PairUser): diff --git a/sources/shiboken2/tests/samplebinding/pen_test.py b/sources/shiboken2/tests/samplebinding/pen_test.py index 2a61ae367..89abf4d54 100644 --- a/sources/shiboken2/tests/samplebinding/pen_test.py +++ b/sources/shiboken2/tests/samplebinding/pen_test.py @@ -31,8 +31,14 @@ '''Test cases for <add-function> with const char* as argument''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Color, Pen, SampleNamespace class TestPen(unittest.TestCase): @@ -57,6 +63,8 @@ class TestPen(unittest.TestCase): def testPenWithIntConvertedToColor(self): pen = Pen(1) self.assertEqual(pen.ctorType(), Pen.ColorCtor) + pen.drawLine(0, 0, 5, 5) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/point_test.py b/sources/shiboken2/tests/samplebinding/point_test.py index d6498d4b3..e2beb78ae 100644 --- a/sources/shiboken2/tests/samplebinding/point_test.py +++ b/sources/shiboken2/tests/samplebinding/point_test.py @@ -31,9 +31,14 @@ '''Test cases for Point class''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Point from py3kcompat import unicode diff --git a/sources/shiboken2/tests/samplebinding/pointerholder_test.py b/sources/shiboken2/tests/samplebinding/pointerholder_test.py index e427e0435..b79eaa33a 100644 --- a/sources/shiboken2/tests/samplebinding/pointerholder_test.py +++ b/sources/shiboken2/tests/samplebinding/pointerholder_test.py @@ -31,9 +31,14 @@ '''Test cases for a class that holds an arbitraty pointer and is modified to hold an PyObject.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import PointerHolder class TestPointerHolder(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py b/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py index c40770862..532f2226c 100644 --- a/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py +++ b/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py @@ -44,7 +44,13 @@ because typing.Sequence is a subclass, but we will generalize this to typing.Iterable in the future. """ +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import IntArray2, VirtualMethods import shiboken2 diff --git a/sources/shiboken2/tests/samplebinding/pointf_test.py b/sources/shiboken2/tests/samplebinding/pointf_test.py index 8d8b47115..e9630fe40 100644 --- a/sources/shiboken2/tests/samplebinding/pointf_test.py +++ b/sources/shiboken2/tests/samplebinding/pointf_test.py @@ -31,8 +31,14 @@ '''Test cases for PointF class''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import PointF class PointFTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/primitivereferenceargument_test.py b/sources/shiboken2/tests/samplebinding/primitivereferenceargument_test.py index ef0e153e9..95c210b23 100644 --- a/sources/shiboken2/tests/samplebinding/primitivereferenceargument_test.py +++ b/sources/shiboken2/tests/samplebinding/primitivereferenceargument_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import sample class PrimitiveReferenceArgumentTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/privatector_test.py b/sources/shiboken2/tests/samplebinding/privatector_test.py index e972512fb..7dc3d6651 100644 --- a/sources/shiboken2/tests/samplebinding/privatector_test.py +++ b/sources/shiboken2/tests/samplebinding/privatector_test.py @@ -32,9 +32,14 @@ '''Test cases for a class with only a private constructor.''' import gc +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import PrivateCtor diff --git a/sources/shiboken2/tests/samplebinding/privatedtor_test.py b/sources/shiboken2/tests/samplebinding/privatedtor_test.py index 478506779..97d034729 100644 --- a/sources/shiboken2/tests/samplebinding/privatedtor_test.py +++ b/sources/shiboken2/tests/samplebinding/privatedtor_test.py @@ -32,9 +32,14 @@ '''Test cases for a class with a private destructor.''' import gc +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + import shiboken2 as shiboken from sample import PrivateDtor diff --git a/sources/shiboken2/tests/samplebinding/protected_test.py b/sources/shiboken2/tests/samplebinding/protected_test.py index d343405ad..0cfc69b12 100644 --- a/sources/shiboken2/tests/samplebinding/protected_test.py +++ b/sources/shiboken2/tests/samplebinding/protected_test.py @@ -31,8 +31,14 @@ '''Test cases for protected methods.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import cacheSize from sample import ProtectedNonPolymorphic, ProtectedVirtualDestructor from sample import ProtectedPolymorphic, ProtectedPolymorphicDaughter, ProtectedPolymorphicGrandDaughter diff --git a/sources/shiboken2/tests/samplebinding/pstrlist_test.py b/sources/shiboken2/tests/samplebinding/pstrlist_test.py index 5ecccd075..04492de33 100644 --- a/sources/shiboken2/tests/samplebinding/pstrlist_test.py +++ b/sources/shiboken2/tests/samplebinding/pstrlist_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import sample class PStrListTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/pystr_test.py b/sources/shiboken2/tests/samplebinding/pystr_test.py index 2aa4da40c..b69cf369e 100644 --- a/sources/shiboken2/tests/samplebinding/pystr_test.py +++ b/sources/shiboken2/tests/samplebinding/pystr_test.py @@ -31,9 +31,14 @@ '''Test cases for definition of __str__ method.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Point class PyStrTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/python_thread_test.py b/sources/shiboken2/tests/samplebinding/python_thread_test.py index 2015c8ed3..56b927367 100644 --- a/sources/shiboken2/tests/samplebinding/python_thread_test.py +++ b/sources/shiboken2/tests/samplebinding/python_thread_test.py @@ -30,16 +30,22 @@ '''Tests for using Shiboken-based bindings with python threads''' -import unittest +import logging +import os +from random import random +import sys import threading -import sample import time +import unittest -import logging +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +import sample #logging.basicConfig(level=logging.DEBUG) -from random import random class Producer(threading.Thread): '''Producer thread''' diff --git a/sources/shiboken2/tests/samplebinding/receive_null_cstring_test.py b/sources/shiboken2/tests/samplebinding/receive_null_cstring_test.py index 68de49376..8023aead0 100644 --- a/sources/shiboken2/tests/samplebinding/receive_null_cstring_test.py +++ b/sources/shiboken2/tests/samplebinding/receive_null_cstring_test.py @@ -31,8 +31,14 @@ '''Test case for a function that could receive a NULL pointer in a '[const] char*' parameter.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import countCharacters class ReceiveNullCStringTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/reference_test.py b/sources/shiboken2/tests/samplebinding/reference_test.py index 152730fad..7ff806692 100644 --- a/sources/shiboken2/tests/samplebinding/reference_test.py +++ b/sources/shiboken2/tests/samplebinding/reference_test.py @@ -31,9 +31,14 @@ '''Test cases for methods that receive references to objects.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class ExtendedReference(Reference): diff --git a/sources/shiboken2/tests/samplebinding/referencetopointer_test.py b/sources/shiboken2/tests/samplebinding/referencetopointer_test.py index 5a02c5943..240719e4b 100644 --- a/sources/shiboken2/tests/samplebinding/referencetopointer_test.py +++ b/sources/shiboken2/tests/samplebinding/referencetopointer_test.py @@ -31,8 +31,14 @@ '''Test cases for a reference to pointer argument type.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import VirtualMethods, Str class ExtendedVirtualMethods(VirtualMethods): diff --git a/sources/shiboken2/tests/samplebinding/return_null_test.py b/sources/shiboken2/tests/samplebinding/return_null_test.py index 15abb8b02..85764679b 100644 --- a/sources/shiboken2/tests/samplebinding/return_null_test.py +++ b/sources/shiboken2/tests/samplebinding/return_null_test.py @@ -31,9 +31,14 @@ '''Test case for functions that could return a NULL pointer.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import returnNullPrimitivePointer, returnNullValueTypePointer, returnNullObjectTypePointer class ReturnNullTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/richcompare_test.py b/sources/shiboken2/tests/samplebinding/richcompare_test.py index b219addc5..bcda390c3 100644 --- a/sources/shiboken2/tests/samplebinding/richcompare_test.py +++ b/sources/shiboken2/tests/samplebinding/richcompare_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class TestRichCompare(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/sample_test.py b/sources/shiboken2/tests/samplebinding/sample_test.py index 94cf4f5e3..d6cf82f9a 100644 --- a/sources/shiboken2/tests/samplebinding/sample_test.py +++ b/sources/shiboken2/tests/samplebinding/sample_test.py @@ -31,8 +31,14 @@ '''Test cases for libsample bindings module''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + import sample class ModuleTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/simplefile_test.py b/sources/shiboken2/tests/samplebinding/simplefile_test.py index 2a42942f7..4a841be80 100644 --- a/sources/shiboken2/tests/samplebinding/simplefile_test.py +++ b/sources/shiboken2/tests/samplebinding/simplefile_test.py @@ -32,8 +32,13 @@ '''Test cases for SimpleFile class''' import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import SimpleFile class SimpleFileTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/size_test.py b/sources/shiboken2/tests/samplebinding/size_test.py index b7547d53f..53626c961 100644 --- a/sources/shiboken2/tests/samplebinding/size_test.py +++ b/sources/shiboken2/tests/samplebinding/size_test.py @@ -31,8 +31,14 @@ '''Test cases for operator overloads on Size class''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Size class PointTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/static_nonstatic_methods_test.py b/sources/shiboken2/tests/samplebinding/static_nonstatic_methods_test.py index 9b5c1e029..cd1a8a4f0 100644 --- a/sources/shiboken2/tests/samplebinding/static_nonstatic_methods_test.py +++ b/sources/shiboken2/tests/samplebinding/static_nonstatic_methods_test.py @@ -32,8 +32,13 @@ '''Test cases for overloads involving static and non-static versions of a method.''' import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import SimpleFile class SimpleFile2 (SimpleFile): diff --git a/sources/shiboken2/tests/samplebinding/str_test.py b/sources/shiboken2/tests/samplebinding/str_test.py index a5ead4783..15df1f55a 100644 --- a/sources/shiboken2/tests/samplebinding/str_test.py +++ b/sources/shiboken2/tests/samplebinding/str_test.py @@ -31,8 +31,14 @@ '''Test cases for a method that receives a reference to class that is implicitly convertible from a Python native type.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Str class StrTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/strlist_test.py b/sources/shiboken2/tests/samplebinding/strlist_test.py index 787374b73..57537f061 100644 --- a/sources/shiboken2/tests/samplebinding/strlist_test.py +++ b/sources/shiboken2/tests/samplebinding/strlist_test.py @@ -31,8 +31,14 @@ '''Test cases for StrList class that inherits from std::list<Str>.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Str, StrList class StrListTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/templateinheritingclass_test.py b/sources/shiboken2/tests/samplebinding/templateinheritingclass_test.py index 914a3e28e..bc66b208f 100644 --- a/sources/shiboken2/tests/samplebinding/templateinheritingclass_test.py +++ b/sources/shiboken2/tests/samplebinding/templateinheritingclass_test.py @@ -29,7 +29,14 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Photon '''This tests classes that inherit from template classes, diff --git a/sources/shiboken2/tests/samplebinding/time_test.py b/sources/shiboken2/tests/samplebinding/time_test.py index 1882ffc5c..f8b35e7b7 100644 --- a/sources/shiboken2/tests/samplebinding/time_test.py +++ b/sources/shiboken2/tests/samplebinding/time_test.py @@ -32,7 +32,13 @@ '''Test cases for constructor and method signature decisor on Time class.''' import sys +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() import datetime from sample import Time, ImplicitConv, ObjectType diff --git a/sources/shiboken2/tests/samplebinding/transform_test.py b/sources/shiboken2/tests/samplebinding/transform_test.py index 51839dbf0..5369ec466 100644 --- a/sources/shiboken2/tests/samplebinding/transform_test.py +++ b/sources/shiboken2/tests/samplebinding/transform_test.py @@ -31,8 +31,14 @@ '''Test cases for argument modification with more than nine arguments.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Point, applyHomogeneousTransform class TransformTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/typeconverters_test.py b/sources/shiboken2/tests/samplebinding/typeconverters_test.py index 46e2dd57c..33f3b62e5 100644 --- a/sources/shiboken2/tests/samplebinding/typeconverters_test.py +++ b/sources/shiboken2/tests/samplebinding/typeconverters_test.py @@ -31,7 +31,14 @@ '''Tests various usages of the type converters.''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + import sample class GetPythonTypeByNameTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/typedealloc_test.py b/sources/shiboken2/tests/samplebinding/typedealloc_test.py index 8f0371d16..b79b6de0e 100644 --- a/sources/shiboken2/tests/samplebinding/typedealloc_test.py +++ b/sources/shiboken2/tests/samplebinding/typedealloc_test.py @@ -32,8 +32,14 @@ '''Test deallocation of type extended in Python.''' import gc -import weakref +import os +import sys import unittest +import weakref + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import Point diff --git a/sources/shiboken2/tests/samplebinding/typedtordoublefree_test.py b/sources/shiboken2/tests/samplebinding/typedtordoublefree_test.py index e1fbc4406..8cf93866f 100644 --- a/sources/shiboken2/tests/samplebinding/typedtordoublefree_test.py +++ b/sources/shiboken2/tests/samplebinding/typedtordoublefree_test.py @@ -29,7 +29,13 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectType class TestTypeDestructorDoubleFree(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml index 19b4948a1..3aaecf247 100644 --- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml @@ -227,7 +227,6 @@ </modify-argument> <modify-argument index="1"> <replace-type modified-type="PStr"/> - <remove-default-expression/> <replace-default-expression with="PStr()"/> </modify-argument> <inject-code class="target" position="end"> @@ -956,6 +955,7 @@ <object-type name="Modifications"> <enum-type name="OverloadedModFunc"/> + <enum-type name="TestEnum"/> <modify-function signature="overloaded(int, bool, int, double)"> <modify-argument index="2"> @@ -1287,6 +1287,11 @@ %PYARG_0 = %CONVERTTOPYTHON[OddBool](%0); </inject-code> </modify-function> + <modify-function signature="setEnumValue(Modifications::TestEnum)"> + <modify-argument index="1"> + <replace-default-expression with="cppSelf->defaultEnumValue()"/> + </modify-argument> + </modify-function> </object-type> <object-type name="AbstractModifications"> @@ -2305,6 +2310,7 @@ <value-type name="Color" /> <value-type name="Pen"> <enum-type identified-by-value="EnumCtor"/> + <enum-type name="RenderHints"/> </value-type> <value-type name="CtorConvRule"> diff --git a/sources/shiboken2/tests/samplebinding/unsafe_parent_test.py b/sources/shiboken2/tests/samplebinding/unsafe_parent_test.py index 9e50dabf6..1387e308c 100644 --- a/sources/shiboken2/tests/samplebinding/unsafe_parent_test.py +++ b/sources/shiboken2/tests/samplebinding/unsafe_parent_test.py @@ -31,9 +31,14 @@ '''Test cases for ...''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import ObjectType class DerivedObjectType(ObjectType): diff --git a/sources/shiboken2/tests/samplebinding/useraddedctor_test.py b/sources/shiboken2/tests/samplebinding/useraddedctor_test.py index 17635259d..f59fb3533 100644 --- a/sources/shiboken2/tests/samplebinding/useraddedctor_test.py +++ b/sources/shiboken2/tests/samplebinding/useraddedctor_test.py @@ -31,7 +31,13 @@ '''Test cases for user added constructors''' +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import * class PointTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/virtualdtor_test.py b/sources/shiboken2/tests/samplebinding/virtualdtor_test.py index 388dc29dc..365d31f59 100644 --- a/sources/shiboken2/tests/samplebinding/virtualdtor_test.py +++ b/sources/shiboken2/tests/samplebinding/virtualdtor_test.py @@ -31,9 +31,14 @@ '''Test cases for virtual destructor.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import VirtualDtor class ExtendedVirtualDtor(VirtualDtor): diff --git a/sources/shiboken2/tests/samplebinding/virtualmethods_test.py b/sources/shiboken2/tests/samplebinding/virtualmethods_test.py index a52ce6bf5..2d3198071 100644 --- a/sources/shiboken2/tests/samplebinding/virtualmethods_test.py +++ b/sources/shiboken2/tests/samplebinding/virtualmethods_test.py @@ -31,9 +31,14 @@ '''Test cases for virtual methods.''' +import os import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * import warnings diff --git a/sources/shiboken2/tests/samplebinding/visibilitychange_test.py b/sources/shiboken2/tests/samplebinding/visibilitychange_test.py index a0ead1fb4..7f723221a 100644 --- a/sources/shiboken2/tests/samplebinding/visibilitychange_test.py +++ b/sources/shiboken2/tests/samplebinding/visibilitychange_test.py @@ -29,8 +29,14 @@ ## ############################################################################# +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import * class VisibilityChangeTest(unittest.TestCase): diff --git a/sources/shiboken2/tests/samplebinding/voidholder_test.py b/sources/shiboken2/tests/samplebinding/voidholder_test.py index 361a3bcdd..07b83347b 100644 --- a/sources/shiboken2/tests/samplebinding/voidholder_test.py +++ b/sources/shiboken2/tests/samplebinding/voidholder_test.py @@ -31,8 +31,14 @@ '''Test case for a class that holds a void pointer.''' +import os +import sys import unittest +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import VoidHolder, Point import shiboken2 as shiboken diff --git a/sources/shiboken2/tests/samplebinding/weakref_test.py b/sources/shiboken2/tests/samplebinding/weakref_test.py index 5379169e1..a4a2dc461 100644 --- a/sources/shiboken2/tests/samplebinding/weakref_test.py +++ b/sources/shiboken2/tests/samplebinding/weakref_test.py @@ -31,8 +31,14 @@ '''Test weakref support''' -import weakref +import os +import sys import unittest +import weakref + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from sample import ObjectType, PrivateDtor diff --git a/sources/shiboken2/tests/samplebinding/writableclassdict_test.py b/sources/shiboken2/tests/samplebinding/writableclassdict_test.py index 003e35e7b..58083b5d4 100644 --- a/sources/shiboken2/tests/samplebinding/writableclassdict_test.py +++ b/sources/shiboken2/tests/samplebinding/writableclassdict_test.py @@ -29,7 +29,14 @@ ## ############################################################################# +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + from sample import Point class ExtPoint(Point): pass diff --git a/sources/shiboken2/tests/shiboken_paths.py b/sources/shiboken2/tests/shiboken_paths.py new file mode 100644 index 000000000..e5a8f2926 --- /dev/null +++ b/sources/shiboken2/tests/shiboken_paths.py @@ -0,0 +1,106 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + + +import os +import sys + + +def get_dir_env_var(var_name): + """Return a directory set by an environment variable""" + result = os.environ.get(var_name) + if not result: + raise ValueError('{} is not set!'.format(var_name)) + if not os.path.isdir(result): + raise ValueError('{} is not a directory!'.format(result)) + return result + + +def get_build_dir(): + return get_dir_env_var('BUILD_DIR') + + +def _prepend_path_var(var_name, paths): + """Prepend additional paths to a path environment variable + like PATH, LD_LIBRARY_PATH""" + old_paths = os.environ.get(var_name) + new_paths = os.pathsep.join(paths) + if old_paths: + new_paths += '{}{}'.format(os.pathsep, old_paths) + os.environ[var_name] = new_paths + + +def add_python_dirs(python_dirs): + """Add directories to the Python path unless present.""" + for python_dir in python_dirs: + if python_dir not in sys.path: + sys.path.append(python_dir) + + +def add_lib_dirs(lib_dirs): + """Add directories to the platform's library path.""" + if sys.platform == 'win32': + if sys.version_info >= (3, 8, 0): + for lib_dir in lib_dirs: + os.add_dll_directory(lib_dir) + else: + _prepend_path_var('PATH', lib_dirs) + else: + _prepend_path_var('LD_LIBRARY_PATH', lib_dirs) + + +def shiboken_paths(include_shiboken_tests=False): + """Return a tuple of python directories/lib directories to be set for + using the shiboken2 module from the build directory or running the + shiboken tests depending on a single environment variable BUILD_DIR + pointing to the build directory.""" + src_dir = os.path.dirname(os.path.abspath(__file__)) + python_dirs = [] + if include_shiboken_tests: + python_dirs.append(src_dir) # For py3kcompat + shiboken_dir = os.path.join(get_build_dir(), 'shiboken2') + python_dirs.append(os.path.join(shiboken_dir, 'shibokenmodule')) + lib_dirs = [os.path.join(shiboken_dir, 'libshiboken')] + if include_shiboken_tests: + shiboken_test_dir = os.path.join(shiboken_dir, 'tests') + for module in ['minimal', 'sample', 'smart', 'other']: + module_dir = os.path.join(shiboken_test_dir, module + 'binding') + python_dirs.append(module_dir) + lib_dir = os.path.join(shiboken_test_dir, 'lib' + module) + lib_dirs.append(lib_dir) + return (python_dirs, lib_dirs) + + +def init_paths(): + """Sets the correct import paths (Python modules and C++ library + paths) for testing shiboken depending on a single + environment variable BUILD_DIR pointing to the build + directory.""" + paths = shiboken_paths(True) + add_python_dirs(paths[0]) + add_lib_dirs(paths[1]) diff --git a/sources/shiboken2/tests/shibokenmodule/module_test.py b/sources/shiboken2/tests/shibokenmodule/module_test.py index 54a175588..d0a8e6bf5 100644 --- a/sources/shiboken2/tests/shibokenmodule/module_test.py +++ b/sources/shiboken2/tests/shibokenmodule/module_test.py @@ -26,8 +26,15 @@ ## ############################################################################# -import shiboken2 as shiboken +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +import shiboken2 as shiboken from sample import * class MultipleInherited (ObjectType, Point): diff --git a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py index e1883c7cc..6210916d3 100644 --- a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py @@ -29,7 +29,16 @@ ## ############################################################################# +from __future__ import print_function + +import gc +import os +import sys import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() from copy import copy from smart import Obj, Registry, Integer @@ -79,6 +88,9 @@ class SmartPointerTests(unittest.TestCase): result = ptrToObj.takeInteger(ptrToObj.m_internalInteger) self.assertEqual(integerCount(), 2) result = None + if integerCount() > 1: + gc.collect() + print('Running garbage collector for reference test', file=sys.stderr) self.assertEqual(integerCount(), 1) # Make a copy of the shared pointer, object count should not change. @@ -171,7 +183,7 @@ class SmartPointerTests(unittest.TestCase): self.assertEqual(objCount(), 10) # clear and delete all objects in the list - ptrToObjList.clear() + del ptrToObjList[:] # Python 2.7 lists have no clear method self.assertEqual(len(ptrToObjList), 0) self.assertEqual(objCount(), 1) |