Kaydet (Commit) 6bfef5f9 authored tarafından Hamish McIntyre-Bhatty's avatar Hamish McIntyre-Bhatty Kaydeden (comit) Samuel Mehrbrodt

tdf#97361 Make var_fields more pythonic.

Use whitespace to improve readability, including
indenting arguments in a more readable way

Change-Id: I7cf687042fb1d4d62e8acb8277539101dc859859
Reviewed-on: https://gerrit.libreoffice.org/61626
Tested-by: Jenkins
Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst eb51a44c
...@@ -7,12 +7,13 @@ ...@@ -7,12 +7,13 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
# #
import unittest import unittest
import os import os
from org.libreoffice.unotest import UnoInProcess from org.libreoffice.unotest import UnoInProcess
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
class TestVarFields(unittest.TestCase): class TestVarFields(unittest.TestCase):
@classmethod @classmethod
...@@ -25,17 +26,21 @@ class TestVarFields(unittest.TestCase): ...@@ -25,17 +26,21 @@ class TestVarFields(unittest.TestCase):
cls._uno.tearDown() cls._uno.tearDown()
def test_var_fields(self): def test_var_fields(self):
"""Reproduce fdo#55814. """
Reproduce fdo#55814.
Note: this test was migrated from java (the steps numbering too) Note: this test was migrated from java (the steps numbering too)
sw/qa/complex/writer/VarFields.java sw/qa/complex/writer/VarFields.java
""" """
xDoc = self.__class__._uno.openEmptyWriterDoc() xDoc = self.__class__._uno.openEmptyWriterDoc()
xBodyText = xDoc.getText() xBodyText = xDoc.getText()
xCursor = xBodyText.createTextCursor() xCursor = xBodyText.createTextCursor()
# 0. create text field # 0. create text field
xField = xDoc.createInstance("com.sun.star.text.textfield.SetExpression") xField = xDoc.createInstance("com.sun.star.text.textfield.SetExpression")
# 1. fill it with properties # 1. fill it with properties
self.__class__._uno.setProperties(xField, self.__class__._uno.setProperties(xField,
{"Content": "0", {"Content": "0",
...@@ -43,72 +48,89 @@ class TestVarFields(unittest.TestCase): ...@@ -43,72 +48,89 @@ class TestVarFields(unittest.TestCase):
"Hint": "trying to reproduce fdo#55814", "Hint": "trying to reproduce fdo#55814",
"SubType": 0, # VAR "SubType": 0, # VAR
"Value": 0.0}) "Value": 0.0})
# 2. create master field # 2. create master field
xMaster = xDoc.createInstance("com.sun.star.text.fieldmaster.SetExpression") xMaster = xDoc.createInstance("com.sun.star.text.fieldmaster.SetExpression")
# 3. set name of the master field to "foo" # 3. set name of the master field to "foo"
xMaster.setPropertyValue("Name", "foo") xMaster.setPropertyValue("Name", "foo")
# 4. get Dependent Field # 4. get Dependent Field
# no op in python ;-) # no op in python ;-)
# 5. connect real field to the master # 5. connect real field to the master
xField.attachTextFieldMaster(xMaster) xField.attachTextFieldMaster(xMaster)
# 6. insert text field into the document # 6. insert text field into the document
xBodyText.insertTextContent(xCursor, xField, False) xBodyText.insertTextContent(xCursor, xField, False)
# 7. retrieve paragraph cursor # 7. retrieve paragraph cursor
xParagraphCursor = xCursor xParagraphCursor = xCursor
xParagraphCursor.gotoEndOfParagraph(False) # not selectd xParagraphCursor.gotoEndOfParagraph(False) # not selected
# 8. enter new line # 8. enter new line
xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False) xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False)
# 9. create new text section # 9. create new text section
xTextSection = xDoc.createInstance("com.sun.star.text.TextSection") xTextSection = xDoc.createInstance("com.sun.star.text.TextSection")
# 10. fill the properties of section # 10. fill the properties of section
self.__class__._uno.checkProperties( self.__class__._uno.checkProperties(xTextSection,
xTextSection, {"Condition": "foo EQ 1",
{"Condition": "foo EQ 1", "IsVisible": False},
"IsVisible": False, self)
},
self
)
# 11. Insert some text to be content on the section # 11. Insert some text to be content on the section
xBodyText.insertString(xCursor, xBodyText.insertString(xCursor,
"The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the lazy dog",
True) True)
# 12. insert section # 12. insert section
xBodyText.insertTextContent(xCursor, xTextSection, True) xBodyText.insertTextContent(xCursor, xTextSection, True)
# 12.1 insert new paragraph. Note: that's here the difference # 12.1 insert new paragraph. Note: that's here the difference
xParagraphCursor.gotoEndOfParagraph(False) # not select xParagraphCursor.gotoEndOfParagraph(False) # not select
# TODO: how to leave the section now? # TODO: how to leave the section now?
xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False) xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False)
xBodyText.insertString(xCursor, "new paragraph", False) xBodyText.insertString(xCursor, "new paragraph", False)
# 13. Access fields to refresh the document # 13. Access fields to refresh the document
xTextFields = xDoc.getTextFields() xTextFields = xDoc.getTextFields()
# 14. refresh document to update the fields # 14. refresh document to update the fields
xTextFields.refresh() xTextFields.refresh()
# 15. retrieve the field # 15. retrieve the field
xFieldEnum = xTextFields.createEnumeration() xFieldEnum = xTextFields.createEnumeration()
# Note: we have only one field here, that why nextElement() is just fine here # Note: we have only one field here, that why nextElement() is just fine here
xField = xFieldEnum.nextElement() xField = xFieldEnum.nextElement()
# check # check
read_content = xField.getPropertyValue("Content") read_content = xField.getPropertyValue("Content")
self.assertEqual("0", read_content) self.assertEqual("0", read_content)
read_content = xField.getPropertyValue("Value") read_content = xField.getPropertyValue("Value")
self.assertEqual(0.0, read_content) self.assertEqual(0.0, read_content)
# 16. change the value of the field from 0 to 1 and check # 16. change the value of the field from 0 to 1 and check
self.__class__._uno.checkProperties( self.__class__._uno.checkProperties(xField, {"Value": 1.0,
xField, "Content": "1"},
{"Value": 1.0, self)
"Content": "1"
},
self
)
# 17. refresh document to update the fields again # 17. refresh document to update the fields again
xTextFields.refresh() xTextFields.refresh()
# 18. store document # 18. store document
url = os.path.join(os.environ["TestUserDir"], "VarFields.odt") url = os.path.join(os.environ["TestUserDir"], "VarFields.odt")
xDoc.storeToURL(url, tuple(list(range(0)))) xDoc.storeToURL(url, tuple(list(range(0))))
# 19. retrieve the section # 19. retrieve the section
xSection = xDoc.getTextSections().getByIndex(0) xSection = xDoc.getTextSections().getByIndex(0)
# 20. retrieve the condition property of that section # 20. retrieve the condition property of that section
read_content = xSection.getPropertyValue("Condition") read_content = xSection.getPropertyValue("Condition")
# 21. check # 21. check
# expected: # expected:
# self.assertEqual("foo EQ 1", readContent) # self.assertEqual("foo EQ 1", readContent)
......
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