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