Merge branch 'dev' into text_align

This commit is contained in:
Veronica Berglyd Olsen
2021-06-11 00:11:40 +02:00
2 changed files with 22 additions and 19 deletions
+4 -3
View File
@@ -106,7 +106,6 @@ class NWItem():
if "order" in xItem.attrib: if "order" in xItem.attrib:
self.setOrder(xItem.attrib["order"]) self.setOrder(xItem.attrib["order"])
retStatus = True
for xValue in xItem: for xValue in xItem:
if xValue.tag == "name": if xValue.tag == "name":
self.setName(xValue.text) self.setName(xValue.text)
@@ -131,10 +130,12 @@ class NWItem():
elif xValue.tag == "cursorPos": elif xValue.tag == "cursorPos":
self.setCursorPos(xValue.text) self.setCursorPos(xValue.text)
else: else:
# Sliently skip as we may otherwise cause orphaned
# items if an otherwise valid file is opened by a
# version of novelWriter that doesn't know the tag.
logger.error("Unknown tag '%s'" % xValue.tag) logger.error("Unknown tag '%s'" % xValue.tag)
retStatus = False
return retStatus return True
@staticmethod @staticmethod
def _subPack(xParent, name, attrib=None, text=None, none=True): def _subPack(xParent, name, attrib=None, text=None, none=True):
+18 -16
View File
@@ -270,7 +270,7 @@ def testCoreItem_LayoutSetter(dummyGUI):
# END Test testCoreItem_LayoutSetter # END Test testCoreItem_LayoutSetter
@pytest.mark.core @pytest.mark.core
def testCoreItem_XMLPackUnpack(dummyGUI): def testCoreItem_XMLPackUnpack(dummyGUI, caplog):
"""Test packing and unpacking XML objects for the NWItem class. """Test packing and unpacking XML objects for the NWItem class.
""" """
theProject = NWProject(dummyGUI) theProject = NWProject(dummyGUI)
@@ -370,31 +370,33 @@ def testCoreItem_XMLPackUnpack(dummyGUI):
# Errors # Errors
## Not an Item ## Not an Item
xDummy = etree.SubElement(nwXML, "stuff") mockXml = etree.SubElement(nwXML, "stuff")
assert not theItem.unpackXML(xDummy) assert theItem.unpackXML(mockXml) is False
## Item without Handle ## Item without Handle
xDummy = etree.SubElement(nwXML, "item", attrib={"stuff": "nah"}) mockXml = etree.SubElement(nwXML, "item", attrib={"stuff": "nah"})
assert not theItem.unpackXML(xDummy) assert theItem.unpackXML(mockXml) is False
## Item with Invalid SubElement ## Item with Invalid SubElement is Accepted w/Error
xDummy = etree.SubElement(nwXML, "item", attrib={"handle": "0123456789abc"}) mockXml = etree.SubElement(nwXML, "item", attrib={"handle": "0123456789abc"})
xParam = etree.SubElement(xDummy, "invalid") xParam = etree.SubElement(mockXml, "invalid")
xParam.text = "stuff" xParam.text = "stuff"
assert not theItem.unpackXML(xDummy) caplog.clear()
assert theItem.unpackXML(mockXml) is True
assert "Unknown tag 'invalid'" in caplog.text
# Pack Valid Item # Pack Valid Item
xDummy = etree.SubElement(nwXML, "group") mockXml = etree.SubElement(nwXML, "group")
theItem._subPack(xDummy, "subGroup", {"one": "two"}, "value", False) theItem._subPack(mockXml, "subGroup", {"one": "two"}, "value", False)
assert etree.tostring(xDummy, pretty_print=False, encoding="utf-8") == ( assert etree.tostring(mockXml, pretty_print=False, encoding="utf-8") == (
b"<group><subGroup one=\"two\">value</subGroup></group>" b"<group><subGroup one=\"two\">value</subGroup></group>"
) )
# Pack Not Allowed None # Pack Not Allowed None
xDummy = etree.SubElement(nwXML, "group") mockXml = etree.SubElement(nwXML, "group")
assert theItem._subPack(xDummy, "subGroup", {}, None, False) is None assert theItem._subPack(mockXml, "subGroup", {}, None, False) is None
assert theItem._subPack(xDummy, "subGroup", {}, "None", False) is None assert theItem._subPack(mockXml, "subGroup", {}, "None", False) is None
assert etree.tostring(xDummy, pretty_print=False, encoding="utf-8") == ( assert etree.tostring(mockXml, pretty_print=False, encoding="utf-8") == (
b"<group/>" b"<group/>"
) )