Debian Codegraph @

tests/test_nested_import/example_api10.qml

raw
1 import QtQuick 2.0
2 import io.thp.pyotherside 1.0
3
4 Python {
5 Component.onCompleted: {
6 addImportPath(Qt.resolvedUrl('.'));
7
8 /**
9 * Here, we test the broken behavior of the PyOtherSide 1.0 API
10 * for imports with "." in the name:
11 * 1. It uses PyImport_ImportModule() which does a "*"_import
12 * 2. The variable in the globals dict that gets set is the full
13 * module name (and not the module after the "." for
14 * non-"*"-imports) including the dot, which is broken, anyway, as
15 * there's not way to retrieve that name in normal Python syntax
16 * (names cannot contain a "."), so for this test we use a dirty
17 * way of accessing they key via the globals() dict (just for
18 * testing - I hope nobody used that in old code, but we want to
19 * have a stable API, so we will drag this behavior along with the
20 * 1.0 API support - new code should definitely use the 1.2 API)
21 **/
22
23 importModule('thp_io.pyotherside.nested', function () {
24 console.log('"nested" imported successfully');
25
26 // In API version 1.0, we expect the import to have done a "*"
27 // import, and to add insult to injury, we assign the module
28 // name with a ".", which basically makes the import unaccessible
29 // from normal Python code (the entry in the globals dict contains
30 // a ".", which isn't a valid name in Python), so we access the
31 // globals dictionary directly
32 console.log('repr of the module: ' + evaluate('repr(globals()["thp_io.pyotherside.nested"])'));
33 call('globals()["thp_io.pyotherside.nested"].info', [], function (result) {
34 console.log('from nested.info(): ' + result);
35 });
36
37 importModule('thp_io.pyotherside.nested.module', function () {
38 console.log('"nested.module" imported successfully');
39 // Globals hack - see above
40 call('globals()["thp_io.pyotherside.nested.module"].info', [], function (result) {
41 console.log('from nested.module.info(): ' + result);
42 // Globals hack again - see above
43 console.log('nested.module.value: ' + evaluate('globals()["thp_io.pyotherside.nested.module"].value'));
44 Qt.quit();
45 });
46 });
47 });
48 }
49 }