~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testdiff.py

  • Committer: Martin Pool
  • Date: 2005-08-24 02:34:24 UTC
  • Revision ID: mbp@sourcefrog.net-20050824023424-67667e2b57c3d7d0
- merge test refactoring from robertc

  More of the common test infrastructure to do with 
  making temporary directories, etc, is now done from a 
  TestCase subclass, and generally have less magic
  compared to unittest. 

robertc@robertcollins.net-20050823111339-fb55b8ce170b20e0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from bzrlib.selftest import TestBase
 
1
from bzrlib.selftest import TestCase
2
2
from bzrlib.diff import internal_diff
3
3
from cStringIO import StringIO
4
4
def udiff_lines(old, new):
21
21
    assert '@@' in lines[2][2:], \
22
22
        "Unterminated hunk header for patch:\n%s" % "".join(lines)
23
23
 
24
 
class AddNL(TestBase):
25
 
    """
26
 
    diff generates a valid diff for patches that add a newline
27
 
    """
28
 
    def runTest(self):
 
24
class TestDiff(TestCase):
 
25
    def test_add_nl(self):
 
26
        """diff generates a valid diff for patches that add a newline"""
29
27
        lines = udiff_lines(['boo'], ['boo\n'])
30
28
        check_patch(lines)
31
29
        assert lines[4] == '\\ No newline at end of file\n', \
32
30
            "expected no-nl, got %r" % lines[4]
33
31
 
34
 
 
35
 
class AddNL2(TestBase):
36
 
    """
37
 
    diff generates a valid diff for patches that change last line and add a
38
 
    newline
39
 
    """
40
 
    def runTest(self):
 
32
    def test_add_nl_2(self):
 
33
        """diff generates a valid diff for patches that change last line and
 
34
        add a newline.
 
35
        """
41
36
        lines = udiff_lines(['boo'], ['goo\n'])
42
37
        check_patch(lines)
43
38
        assert lines[4] == '\\ No newline at end of file\n', \
44
39
            "expected no-nl, got %r" % lines[4]
45
40
 
46
 
class RemoveNL(TestBase):
47
 
    """
48
 
    diff generates a valid diff for patches that change last line and add a
49
 
    newline
50
 
    """
51
 
    def runTest(self):
 
41
    def test_remove_nl(self):
 
42
        """diff generates a valid diff for patches that change last line and
 
43
        add a newline.
 
44
        """
52
45
        lines = udiff_lines(['boo\n'], ['boo'])
53
46
        check_patch(lines)
54
47
        assert lines[5] == '\\ No newline at end of file\n', \
55
48
            "expected no-nl, got %r" % lines[5]
56
49
 
57
 
TEST_CLASSES = [
58
 
    AddNL, 
59
 
    AddNL2, 
60
 
    RemoveNL,
61
 
]
 
50
TEST_CLASSES = [ TestDiff ]