unotest.py: refactor confusing mess of openDoc functions
Change-Id: I148332c639510c55dea2d09bc7aa695708fbf34c
This commit is contained in:
parent
01cc6e5107
commit
01b0d6da7f
@ -20,7 +20,7 @@ class Fdo84315(unittest.TestCase):
|
||||
cls._uno = UnoInProcess()
|
||||
cls._uno.setUp()
|
||||
workdir = os.environ[ "WORKDIR_FOR_BUILD" ]
|
||||
cls._xDoc = cls._uno.openDoc(workdir + "/CppunitTest/fdo84315.odb")
|
||||
cls._xDoc = cls._uno.openDocFromAbsolutePath(workdir + "/CppunitTest/fdo84315.odb")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
@ -38,7 +38,7 @@ class CheckCrossReferences(unittest.TestCase):
|
||||
def setUpClass(cls):
|
||||
cls._uno = UnoInProcess()
|
||||
cls._uno.setUp()
|
||||
cls.document = cls._uno.openWriterTemplateDoc("CheckCrossReferences.odt")
|
||||
cls.document = cls._uno.openDocFromTDOC("CheckCrossReferences.odt")
|
||||
cls.xParaEnum = None
|
||||
cls.xPortionEnum = None
|
||||
cls.xFieldsRefresh = None
|
||||
|
@ -17,7 +17,7 @@ class CheckFields(unittest.TestCase):
|
||||
def setUpClass(cls):
|
||||
cls._uno = UnoInProcess()
|
||||
cls._uno.setUp()
|
||||
cls._xDoc = cls._uno.openWriterTemplateDoc("fdo39694.ott")
|
||||
cls._xDoc = cls._uno.openTemplateFromTDOC("fdo39694.ott")
|
||||
cls._xEmptyDoc = cls._uno.openEmptyWriterDoc()
|
||||
|
||||
@classmethod
|
||||
|
@ -26,7 +26,7 @@ class CheckFlies(unittest.TestCase):
|
||||
def setUpClass(cls):
|
||||
cls._uno = UnoInProcess()
|
||||
cls._uno.setUp()
|
||||
cls.document = cls._uno.openWriterTemplateDoc("CheckFlies.odt")
|
||||
cls.document = cls._uno.openDocFromTDOC("CheckFlies.odt")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
@ -3250,7 +3250,7 @@ class TextPortionEnumerationTest(unittest.TestCase):
|
||||
def doload(self, file):
|
||||
xComp = None
|
||||
print("Loading test document...")
|
||||
xComp = self.__class__._uno.openDoc(file)
|
||||
xComp = self.__class__._uno.openDocFromAbsolutePath(file)
|
||||
self.assertIsNotNone(xComp, "cannot load: {}".format(file))
|
||||
print("...done")
|
||||
return xComp
|
||||
@ -3266,7 +3266,7 @@ class TextPortionEnumerationTest(unittest.TestCase):
|
||||
xComp = None
|
||||
filename = "TESTMETA.odt"
|
||||
try:
|
||||
xComp = self.__class__._uno.openBaseDoc(filename)
|
||||
xComp = self.__class__._uno.openDocFromTDOC(filename)
|
||||
if xComp:
|
||||
self.checkloadmeta(xComp)
|
||||
with TemporaryDirectory() as tempdir:
|
||||
@ -3338,7 +3338,7 @@ class TextPortionEnumerationTest(unittest.TestCase):
|
||||
xComp = None
|
||||
filename = "TESTXMLID.odt"
|
||||
try:
|
||||
xComp = self.__class__._uno.openBaseDoc(filename)
|
||||
xComp = self.__class__._uno.openDocFromTDOC(filename)
|
||||
if xComp:
|
||||
self.checkloadxmlid(xComp)
|
||||
with TemporaryDirectory() as tempdir:
|
||||
|
@ -195,72 +195,45 @@ class UnoInProcess:
|
||||
if not(havePonies):
|
||||
pyuno.private_initTestEnvironment()
|
||||
havePonies = True
|
||||
|
||||
def openEmptyWriterDoc(self):
|
||||
assert(self.xContext)
|
||||
smgr = self.getContext().ServiceManager
|
||||
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
|
||||
props = [("Hidden", True), ("ReadOnly", False)]
|
||||
loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
|
||||
self.xDoc = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, loadProps)
|
||||
assert(self.xDoc)
|
||||
return self.xDoc
|
||||
return self.openEmptyDoc("private:factory/swriter")
|
||||
|
||||
def openEmptyCalcDoc(self):
|
||||
self.xDoc = self.openEmptyDoc("private:factory/scalc")
|
||||
return self.xDoc
|
||||
return self.openEmptyDoc("private:factory/scalc")
|
||||
|
||||
def openEmptyDoc(self, url, bHidden = True, bReadOnly = False):
|
||||
assert(self.xContext)
|
||||
smgr = self.getContext().ServiceManager
|
||||
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
|
||||
props = [("Hidden", bHidden), ("ReadOnly", bReadOnly)]
|
||||
loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
|
||||
self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
|
||||
assert(self.xDoc)
|
||||
return self.xDoc
|
||||
return self.__openDocFromURL(url, props)
|
||||
|
||||
def openWriterTemplateDoc(self, file):
|
||||
assert(self.xContext)
|
||||
smgr = self.getContext().ServiceManager
|
||||
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
|
||||
props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", True)]
|
||||
loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
|
||||
def openTemplateFromTDOC(self, file):
|
||||
return self.openDocFromTDOC(file, True)
|
||||
|
||||
def openDocFromTDOC(self, file, asTemplate = False):
|
||||
path = os.getenv("TDOC")
|
||||
if os.name == "nt":
|
||||
# do not quote drive letter - it must be "X:"
|
||||
url = "file:///" + path + "/" + quote(file)
|
||||
else:
|
||||
url = "file://" + quote(path) + "/" + quote(file)
|
||||
self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
|
||||
assert(self.xDoc)
|
||||
return self.xDoc
|
||||
return self.openDocFromURL(url, asTemplate)
|
||||
|
||||
def openBaseDoc(self, file):
|
||||
assert(self.xContext)
|
||||
smgr = self.getContext().ServiceManager
|
||||
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
|
||||
props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", False)]
|
||||
loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
|
||||
path = os.getenv("TDOC")
|
||||
if os.name == "nt":
|
||||
#do not quote drive letter - it must be "X:"
|
||||
url = "file:///" + path + "/" + quote(file)
|
||||
else:
|
||||
url = "file://" + quote(path) + "/" + quote(file)
|
||||
self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
|
||||
assert(self.xDoc)
|
||||
return self.xDoc
|
||||
|
||||
def openDoc(self, file):
|
||||
assert(self.xContext)
|
||||
smgr = self.getContext().ServiceManager
|
||||
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
|
||||
props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", False)]
|
||||
loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
|
||||
def openDocFromAbsolutePath(self, file):
|
||||
if os.name == "nt":
|
||||
url = "file:///" + file
|
||||
else:
|
||||
url = "file://" + file
|
||||
return self.openDocFromURL(url)
|
||||
|
||||
def openDocFromURL(self, url, asTemplate = False):
|
||||
props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", asTemplate)]
|
||||
return self.__openDocFromURL(url, props)
|
||||
|
||||
def __openDocFromURL(self, url, props):
|
||||
assert(self.xContext)
|
||||
smgr = self.getContext().ServiceManager
|
||||
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
|
||||
loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
|
||||
self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
|
||||
assert(self.xDoc)
|
||||
return self.xDoc
|
||||
|
Loading…
x
Reference in New Issue
Block a user