~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/log.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-05 15:31:34 UTC
  • mto: (4343.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4344.
  • Revision ID: v.ladeuil+lp@free.fr-20090505153134-q4bp4is9gywsmzrv
Clean up test for log formats.

* bzrlib/tests/blackbox/test_logformats.py:
Update tests to actual style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    and may be slow.
45
45
 
46
46
    Not all operations are logged yet.
47
 
 
48
 
    See also TransportTraceDecorator, that records a machine-readable log in 
49
 
    memory for eg testing.
50
47
    """
51
48
 
52
49
    def __init__(self, *args, **kw):
107
104
    def _show_result(self, before, methodname, result):
108
105
        result_len = None
109
106
        if isinstance(result, types.GeneratorType):
110
 
            # We now consume everything from the generator so that we can show
111
 
            # the results and the time it took to get them.  However, to keep
112
 
            # compatibility with callers that may specifically expect a result
113
 
            # (see <https://launchpad.net/bugs/340347>) we also return a new
114
 
            # generator, reset to the starting position.
 
107
            # eagerly pull in all the contents, so that we can measure how
 
108
            # long it takes to get them.  this does make the behaviour a bit
 
109
            # different, but we hope not noticably so
115
110
            result = list(result)
116
 
            return_result = iter(result)
117
 
        else:
118
 
            return_result = result
119
111
        if isinstance(result, (cStringIO.OutputType, StringIO.StringIO)):
120
112
            val = repr(result.getvalue())
121
113
            result_len = len(val)
130
122
        else:
131
123
            shown_result = self._shorten(self._strip_tuple_parens(result))
132
124
        mutter("  --> %s" % shown_result)
133
 
        # The log decorator no longer shows the elapsed time or transfer rate
134
 
        # because they're available in the log prefixes and the transport
135
 
        # activity display respectively.
136
 
        if False:
137
 
            elapsed = time.time() - before
138
 
            if result_len and elapsed > 0:
139
 
                # this is the rate of higher-level data, not the raw network speed
140
 
                mutter("      %9.03fs %8dKB/s" % (elapsed, result_len/elapsed/1024))
141
 
            else:
142
 
                mutter("      %9.03fs" % (elapsed))
143
 
        return return_result
 
125
        # XXX: the time may be wrong when e.g. a generator object is returned from
 
126
        # an http readv, if the object is returned before the bulk data
 
127
        # is read.
 
128
        elapsed = time.time() - before
 
129
        if result_len and elapsed > 0:
 
130
            # this is the rate of higher-level data, not the raw network speed
 
131
            mutter("      %9.03fs %8dKB/s" % (elapsed, result_len/elapsed/1024))
 
132
        else:
 
133
            mutter("      %9.03fs" % (elapsed))
 
134
        return result
144
135
 
145
136
    def _shorten(self, x):
146
137
        if len(x) > 70: