Skip to content

Commit

Permalink
common.py: Integrate centralized and reusable testing functionality
Browse files Browse the repository at this point in the history
- Bugfix for incorrectly managing file-adds in diff. Updated test.
  • Loading branch information
dsoprea committed Feb 29, 2020
1 parent 057ecb3 commit b8d1fca
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 368 deletions.
10 changes: 10 additions & 0 deletions svn/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ def diff(self, old, new, rel_path=None):
hunks = {}

def _process_hunk(file_hunk_raw):
# hunks_info will be `None` for file-adds.
filepath, hunks_info = self._split_file_hunk(file_hunk_raw)

hunks[filepath] = hunks_info

while True:
Expand Down Expand Up @@ -484,6 +486,14 @@ def _split_file_hunk(self, file_hunk):
# ===================================================================
filepath = lines[0][len(_FILE_HUNK_PREFIX):]

# File was added. We have the file-hunk header but no actual hunks.
if len(lines) == 3:
assert \
lines[2] == '', \
"Empty diff expects third line to be empty:\n{}".format(lines)

return filepath, None

assert \
lines[2].startswith(_HUNK_HEADER_LEFT_PREFIX), \
"Could not find 'left' header prefix: [{}]".format(lines[2])
Expand Down
12 changes: 11 additions & 1 deletion svn/utility.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import os

import svn.common
import svn.local
import svn.remote

import svn.constants

def get_client(url_or_path, *args, **kwargs):
if url_or_path[0] == '/':
return svn.local.LocalClient(url_or_path, *args, **kwargs)
else:
return svn.remote.RemoteClient(url_or_path, *args, **kwargs)

def get_common_for_cwd():
path = os.getcwd()
uri = 'file://{}'.format(path)

cc = svn.common.CommonClient(uri, svn.constants.LT_URL)
return cc

0 comments on commit b8d1fca

Please sign in to comment.