From 66e847f972df9948b7a0c1897b179a05b69e7c81 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 16 Sep 2024 23:27:11 -0400 Subject: [PATCH] tests: add variable to suppress TTS tests TTS support can be gated on e.g. Gentoo's USE=speech, so we don't want to run the basic selfcheck of speech support if this is disabled. We do want to run the general Qt checks, though (and also do a selfcheck of speech support if the USE=speech is enabled!) -- so add a sneaky environment variable that we can use to conditionally skip running those parts. --- src/calibre/test_build.py | 14 +++++++++----- src/calibre/utils/run_tests.py | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index 08f680b0fd..77852088bd 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -123,6 +123,7 @@ class BuildTest(unittest.TestCase): from speechd.client import SSIPClient del SSIPClient + @unittest.skipIf('SKIP_SPEECH_TESTS' in os.environ, 'Speech support is opted out') def test_piper(self): import subprocess @@ -322,7 +323,7 @@ class BuildTest(unittest.TestCase): def test_qt(self): if is_sanitized: raise unittest.SkipTest('Skipping Qt build test as sanitizer is enabled') - from qt.core import QApplication, QFontDatabase, QImageReader, QLoggingCategory, QMediaDevices, QNetworkAccessManager, QSslSocket, QTextToSpeech, QTimer + from qt.core import QApplication, QFontDatabase, QImageReader, QLoggingCategory, QNetworkAccessManager, QSslSocket, QTimer QLoggingCategory.setFilterRules('''qt.webenginecontext.debug=true''') if hasattr(os, 'geteuid') and os.geteuid() == 0: # likely a container build, webengine cannot run as root with sandbox @@ -356,12 +357,15 @@ class BuildTest(unittest.TestCase): try: ensure_app() self.assertGreaterEqual(len(QFontDatabase.families()), 5, 'The QPA headless plugin is not able to locate enough system fonts via fontconfig') - available_tts_engines = tuple(x for x in QTextToSpeech.availableEngines() if x != 'mock') - self.assertTrue(available_tts_engines) - QMediaDevices.audioOutputs() + if 'SKIP_SPEECH_TESTS' not in os.environ: + from qt.core import QMediaDevices, QTextToSpeech + + available_tts_engines = tuple(x for x in QTextToSpeech.availableEngines() if x != 'mock') + self.assertTrue(available_tts_engines) + + QMediaDevices.audioOutputs() - self.assertGreaterEqual from calibre.ebooks.oeb.transforms.rasterize import rasterize_svg img = rasterize_svg(as_qimage=True) self.assertFalse(img.isNull()) diff --git a/src/calibre/utils/run_tests.py b/src/calibre/utils/run_tests.py index 699582961a..e0e14bcb0b 100644 --- a/src/calibre/utils/run_tests.py +++ b/src/calibre/utils/run_tests.py @@ -190,6 +190,8 @@ class TestImports(unittest.TestCase): 'calibre.utils.linux_trash', 'calibre.utils.open_with.linux', 'calibre.gui2.linux_file_dialogs', } + if 'SKIP_SPEECH_TESTS' in os.environ: + exclude_packages.add('calibre.gui2.tts') if not isbsd: exclude_modules.add('calibre.devices.usbms.hal') d = os.path.dirname