Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
super(TestHunk, self).setUp()
self.context_line = Line('Sample line', line_type=LINE_TYPE_CONTEXT)
self.added_line = Line('Sample line', line_type=LINE_TYPE_ADDED)
self.removed_line = Line('Sample line', line_type=LINE_TYPE_REMOVED)
def setUp(self):
super(TestHunk, self).setUp()
self.context_line = Line('Sample line', line_type=LINE_TYPE_CONTEXT)
self.added_line = Line('Sample line', line_type=LINE_TYPE_ADDED)
self.removed_line = Line('Sample line', line_type=LINE_TYPE_REMOVED)
def setUp(self):
super(TestHunk, self).setUp()
self.context_line = Line('Sample line', line_type=LINE_TYPE_CONTEXT)
self.added_line = Line('Sample line', line_type=LINE_TYPE_ADDED)
self.removed_line = Line('Sample line', line_type=LINE_TYPE_REMOVED)
def __init__(self, value, line_type,
source_line_no=None, target_line_no=None, diff_line_no=None):
super(Line, self).__init__()
self.source_line_no = source_line_no
self.target_line_no = target_line_no
self.diff_line_no = diff_line_no
self.line_type = line_type
self.value = value
def _parse_hunk(diff, source_start, source_len, target_start, target_len,
section_header):
"""Parse a diff hunk details."""
hunk = Hunk(source_start, source_len, target_start, target_len,
section_header)
source_line_no = hunk.source_start
target_line_no = hunk.target_start
for line in diff:
valid_line = RE_HUNK_BODY_LINE.match(line)
if not valid_line:
raise UnidiffParseError('Hunk diff line expected: %s' % line)
line_type = valid_line.group('line_type')
value = valid_line.group('value')
original_line = Line(value, line_type=line_type)
if line_type == LINE_TYPE_ADDED:
original_line.target_line_no = target_line_no
target_line_no += 1
elif line_type == LINE_TYPE_REMOVED:
original_line.source_line_no = source_line_no
source_line_no += 1
elif line_type == LINE_TYPE_CONTEXT:
original_line.target_line_no = target_line_no
target_line_no += 1
original_line.source_line_no = source_line_no
source_line_no += 1
else:
original_line = None
if original_line:
hunk.append(original_line)
for diff_line_no, line in diff:
if encoding is not None:
line = line.decode(encoding)
valid_line = RE_HUNK_BODY_LINE.match(line)
if not valid_line:
valid_line = RE_HUNK_EMPTY_BODY_LINE.match(line)
if not valid_line:
raise UnidiffParseError('Hunk diff line expected: %s' % line)
line_type = valid_line.group('line_type')
if line_type == LINE_TYPE_EMPTY:
line_type = LINE_TYPE_CONTEXT
value = valid_line.group('value')
original_line = Line(value, line_type=line_type)
if line_type == LINE_TYPE_ADDED:
original_line.target_line_no = target_line_no
target_line_no += 1
elif line_type == LINE_TYPE_REMOVED:
original_line.source_line_no = source_line_no
source_line_no += 1
elif line_type == LINE_TYPE_CONTEXT:
original_line.target_line_no = target_line_no
target_line_no += 1
original_line.source_line_no = source_line_no
source_line_no += 1
elif line_type == LINE_TYPE_NO_NEWLINE:
pass
else:
original_line = None