Skip to content

Commit 6de4be1

Browse files
committed
Move rels folder to constant
I'm probably not going to move all strings to constants. But we can make a start, right.
1 parent 1dc8d4c commit 6de4be1

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

io_mesh_3mf/annotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def add_rels(self, rels_file):
8080
f"Relationship file {rels_file.name} has malformed XML (position {e.position[0]}:{e.position[1]}).")
8181
return # Skip this file.
8282

83-
for relationship_node in root.iterfind("rel:Relationship", RELS_NAMESPACES):
83+
for relationship_node in root.iterfind(RELS_RELATIONSHIP_FIND, RELS_NAMESPACES):
8484
try:
8585
target = relationship_node.attrib["Target"]
8686
namespace = relationship_node.attrib["Type"]

io_mesh_3mf/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@
5353
RELS_NAMESPACES = { # Namespaces used for the rels files.
5454
"rel": RELS_NAMESPACE
5555
}
56+
RELS_RELATIONSHIP_FIND = "rel:Relationship"

test/annotations.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def test_write_rels_empty(self):
296296

297297
file.seek(0)
298298
root = xml.etree.ElementTree.ElementTree(file=file).getroot()
299-
relationships = root.findall("rel:Relationship", namespaces=RELS_NAMESPACES)
299+
relationships = root.findall(RELS_RELATIONSHIP_FIND, namespaces=RELS_NAMESPACES)
300300
self.assertEqual(
301301
len(relationships),
302302
1,
@@ -328,7 +328,7 @@ def test_write_rels_different_annotations(self):
328328

329329
file.seek(0)
330330
root = xml.etree.ElementTree.ElementTree(file=file).getroot()
331-
relationships = root.findall("rel:Relationship", namespaces=RELS_NAMESPACES)
331+
relationships = root.findall(RELS_RELATIONSHIP_FIND, namespaces=RELS_NAMESPACES)
332332
self.assertEqual(
333333
len(relationships),
334334
1,
@@ -349,7 +349,7 @@ def test_write_rels_relationship(self):
349349

350350
file.seek(0)
351351
root = xml.etree.ElementTree.ElementTree(file=file).getroot()
352-
relationships = root.findall("rel:Relationship", namespaces=RELS_NAMESPACES)
352+
relationships = root.findall(RELS_RELATIONSHIP_FIND, namespaces=RELS_NAMESPACES)
353353
self.assertEqual(
354354
len(relationships),
355355
2,
@@ -373,14 +373,15 @@ def test_write_rels_different_source(self):
373373
custom_file = io.BytesIO()
374374
custom_file.close = lambda: None
375375
# Return the correct file handle depending on which file is opened.
376-
archive.open = lambda fname, *args, **kwargs: custom_file if fname == "3D/" + RELS_FOLDER + "/.rels" else root_file
376+
archive.open = lambda fname, *args, **kwargs:\
377+
custom_file if fname == "3D/" + RELS_FOLDER + "/.rels" else root_file
377378

378379
self.annotations.annotations["file.txt"] = {io_mesh_3mf.annotations.Relationship(namespace="nsp", source="3D/")}
379380
self.annotations.write_rels(archive)
380381

381382
custom_file.seek(0)
382383
root = xml.etree.ElementTree.ElementTree(file=custom_file).getroot()
383-
relationships = root.findall("rel:Relationship", namespaces=RELS_NAMESPACES)
384+
relationships = root.findall(RELS_RELATIONSHIP_FIND, namespaces=RELS_NAMESPACES)
384385
self.assertEqual(len(relationships), 1, "Only the custom relationship got saved to this file.")
385386
self.assertEqual(relationships[0].attrib["Target"], "/file.txt", "The target of the relationship is absolute.")
386387
self.assertEqual(relationships[0].attrib["Type"], "nsp", "This is the namespace we added.")

0 commit comments

Comments
 (0)