~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testlog.py

- ignore .swp files from upload

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
 
18
from cStringIO import StringIO
18
19
 
19
 
from bzrlib.selftest import BzrTestBase
 
20
from bzrlib.selftest import BzrTestBase, TestCaseInTempDir
20
21
from bzrlib.log import LogFormatter, show_log, LongLogFormatter
21
22
from bzrlib.branch import Branch
 
23
from bzrlib.errors import InvalidRevisionNumber
22
24
 
23
25
class _LogEntry(object):
24
26
    # should probably move into bzrlib.log?
47
49
        self.logs.append(le)
48
50
 
49
51
 
50
 
class SimpleLogTest(BzrTestBase):
 
52
class SimpleLogTest(TestCaseInTempDir):
 
53
 
51
54
    def checkDelta(self, delta, **kw):
52
55
        """Check the filenames touched by a delta are as expected."""
53
56
        for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
61
64
            got = [x[0] for x in getattr(delta, n)]
62
65
            self.assertEquals(expected, got)
63
66
 
64
 
    
65
 
    def runTest(self):
 
67
    def test_cur_revno(self):
 
68
        b = Branch('.', init=True)
 
69
 
 
70
        lf = LogCatcher()
 
71
        b.commit('empty commit')
 
72
        show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
 
73
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
74
                          start_revision=2, end_revision=1) 
 
75
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
76
                          start_revision=1, end_revision=2) 
 
77
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
78
                          start_revision=0, end_revision=2) 
 
79
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
80
                          start_revision=1, end_revision=0) 
 
81
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
82
                          start_revision=-1, end_revision=1) 
 
83
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
84
                          start_revision=1, end_revision=-1) 
 
85
 
 
86
    def test_cur_revno(self):
 
87
        b = Branch.initialize('.')
 
88
 
 
89
        lf = LogCatcher()
 
90
        b.commit('empty commit')
 
91
        show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
 
92
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
93
                          start_revision=2, end_revision=1) 
 
94
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
95
                          start_revision=1, end_revision=2) 
 
96
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
97
                          start_revision=0, end_revision=2) 
 
98
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
99
                          start_revision=1, end_revision=0) 
 
100
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
101
                          start_revision=-1, end_revision=1) 
 
102
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
 
103
                          start_revision=1, end_revision=-1) 
 
104
 
 
105
    def test_simple_log(self):
66
106
        eq = self.assertEquals
67
 
        ass = self.assert_
68
107
        
69
 
        b = Branch('.', init=True)
 
108
        b = Branch.initialize('.')
70
109
 
71
110
        lf = LogCatcher()
72
111
        show_log(b, lf)
88
127
        self.build_tree(['hello'])
89
128
        b.add('hello')
90
129
        b.commit('add one file')
 
130
 
 
131
        lf = StringIO()
91
132
        # log using regular thing
92
 
        show_log(b, LongLogFormatter(self.TEST_LOG))
 
133
        show_log(b, LongLogFormatter(lf))
 
134
        lf.seek(0)
 
135
        for l in lf.readlines():
 
136
            self.log(l)
93
137
 
94
138
        # get log as data structure
95
139
        lf = LogCatcher()
107
151
        self.log('log 2 delta: %r' % d)
108
152
        # self.checkDelta(d, added=['hello'])
109
153
        
 
154
        # commit a log message with control characters
 
155
        msg = "All 8-bit chars: " +  ''.join([unichr(x) for x in range(256)])
 
156
        b.commit(msg)
 
157
        lf = LogCatcher()
 
158
        show_log(b, lf, verbose=True)
 
159
        committed_msg = lf.logs[0].rev.message
 
160
        self.log("escaped commit message: %r", committed_msg)
 
161
        self.assert_(msg != committed_msg)
 
162
        self.assert_(len(committed_msg) > len(msg))