Ejemplo n.º 1
0
class DebuggerTest(UsesQApplication):

    def setUp(self):
        UsesQApplication.setUp(self)
        self.engine = QScriptEngine()
        self.debugger = QScriptEngineDebugger()
        self.has_suspended = 0
        self.has_resumed = 0
        self.count = 3

    def suspended(self):
        self.has_suspended += 1
        # Will emit evaluationResumed until there are more instructions to be run
        QTimer.singleShot(100, self.debugger.action(QScriptEngineDebugger.StepIntoAction).trigger)

    def resumed(self):
        # Will be called when debugger.state() change from Suspended to Running
        # except for the first time.
        self.has_resumed += 1

    def testBasic(self):
        '''Interrupt and resume evaluation with QScriptEngineDebugger'''

        self.debugger.attachTo(self.engine)
        self.debugger.setAutoShowStandardWindow(False)
        self.debugger.connect(SIGNAL('evaluationSuspended()'), self.suspended)
        self.debugger.connect(SIGNAL('evaluationResumed()'), self.resumed)

        self.debugger.action(QScriptEngineDebugger.InterruptAction).trigger()
        self.engine.evaluate("3+4\n2+1\n5+1")
        self.assert_(self.has_resumed >= 1)
        self.assert_(self.has_suspended >= 1)
Ejemplo n.º 2
0
 def setUp(self):
     UsesQApplication.setUp(self)
     self.engine = QScriptEngine()
     self.debugger = QScriptEngineDebugger()
     self.has_suspended = 0
     self.has_resumed = 0
     self.count = 3
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
class DebuggerTest(UsesQApplication):
    def setUp(self):
        UsesQApplication.setUp(self)
        self.engine = QScriptEngine()
        self.debugger = QScriptEngineDebugger()
        self.has_suspended = 0
        self.has_resumed = 0
        self.count = 3

    def suspended(self):
        self.has_suspended += 1
        # Will emit evaluationResumed until there are more instructions to be run
        QTimer.singleShot(
            100,
            self.debugger.action(QScriptEngineDebugger.StepIntoAction).trigger)

    def resumed(self):
        # Will be called when debugger.state() change from Suspended to Running
        # except for the first time.
        self.has_resumed += 1

    def testBasic(self):
        '''Interrupt and resume evaluation with QScriptEngineDebugger'''

        self.debugger.attachTo(self.engine)
        self.debugger.setAutoShowStandardWindow(False)
        self.debugger.connect(SIGNAL('evaluationSuspended()'), self.suspended)
        self.debugger.connect(SIGNAL('evaluationResumed()'), self.resumed)

        # For some reason StepIntoAction does not actually continue execution, and thus interrupting
        # causes the test to hang. The same behavior is present in a Qt5.6 C++ code equivalent. It
        # seems like a bug in QtScript, thus the interruption is commented out for now, which will
        # force the test to fail.
        #self.debugger.action(QScriptEngineDebugger.InterruptAction).trigger()
        self.engine.evaluate("3+4\n2+1\n5+1")
        self.assertTrue(self.has_resumed >= 1)
        self.assertTrue(self.has_suspended >= 1)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)