Skip to content

Commit 9f01114

Browse files
committed
Return empty dictionary when file has no properties
Fix #89: properties method failed when no props defined When a file has no properties, the xml doesn't contain 'target' and target_elem is None. To conform to the documentation for properties, return an empty dict (instead of None). Test for both no properties and mime type property (writing a binary file in the simplest way I can find that works in py2 and py3).
1 parent c0878be commit 9f01114

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

svn/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def properties(self, rel_path=None):
154154
# query the proper list of this path
155155
root = xml.etree.ElementTree.fromstring(result)
156156
target_elem = root.find('target')
157+
if not target_elem:
158+
return {}
159+
157160
property_names = [p.attrib["name"]
158161
for p in target_elem.findall('property')]
159162

tests/test_common.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ def __init__(self, *args, **kwargs):
1414
self.maxDiff = None
1515
super(TestCommonClient, self).__init__(*args, **kwargs)
1616

17+
def test_properties(self):
18+
with svn.test_support.temp_repo():
19+
with svn.test_support.temp_checkout() as (working_path, lc):
20+
svn.test_support.populate_bigger_file_changes1()
21+
22+
self.assertEqual(0, len(lc.properties('new_file')))
23+
self.assertEqual(0, len(lc.properties('committed_unchanged')))
24+
25+
binary_file = 'binary.dat'
26+
with open(os.path.join(working_path, binary_file), 'wb') as f:
27+
f.write(bytearray(range(10)))
28+
lc.add(binary_file) # file must be added to have props detected
29+
binary_props = lc.properties(binary_file)
30+
self.assertEqual(1, len(binary_props))
31+
self.assertIsNotNone(binary_props['svn:mime-type'])
32+
self.assertEqual('application/octet-stream', binary_props['svn:mime-type'])
33+
1734
def test_update(self):
1835
with svn.test_support.temp_repo():
1936
with svn.test_support.temp_checkout() as (_, lc):

0 commit comments

Comments
 (0)