8
8
return output.readlines()
10
def check_patch(lines):
11
assert len(lines) > 1, \
12
"Not enough lines for a file header for patch:\n%s" % "".join(lines)
13
assert lines[0].startswith ('---'), \
14
'No orig line for patch:\n%s' % "".join(lines)
15
assert lines[1].startswith ('+++'), \
16
'No mod line for patch:\n%s' % "".join(lines)
17
assert len(lines) > 2, \
18
"No hunks for patch:\n%s" % "".join(lines)
19
assert lines[2].startswith('@@'),\
20
"No hunk header for patch:\n%s" % "".join(lines)
21
assert '@@' in lines[2][2:], \
22
"Unterminated hunk header for patch:\n%s" % "".join(lines)
24
class AddNL(TestCase):
26
diff generates a valid diff for patches that add a newline
10
class TestDiff(TestCase):
11
def test_add_nl(self):
12
"""diff generates a valid diff for patches that add a newline"""
29
13
lines = udiff_lines(['boo'], ['boo\n'])
31
assert lines[4] == '\\ No newline at end of file\n', \
32
"expected no-nl, got %r" % lines[4]
35
class AddNL2(TestCase):
37
diff generates a valid diff for patches that change last line and add a
14
self.check_patch(lines)
15
self.assertEquals(lines[4], '\\ No newline at end of file\n')
16
## "expected no-nl, got %r" % lines[4]
18
def test_add_nl_2(self):
19
"""diff generates a valid diff for patches that change last line and
41
22
lines = udiff_lines(['boo'], ['goo\n'])
43
assert lines[4] == '\\ No newline at end of file\n', \
44
"expected no-nl, got %r" % lines[4]
23
self.check_patch(lines)
24
self.assertEquals(lines[4], '\\ No newline at end of file\n')
25
## "expected no-nl, got %r" % lines[4]
46
class RemoveNL(TestCase):
48
diff generates a valid diff for patches that change last line and add a
27
def test_remove_nl(self):
28
"""diff generates a valid diff for patches that change last line and
52
31
lines = udiff_lines(['boo\n'], ['boo'])
54
assert lines[5] == '\\ No newline at end of file\n', \
55
"expected no-nl, got %r" % lines[5]
32
self.check_patch(lines)
33
self.assertEquals(lines[5], '\\ No newline at end of file\n')
34
## "expected no-nl, got %r" % lines[5]
36
def check_patch(self, lines):
37
self.assert_(len(lines) > 1)
38
## "Not enough lines for a file header for patch:\n%s" % "".join(lines)
39
self.assert_(lines[0].startswith ('---'))
40
## 'No orig line for patch:\n%s' % "".join(lines)
41
self.assert_(lines[1].startswith ('+++'))
42
## 'No mod line for patch:\n%s' % "".join(lines)
43
self.assert_(len(lines) > 2)
44
## "No hunks for patch:\n%s" % "".join(lines)
45
self.assert_(lines[2].startswith('@@'))
46
## "No hunk header for patch:\n%s" % "".join(lines)
47
self.assert_('@@' in lines[2][2:])
48
## "Unterminated hunk header for patch:\n%s" % "".join(lines)