-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert Python set and iterable to JS Array
- Loading branch information
Showing
8 changed files
with
150 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def get_set(): | ||
return set((1, 2, 3)) | ||
|
||
def get_iterable_generator_expression(): | ||
return (x * 2 for x in range(4)) | ||
|
||
def get_iterable_generator(): | ||
for i in range(5): | ||
yield i * 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import QtQuick 2.0 | ||
import io.thp.pyotherside 1.3 | ||
|
||
Python { | ||
property var tests: ([]) | ||
|
||
Component.onCompleted: { | ||
addImportPath(Qt.resolvedUrl('.')); | ||
|
||
importModule('test_iterable', function () { | ||
function test_next() { | ||
console.log('================================'); | ||
if (tests.length == 0) { | ||
console.log('Tests completed'); | ||
Qt.quit(); | ||
} else { | ||
var test = tests.pop(); | ||
console.log('-> ' + test.name); | ||
call(test.func, [], function (reply) { | ||
if (reply === undefined || reply === null) { | ||
error('Got undefined or null'); | ||
return; | ||
} | ||
|
||
// Sort, because a Python set is unordered (to make expected work below) | ||
reply.sort(function (a, b) { return a - b; }); | ||
|
||
console.log('Got: ' + reply); | ||
console.log('Expected: ' + test.expected); | ||
if (reply.toString() !== test.expected.toString()) { | ||
error('Results do not match'); | ||
return; | ||
} | ||
test_next(); | ||
}); | ||
} | ||
} | ||
|
||
tests.unshift({ | ||
name: 'Getting set returns JS array', | ||
func: 'test_iterable.get_set', | ||
expected: [1, 2, 3] | ||
}); | ||
tests.unshift({ | ||
name: 'Getting generator expression returns JS array', | ||
func: 'test_iterable.get_iterable_generator_expression', | ||
expected: [0, 2, 4, 6] | ||
}); | ||
tests.unshift({ | ||
name: 'Getting generator returns JS array', | ||
func: 'test_iterable.get_iterable_generator', | ||
expected: [0, 3, 6, 9, 12] | ||
}); | ||
|
||
test_next(); | ||
}); | ||
} | ||
|
||
onError: { | ||
console.log('Error: ' + traceback); | ||
console.log('Tests failed'); | ||
Qt.quit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters