24 print(
"pyuno not found: try to set PYTHONPATH and URE_BOOTSTRAP variables")
25 print(
"to something like:")
26 print(
" PYTHONPATH=/installation/opt/program")
27 print(
" URE_BOOTSTRAP=file:///installation/opt/program/fundamentalrc")
33 print(
"UNO API class not found: try to set URE_BOOTSTRAP variable")
34 print(
"to something like:")
35 print(
" URE_BOOTSTRAP=file:///installation/opt/program/fundamentalrc")
39 from urllib.parse
import quote
41 from urllib
import quote
49 '''mkPropertyValues(Name=Value, Name=Value,...) -> (PropertyValue, PropertyValue,...)
52 return tuple(PropertyValue(k,0,kwargs[k],0)
for k
in kwargs)
55 return pyuno.fileUrlToSystemPath(url)
58 return pyuno.systemPathToFileUrl(systemPath)
76 prog = self.
args[
"program"]
78 prog = os.getenv(
"SOFFICE_BIN")
80 raise Exception(
"SOFFICE_BIN must be set")
81 channel =
"pipe,name=pytest" + str(uuid.uuid1())
83 userdir = self.
args[
"userdir"]
85 userdir =
"file:///tmp"
86 if not(userdir.startswith(
"file://")):
87 raise Exception(
"--userdir must be file URL")
92 argv = [ soffice,
"--accept=" + channel +
";urp",
93 "-env:UserInstallation=" + userdir,
95 "--norestore",
"--nologo",
"--headless"]
96 if "--valgrind" in self.
args:
97 argv.append(
"--valgrind")
99 print (
"starting LibreOffice with channel: ", channel)
100 return subprocess.Popen(argv)
104 xUnoResolver = xLocalContext.ServiceManager.createInstanceWithContext(
105 "com.sun.star.bridge.UnoUrlResolver", xLocalContext)
106 url = (
"uno:%s;urp;StarOffice.ComponentContext" % channel)
108 print(
"Connecting to: ", url)
111 self.
xContext = xUnoResolver.resolve(url)
114 except pyuno.getClass(
"com.sun.star.connection.NoConnectException"):
115 print(
"WARN: NoConnectException: sleeping...")
123 print(
"tearDown: calling terminate()...")
125 xDesktop = xMgr.createInstanceWithContext(
126 "com.sun.star.frame.Desktop", self.
xContext)
131 except pyuno.getClass(
"com.sun.star.beans.UnknownPropertyException"):
132 print(
"caught UnknownPropertyException")
135 print(
"caught DisposedException")
144 raise Exception(
"Exit status indicates failure: " + str(ret))
164 desktop = smgr.createInstanceWithContext(
"com.sun.star.frame.Desktop", self.
getContext())
165 props = [(
"Hidden",
True), (
"ReadOnly",
False)]
166 loadProps = tuple([
mkPropertyValue(name, value)
for (name, value)
in props])
167 self.
xDoc = desktop.loadComponentFromURL(
"private:factory/swriter",
"_blank", 0, loadProps)
171 for k,v
in dict.items():
172 obj.setPropertyValue(k, v)
173 value = obj.getPropertyValue(k)
174 test.assertEqual(value, v)
196 pyuno.private_initTestEnvironment()
206 props = [(
"Hidden", bHidden), (
"ReadOnly", bReadOnly)]
217 return self.
openDocFromURL(pathlib.Path(file).as_uri(), asTemplate)
220 props = [(
"Hidden",
True), (
"ReadOnly",
False), (
"AsTemplate", asTemplate)]
226 desktop = smgr.createInstanceWithContext(
"com.sun.star.frame.Desktop", self.
getContext())
227 loadProps = tuple([
mkPropertyValue(name, value)
for (name, value)
in props])
228 self.
xDoc = desktop.loadComponentFromURL(url,
"_blank", 0, loadProps)
233 for k,v
in dict.items():
234 obj.setPropertyValue(k, v)
235 value = obj.getPropertyValue(k)
236 test.assertEqual(value, v)
239 for k,v
in dict.items():
240 obj.setPropertyValue(k, v)
245 if hasattr(self,
'xDoc'):
247 self.
xDoc.close(
True)
256 test.run(connection.getContext())
258 connection.postTest()
267 test.run(connection.getContext())
270 connection.postTest()
271 except KeyboardInterrupt:
274 print(
"retryInvoke: caught exception")
275 raise Exception(
"FAILED retryInvoke")
281 invoker(connection, test)
283 connection.tearDown()
286 src = os.getenv(
"TDOC")
287 assert(src
is not None)
288 src = os.path.join(src, file)
289 dst = os.getenv(
"TestUserDir")
290 assert(dst
is not None)
291 uri = urllib.parse.urlparse(dst)
292 assert(uri.scheme.casefold() ==
"file")
293 assert(uri.netloc ==
"" or uri.netloc.casefold() ==
"localhost")
294 assert(uri.params ==
"")
295 assert(uri.query ==
"")
296 assert(uri.fragment ==
"")
297 dst = urllib.request.url2pathname(uri.path)
298 dst = os.path.join(dst,
"tmp", file)
299 os.makedirs(os.path.dirname(dst), exist_ok=
True)
302 except FileNotFoundError:
304 shutil.copyfile(src, dst)
309if __name__ ==
"__main__":
310 parser = argparse.ArgumentParser(
"Help utilities for testing LibreOffice")
311 group = parser.add_mutually_exclusive_group()
312 group.add_argument(
"-v",
"--verbose", help=
"increase output verbosity", action=
"store_true")
314 args = parser.parse_args()
317 con = PersistentConnection({
"verbose" : args.verbose})
318 print(
"starting soffice ... ", end=
"")
322 print (
"shutting down ... ", end=
"")
def connect(self, channel)
def bootstrap(self, soffice, userdir, channel)
def openTemplateFromTDOC(self, file)
def openDocFromTDOC(self, file, asTemplate=False)
def openEmptyCalcDoc(self)
def checkProperties(self, obj, dict, test)
def setProperties(self, obj, dict)
def openDocFromURL(self, url, asTemplate=False)
def openEmptyWriterDoc(self)
def openDocFromAbsolutePath(self, file, asTemplate=False)
def __openDocFromURL(self, url, props)
def openEmptyDoc(self, url, bHidden=True, bReadOnly=False)
def openEmptyWriterDoc(self)
def checkProperties(self, obj, dict, test)
def mkPropertyValues(**kwargs)
def systemPathToFileUrl(systemPath)
def mkPropertyValue(name, value)
utilities ###
def makeCopyFromTDOC(file)
def retryInvoke(connection, test)
def fileUrlToSystemPath(url)
def simpleInvoke(connection, test)
def runConnectionTests(connection, invoker, tests)
PyRef getClass(const OUString &name, const Runtime &runtime)
def getComponentContext()
def createUnoStruct(typeName, *args, **kwargs)