aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/iOS/testbed
diff options
context:
space:
mode:
Diffstat (limited to 'iOS/testbed')
-rw-r--r--iOS/testbed/__main__.py2
-rw-r--r--iOS/testbed/iOSTestbedTests/iOSTestbedTests.m51
2 files changed, 42 insertions, 11 deletions
diff --git a/iOS/testbed/__main__.py b/iOS/testbed/__main__.py
index c05497ede3a..1146bf3b988 100644
--- a/iOS/testbed/__main__.py
+++ b/iOS/testbed/__main__.py
@@ -127,7 +127,7 @@ async def async_check_output(*args, **kwargs):
async def select_simulator_device():
# List the testing simulators, in JSON format
raw_json = await async_check_output(
- "xcrun", "simctl", "--set", "testing", "list", "-j"
+ "xcrun", "simctl", "list", "-j"
)
json_data = json.loads(raw_json)
diff --git a/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m b/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m
index dd6e76f9496..b502a6eb277 100644
--- a/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m
+++ b/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m
@@ -15,6 +15,11 @@
PyStatus status;
PyPreConfig preconfig;
PyConfig config;
+ PyObject *app_packages_path;
+ PyObject *method_args;
+ PyObject *result;
+ PyObject *site_module;
+ PyObject *site_addsitedir_attr;
PyObject *sys_module;
PyObject *sys_path_attr;
NSArray *test_args;
@@ -111,29 +116,55 @@
return;
}
- sys_module = PyImport_ImportModule("sys");
- if (sys_module == NULL) {
- XCTFail(@"Could not import sys module");
+ // Add app_packages as a site directory. This both adds to sys.path,
+ // and ensures that any .pth files in that directory will be executed.
+ site_module = PyImport_ImportModule("site");
+ if (site_module == NULL) {
+ XCTFail(@"Could not import site module");
return;
}
- sys_path_attr = PyObject_GetAttrString(sys_module, "path");
- if (sys_path_attr == NULL) {
- XCTFail(@"Could not access sys.path");
+ site_addsitedir_attr = PyObject_GetAttrString(site_module, "addsitedir");
+ if (site_addsitedir_attr == NULL || !PyCallable_Check(site_addsitedir_attr)) {
+ XCTFail(@"Could not access site.addsitedir");
return;
}
- // Add the app packages path
path = [NSString stringWithFormat:@"%@/app_packages", resourcePath, nil];
NSLog(@"App packages path: %@", path);
wtmp_str = Py_DecodeLocale([path UTF8String], NULL);
- failed = PyList_Insert(sys_path_attr, 0, PyUnicode_FromString([path UTF8String]));
- if (failed) {
- XCTFail(@"Unable to add app packages to sys.path");
+ app_packages_path = PyUnicode_FromWideChar(wtmp_str, wcslen(wtmp_str));
+ if (app_packages_path == NULL) {
+ XCTFail(@"Could not convert app_packages path to unicode");
return;
}
PyMem_RawFree(wtmp_str);
+ method_args = Py_BuildValue("(O)", app_packages_path);
+ if (method_args == NULL) {
+ XCTFail(@"Could not create arguments for site.addsitedir");
+ return;
+ }
+
+ result = PyObject_CallObject(site_addsitedir_attr, method_args);
+ if (result == NULL) {
+ XCTFail(@"Could not add app_packages directory using site.addsitedir");
+ return;
+ }
+
+ // Add test code to sys.path
+ sys_module = PyImport_ImportModule("sys");
+ if (sys_module == NULL) {
+ XCTFail(@"Could not import sys module");
+ return;
+ }
+
+ sys_path_attr = PyObject_GetAttrString(sys_module, "path");
+ if (sys_path_attr == NULL) {
+ XCTFail(@"Could not access sys.path");
+ return;
+ }
+
path = [NSString stringWithFormat:@"%@/app", resourcePath, nil];
NSLog(@"App path: %@", path);
wtmp_str = Py_DecodeLocale([path UTF8String], NULL);