Skip to content

Commit d4bf285

Browse files
committed
Fix CI: handle surrogate strings in import, add expectedFailure for Windows-only tests
- Use to_str() instead of as_str() in import_module_level and get_spec_origin to avoid panic on strings with surrogates - Add @expectedfailure for test_dll_dependency_import (no C extension), test_unencodable_filename (subprocess), test_tagged_suffix (no .pyd)
1 parent 5c6b68b commit d4bf285

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Lib/test/test_import/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ def run():
768768
finally:
769769
del sys.path[0]
770770

771+
@unittest.expectedFailure # TODO: RUSTPYTHON; no C extension support
771772
@unittest.skipUnless(sys.platform == "win32", "Windows-specific")
772773
def test_dll_dependency_import(self):
773774
from _winapi import GetModuleFileName
@@ -2043,6 +2044,7 @@ def exec_module(*args):
20432044
else:
20442045
importlib.SourceLoader.exec_module = old_exec_module
20452046

2047+
@unittest.expectedFailure # TODO: RUSTPYTHON; subprocess fails on Windows
20462048
@unittest.skipUnless(TESTFN_UNENCODABLE, 'need TESTFN_UNENCODABLE')
20472049
def test_unencodable_filename(self):
20482050
# Issue #11619: The Python parser and the import machinery must not

Lib/test/test_importlib/test_windows.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def test_raises_deprecation_warning(self):
139139

140140
@unittest.skipUnless(sys.platform.startswith('win'), 'requires Windows')
141141
class WindowsExtensionSuffixTests:
142+
@unittest.expectedFailure # TODO: RUSTPYTHON; no C extension (.pyd) support
142143
def test_tagged_suffix(self):
143144
suffixes = self.machinery.EXTENSION_SUFFIXES
144145
abi_flags = "t" if support.Py_GIL_DISABLED else ""

crates/vm/src/import.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub(crate) fn get_spec_file_origin(
257257
} else {
258258
origin
259259
.downcast_ref::<PyStr>()
260-
.map(|s| s.as_str().to_owned())
260+
.and_then(|s| s.to_str().map(|s| s.to_owned()))
261261
}
262262
})
263263
}
@@ -354,7 +354,9 @@ pub fn import_module_level(
354354
return Err(vm.new_value_error("level must be >= 0".to_owned()));
355355
}
356356

357-
let name_str = name.as_str();
357+
let name_str = name.to_str().ok_or_else(|| {
358+
vm.new_value_error("module name cannot contain surrogates".to_owned())
359+
})?;
358360

359361
// Resolve absolute name
360362
let abs_name = if level > 0 {

0 commit comments

Comments
 (0)