Debian Codegraph @

tests/test_iterable/test_iterable.qml

raw
1 import QtQuick 2.0
2 import io.thp.pyotherside 1.3
3
4 Python {
5 property var tests: ([])
6
7 Component.onCompleted: {
8 addImportPath(Qt.resolvedUrl('.'));
9
10 importModule('test_iterable', function () {
11 function test_next() {
12 console.log('================================');
13 if (tests.length == 0) {
14 console.log('Tests completed');
15 Qt.quit();
16 } else {
17 var test = tests.pop();
18 console.log('-> ' + test.name);
19 call(test.func, [], function (reply) {
20 if (reply === undefined || reply === null) {
21 error('Got undefined or null');
22 return;
23 }
24
25 // Sort, because a Python set is unordered (to make expected work below)
26 reply.sort(function (a, b) { return a - b; });
27
28 console.log('Got: ' + reply);
29 console.log('Expected: ' + test.expected);
30 if (reply.toString() !== test.expected.toString()) {
31 error('Results do not match');
32 return;
33 }
34 test_next();
35 });
36 }
37 }
38
39 tests.unshift({
40 name: 'Getting set returns JS array',
41 func: 'test_iterable.get_set',
42 expected: [1, 2, 3]
43 });
44 tests.unshift({
45 name: 'Getting generator expression returns JS array',
46 func: 'test_iterable.get_iterable_generator_expression',
47 expected: [0, 2, 4, 6]
48 });
49 tests.unshift({
50 name: 'Getting generator returns JS array',
51 func: 'test_iterable.get_iterable_generator',
52 expected: [0, 3, 6, 9, 12]
53 });
54
55 test_next();
56 });
57 }
58
59 onError: {
60 console.log('Error: ' + traceback);
61 console.log('Tests failed');
62 Qt.quit();
63 }
64 }