1
0
mirror of https://github.com/thp/pyotherside.git synced 2025-02-05 08:08:23 +08:00
pyotherside/tests/test_callback_errors/test_callback_errors.qml
Thomas Perl 4028d4f3b8 QML API 1.2: Handle JS exceptions in callbacks from Python
Also improve error message in pyotherside.send() callback handler
to include filename and line number.
2014-02-12 23:02:57 +01:00

42 lines
1.1 KiB
QML

import QtQuick 2.0
import io.thp.pyotherside 1.2
// Test if PyOtherSide correctly reports JS errors happening in callbacks
// in signal error(string traceback) for both imports and function calls.
Python {
property var tests: ([])
function test_next() {
if (tests.length) {
tests.pop()();
} else {
console.log('Tests done');
Qt.quit();
}
}
Component.onCompleted: {
tests.unshift(function () {
console.log('Expecting ReferenceError for "invalid" on import');
importModule('os', function (success) {
invalid;
});
});
tests.unshift(function() {
console.log('Expecting TypeError for "lock" property');
call('os.getcwd', [], function (result) {
console.lock(result);
});
});
test_next();
}
onError: {
// Remove full path to .qml file
var msg = traceback.replace(Qt.resolvedUrl('.'), '');
console.log('Got error: ' + msg);
test_next();
}
}