From 427c7147d23fa21c6e8bd08407b1badc48b49c3c Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 22 May 2017 16:44:51 +0200 Subject: move everying into sources/pyside2 (5.9 edition) in preparation for a subtree merge. this should not be necessary to do in a separate commit, but git is a tad stupid about following history correctly without it. --- sources/pyside2/tests/QtScript/CMakeLists.txt | 5 ++ sources/pyside2/tests/QtScript/base_test.py | 32 ++++++++ sources/pyside2/tests/QtScript/bug_1022.py | 41 ++++++++++ sources/pyside2/tests/QtScript/engine_test.py | 41 ++++++++++ sources/pyside2/tests/QtScript/property_test.py | 90 ++++++++++++++++++++++ .../pyside2/tests/QtScript/qscriptvalue_test.py | 72 +++++++++++++++++ 6 files changed, 281 insertions(+) create mode 100644 sources/pyside2/tests/QtScript/CMakeLists.txt create mode 100644 sources/pyside2/tests/QtScript/base_test.py create mode 100644 sources/pyside2/tests/QtScript/bug_1022.py create mode 100644 sources/pyside2/tests/QtScript/engine_test.py create mode 100644 sources/pyside2/tests/QtScript/property_test.py create mode 100644 sources/pyside2/tests/QtScript/qscriptvalue_test.py (limited to 'sources/pyside2/tests/QtScript') diff --git a/sources/pyside2/tests/QtScript/CMakeLists.txt b/sources/pyside2/tests/QtScript/CMakeLists.txt new file mode 100644 index 000000000..dfea68df0 --- /dev/null +++ b/sources/pyside2/tests/QtScript/CMakeLists.txt @@ -0,0 +1,5 @@ +PYSIDE_TEST(base_test.py) +PYSIDE_TEST(bug_1022.py) +PYSIDE_TEST(engine_test.py) +PYSIDE_TEST(property_test.py) +PYSIDE_TEST(qscriptvalue_test.py) diff --git a/sources/pyside2/tests/QtScript/base_test.py b/sources/pyside2/tests/QtScript/base_test.py new file mode 100644 index 000000000..623610ac0 --- /dev/null +++ b/sources/pyside2/tests/QtScript/base_test.py @@ -0,0 +1,32 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $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$ +## +############################################################################# + +from PySide2 import QtScript + + +#only test if the module import works fine bug #278 diff --git a/sources/pyside2/tests/QtScript/bug_1022.py b/sources/pyside2/tests/QtScript/bug_1022.py new file mode 100644 index 000000000..740180709 --- /dev/null +++ b/sources/pyside2/tests/QtScript/bug_1022.py @@ -0,0 +1,41 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $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 unittest + +from PySide2.QtCore import * +from PySide2.QtScript import * + +class QScriptValueTest(unittest.TestCase): + def testQScriptValue(self): + app = QCoreApplication([]) + engine = QScriptEngine() + repr(engine.evaluate('1 + 1')) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtScript/engine_test.py b/sources/pyside2/tests/QtScript/engine_test.py new file mode 100644 index 000000000..15f50fe29 --- /dev/null +++ b/sources/pyside2/tests/QtScript/engine_test.py @@ -0,0 +1,41 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $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 unittest + +from PySide2.QtCore import QObject +from PySide2.QtScript import QScriptEngine + +class QScriptEngineTest(unittest.TestCase): + + def testQScriptEngine(self): + engine = QScriptEngine() + obj = engine.evaluate("({ unitName: 'Celsius', toKelvin: function(x) { return x + 273; } })") + toKelvin = obj.property("toKelvin") + result = toKelvin.call(obj, [100]) + self.assertEqual(result.toNumber(), 373) diff --git a/sources/pyside2/tests/QtScript/property_test.py b/sources/pyside2/tests/QtScript/property_test.py new file mode 100644 index 000000000..b958d3106 --- /dev/null +++ b/sources/pyside2/tests/QtScript/property_test.py @@ -0,0 +1,90 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $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 unittest + +from PySide2.QtCore import QObject, Property, QCoreApplication +from PySide2.QtScript import QScriptEngine + +class MyObject(QObject): + def __init__(self, parent = None): + QObject.__init__(self, parent) + self._p = 100 + + def setX(self, value): + self._p = value + + def getX(self): + return self._p + + def resetX(self): + self._p = 100 + + def delX(self): + self._p = 0 + + x = Property(int, getX, setX, resetX, delX) + + +class QPropertyTest(unittest.TestCase): + + def testSimple(self): + o = MyObject() + self.assertEqual(o.x, 100) + o.x = 42 + self.assertEqual(o.x, 42) + + def testHasProperty(self): + o = MyObject() + o.setProperty("x", 10) + self.assertEqual(o.x, 10) + self.assertEqual(o.property("x"), 10) + + def testMetaProperty(self): + o = MyObject() + m = o.metaObject() + found = False + for i in range(m.propertyCount()): + mp = m.property(i) + if mp.name() == "x": + found = True + break + self.assertTrue(found) + + def testScriptQProperty(self): + qapp = QCoreApplication([]) + myEngine = QScriptEngine() + obj = MyObject() + scriptObj = myEngine.newQObject(obj) + myEngine.globalObject().setProperty("obj", scriptObj) + myEngine.evaluate("obj.x = 42") + self.assertEqual(scriptObj.property("x").toInt32(), 42) + self.assertEqual(obj.property("x"), 42) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtScript/qscriptvalue_test.py b/sources/pyside2/tests/QtScript/qscriptvalue_test.py new file mode 100644 index 000000000..1e1a16677 --- /dev/null +++ b/sources/pyside2/tests/QtScript/qscriptvalue_test.py @@ -0,0 +1,72 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $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$ +## +############################################################################# + +from __future__ import print_function + +import unittest + +from PySide2.QtScript import * + +# Required for eval() to work +import PySide2.QtScript + +from helper import UsesQApplication + +class TestQScriptValue (UsesQApplication): + + def testOperator(self): + engine = QScriptEngine() + value = engine.evaluate('x = {"a": 1, "b":2}') + self.assertEqual(value['a'], 1) + self.assertRaises(KeyError, value.__getitem__, 'c') + value = engine.evaluate('x = ["x", "y", "z"]') + self.assertEqual(value[2], 'z') + self.assertRaises(IndexError, value.__getitem__, 23) + + def testRepr(self): + value = QScriptValue("somePerson = { firstName: 'John', lastName: 'Doe' }") + print(repr(value)) + value2 = eval(repr(value)) + self.assertEqual(value.toString(), value2.toString()) + self.assertEqual(value.toVariant(), value2.toVariant()) + + def testIteratorProtocol(self): + engine = QScriptEngine() + value = engine.evaluate('x = {"a": 1, "b":2}') + d = {} + for k, v in QScriptValueIterator(value): + d[k] = v + self.assertEqual(d, {'a': 1, 'b': 2}) + + d = {} + for k, v in value: + d[k] = v + self.assertEqual(d, {'a': 1, 'b': 2}) + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3