Kaydet (Commit) 6e8eb540 authored tarafından David Ostrovsky's avatar David Ostrovsky Kaydeden (comit) Noel Power

Migrate CheckFields unit test to python

Change-Id: Ia765b37888b4095a735015e792f06fc89201d1a3
Reviewed-on: https://gerrit.libreoffice.org/4294Reviewed-by: 's avatarNoel Power <noel.power@suse.com>
Tested-by: 's avatarNoel Power <noel.power@suse.com>
üst b9155a66
...@@ -40,6 +40,7 @@ $(call gb_PythonTest_get_target,%) : ...@@ -40,6 +40,7 @@ $(call gb_PythonTest_get_target,%) :
($(gb_PythonTest_PRECOMMAND) \ ($(gb_PythonTest_PRECOMMAND) \
$(if $(G_SLICE),G_SLICE=$(G_SLICE)) \ $(if $(G_SLICE),G_SLICE=$(G_SLICE)) \
$(if $(GLIBCXX_FORCE_NEW),GLIBCXX_FORCE_NEW=$(GLIBCXX_FORCE_NEW)) \ $(if $(GLIBCXX_FORCE_NEW),GLIBCXX_FORCE_NEW=$(GLIBCXX_FORCE_NEW)) \
$(DEFS) \
URE_BOOTSTRAP=vnd.sun.star.pathname:$(call gb_Helper_get_rcfile,$(gb_DEVINSTALLROOT)/program/fundamental) \ URE_BOOTSTRAP=vnd.sun.star.pathname:$(call gb_Helper_get_rcfile,$(gb_DEVINSTALLROOT)/program/fundamental) \
PYTHONPATH="$(PYPATH)" \ PYTHONPATH="$(PYPATH)" \
UserInstallation=$(call gb_Helper_make_url,$(dir $(call gb_PythonTest_get_target,$*))user) \ UserInstallation=$(call gb_Helper_make_url,$(dir $(call gb_PythonTest_get_target,$*))user) \
...@@ -63,6 +64,11 @@ $(call gb_Helper_make_userfriendly_targets,$(1),PythonTest) ...@@ -63,6 +64,11 @@ $(call gb_Helper_make_userfriendly_targets,$(1),PythonTest)
endef endef
define gb_PythonTest_set_defs
$(call gb_PythonTest_get_target,$(1)) : DEFS := $(2)
endef
# put the directory on the PYTHONPATH because the "unittest" loader # put the directory on the PYTHONPATH because the "unittest" loader
# mysteriously fails to load modules given as absolute path unless the $PWD is # mysteriously fails to load modules given as absolute path unless the $PWD is
# a prefix of the absolute path, which it is not when we go into a certain # a prefix of the absolute path, which it is not when we go into a certain
...@@ -94,6 +100,7 @@ $(call gb_Helper_make_userfriendly_targets,$(1),PythonTest) ...@@ -94,6 +100,7 @@ $(call gb_Helper_make_userfriendly_targets,$(1),PythonTest)
endef endef
gb_PythonTest_set_defs :=
gb_PythonTest_add_modules := gb_PythonTest_add_modules :=
gb_PythonTest_use_customtarget := gb_PythonTest_use_customtarget :=
......
...@@ -9,8 +9,13 @@ ...@@ -9,8 +9,13 @@
$(eval $(call gb_PythonTest_PythonTest,sw_python)) $(eval $(call gb_PythonTest_PythonTest,sw_python))
$(eval $(call gb_PythonTest_set_defs,sw_python,\
TDOC="$(SRCDIR)/sw/qa/complex/writer/testdocuments" \
))
$(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_index \ check_index \
check_fields \
get_expression \ get_expression \
set_expression \ set_expression \
var_fields \ var_fields \
......
import unittest
from org.libreoffice.unotest import UnoInProcess
class CheckFields(unittest.TestCase):
_uno = None
_xDoc = None
@classmethod
def setUpClass(cls):
cls._uno = UnoInProcess()
cls._uno.setUp()
cls._xDoc = cls._uno.openWriterTemplateDoc("fdo39694.ott")
cls._xEmptyDoc = cls._uno.openEmptyWriterDoc()
@classmethod
def tearDownClass(cls):
cls._uno.tearDown()
def test_fdo39694_load(self):
placeholders = ["<Kadr1>", "<Kadr2>", "<Kadr3>", "<Kadr4>", "<Pnname>", "<Pvname>", "<Pgeboren>"]
xDoc = self.__class__._xDoc
xEnumerationAccess = xDoc.getTextFields()
xFieldEnum = xEnumerationAccess.createEnumeration()
while xFieldEnum.hasMoreElements():
xField = xFieldEnum.nextElement()
if xField.supportsService("com.sun.star.text.TextField.JumpEdit"):
xAnchor = xField.getAnchor()
readContent = xAnchor.getString()
self.assertTrue(readContent in placeholders,
"field %s is not contained: " % readContent)
def test_fdo42073(self):
xDoc = self.__class__._xEmptyDoc
xBodyText = xDoc.getText()
xCursor = xBodyText.createTextCursor()
xTextField = xDoc.createInstance("com.sun.star.text.TextField.Input")
xBodyText.insertTextContent(xCursor, xTextField, True)
readContent = xTextField.getPropertyValue("Content")
self.assertEqual("", readContent)
content = "this is not surprising"
xTextField.setPropertyValue("Content", content)
readContent = xTextField.getPropertyValue("Content")
self.assertEqual(content, readContent)
if __name__ == '__main__':
unittest.main()
...@@ -31,6 +31,11 @@ except ImportError: ...@@ -31,6 +31,11 @@ except ImportError:
print(" URE_BOOTSTRAP=file:///installation/opt/program/fundamentalrc") print(" URE_BOOTSTRAP=file:///installation/opt/program/fundamentalrc")
raise raise
try:
from urllib.parse import quote
except ImportError:
from urllib import quote
### utilities ### ### utilities ###
def mkPropertyValue(name, value): def mkPropertyValue(name, value):
...@@ -181,6 +186,18 @@ class UnoInProcess: ...@@ -181,6 +186,18 @@ class UnoInProcess:
assert(self.xDoc) assert(self.xDoc)
return self.xDoc return self.xDoc
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])
path = os.getenv("TDOC")
url = "file://" + quote(path) + "/" + quote(file)
self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
assert(self.xDoc)
return self.xDoc
def checkProperties(self, obj, dict, test): def checkProperties(self, obj, dict, test):
for k,v in dict.items(): for k,v in dict.items():
obj.setPropertyValue(k, v) obj.setPropertyValue(k, v)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment