Let the speech tests load speech.py inside a package again
speech.py now imports its translations relatively, so loading it on its own failed with ModuleNotFoundError and every speech test errored. The tests now give it a package of its own, as the menu tests do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2624b137dc
commit
e6505790c2
1 file changed
+7
-3
@@ -12,10 +12,14 @@ import pygame
|
||||
|
||||
def load_speech():
|
||||
"""Load speech code without initializing the library or a speech provider."""
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"_speech_test_library.speech", Path(__file__).resolve().parents[1] / "speech.py")
|
||||
packageName = "_speech_test_library"
|
||||
# A package of its own, so speech's relative imports, such as its translations, resolve without the library.
|
||||
package = ModuleType(packageName)
|
||||
package.__path__ = [str(Path(__file__).resolve().parents[1])]
|
||||
spec = importlib.util.spec_from_file_location(f"{packageName}.speech", Path(package.__path__[0]) / "speech.py")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
with patch.dict(sys.modules, {packageName: package}):
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user