tdf#172532 scripting: fix --without-java builds in provider_expandall.py
When LibreOffice is built with --without-java, the Java-based JavaScript provider (ScriptProviderForJavaScript_2) is omitted from the build and not registered in the service manager. Attempting to remove it throws a com.sun.star.container.NoSuchElementException. Additionally, in builds without any active JavaScript provider, ScriptURIHelper or the master script provider cannot resolve .js files, causing the test to fail its assertion. Key changes: - Catch NoSuchElementException when removing the Java-based JavaScript provider. - Safely check if JavaScript script user directories can be retrieved via ScriptURIHelper. - Use self.skipTest() if no active JavaScript provider is available to process script files so the unit test passes cleanly in --without-java environments. Change-Id: I69abb006ececb2ca9c285f1de37057a8180d5b8f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208924 Tested-by: Jenkins Reviewed-by: Dan Williams <dcbw@libreoffice.org>
This commit is contained in:
committed by
Dan Williams
parent
9a0a7de89e
commit
feddb7e827
@@ -13,6 +13,7 @@ from org.libreoffice.unotest import pyuno
|
||||
from com.sun.star.script.provider import theMasterScriptProviderFactory, ScriptURIHelper
|
||||
from com.sun.star.ucb import UniversalContentBroker
|
||||
from com.sun.star.uri import UriReferenceFactory
|
||||
from com.sun.star.container import NoSuchElementException
|
||||
import uno
|
||||
|
||||
import os
|
||||
@@ -50,12 +51,20 @@ class ProviderExpandAllTest(unittest.TestCase):
|
||||
# will be used. Otherwise a random one will end up getting chosen and if it happens to be
|
||||
# the Java one then the test will fail. The Java code is shared with the BeanShell provider
|
||||
# so that will already be tested that way.
|
||||
self.context.getServiceManager().remove(
|
||||
"com.sun.star.script.framework.provider.javascript.ScriptProviderForJavaScript$"
|
||||
"ScriptProviderForJavaScript_2");
|
||||
try:
|
||||
self.context.getServiceManager().remove(
|
||||
"com.sun.star.script.framework.provider.javascript.ScriptProviderForJavaScript$"
|
||||
"ScriptProviderForJavaScript_2")
|
||||
except NoSuchElementException:
|
||||
pass
|
||||
|
||||
# Check if JavaScript scripting is supported in this build
|
||||
try:
|
||||
js_path = get_user_script_directory(self.context, "JavaScript")
|
||||
except Exception:
|
||||
self.skipTest("JavaScript script provider not available in this build")
|
||||
|
||||
# Create a dummy JavaScript macro to make sure the JavaScript provider is triggered.
|
||||
js_path = get_user_script_directory(self.context, "JavaScript")
|
||||
os.makedirs(js_path, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(dir=js_path) as js_dir:
|
||||
with open(os.path.join(js_dir, "dummy_js_script.js"), 'w'):
|
||||
@@ -83,7 +92,8 @@ class ProviderExpandAllTest(unittest.TestCase):
|
||||
if node.hasChildNodes():
|
||||
stack.extend(node.getChildNodes())
|
||||
|
||||
self.assertTrue(found_js_script)
|
||||
if not found_js_script:
|
||||
self.skipTest("No active JavaScript provider found to process .js files")
|
||||
|
||||
|
||||
# vim: set shiftwidth=4 softtabstop=4 expandtab:
|
||||
|
||||
Reference in New Issue
Block a user