Skip to content

Commit

Permalink
Return empty dictionary when file has no properties
Browse files Browse the repository at this point in the history
Fix dsoprea#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).
  • Loading branch information
idbrii committed Apr 29, 2021
1 parent b10f276 commit f9540eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions svn/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def properties(self, rel_path=None):
# query the proper list of this path
root = xml.etree.ElementTree.fromstring(result)
target_elem = root.find('target')
if not target_elem:
return {}

property_names = [p.attrib["name"]
for p in target_elem.findall('property')]

Expand Down
17 changes: 17 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ def __init__(self, *args, **kwargs):
self.maxDiff = None
super(TestCommonClient, self).__init__(*args, **kwargs)

def test_properties(self):
with svn.test_support.temp_repo():
with svn.test_support.temp_checkout() as (working_path, lc):
svn.test_support.populate_bigger_file_changes1()

self.assertEqual(0, len(lc.properties('new_file')))
self.assertEqual(0, len(lc.properties('committed_unchanged')))

binary_file = 'binary.dat'
with open(os.path.join(working_path, binary_file), 'wb') as f:
f.write((10).to_bytes(10, 'big'))
lc.add(binary_file) # file must be added to have props detected
binary_props = lc.properties(binary_file)
self.assertEqual(1, len(binary_props))
self.assertIsNotNone(binary_props['svn:mime-type'])
self.assertEqual('application/octet-stream', binary_props['svn:mime-type'])

def test_update(self):
with svn.test_support.temp_repo():
with svn.test_support.temp_checkout() as (_, lc):
Expand Down

0 comments on commit f9540eb

Please sign in to comment.