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
+6
-2
@@ -12,9 +12,13 @@ import pygame
|
|||||||
|
|
||||||
def load_speech():
|
def load_speech():
|
||||||
"""Load speech code without initializing the library or a speech provider."""
|
"""Load speech code without initializing the library or a speech provider."""
|
||||||
spec = importlib.util.spec_from_file_location(
|
packageName = "_speech_test_library"
|
||||||
"_speech_test_library.speech", Path(__file__).resolve().parents[1] / "speech.py")
|
# 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)
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
with patch.dict(sys.modules, {packageName: package}):
|
||||||
spec.loader.exec_module(module)
|
spec.loader.exec_module(module)
|
||||||
return module
|
return module
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user