/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Martin Pool
  • Date: 2009-03-04 06:56:23 UTC
  • mfrom: (4075 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4081.
  • Revision ID: mbp@sourcefrog.net-20090304065623-l2vub3zxscvhs17a
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1820
1820
        return sio
1821
1821
 
1822
1822
 
 
1823
class CapturedCall(object):
 
1824
    """A helper for capturing smart server calls for easy debug analysis."""
 
1825
 
 
1826
    def __init__(self, params, prefix_length):
 
1827
        """Capture the call with params and skip prefix_length stack frames."""
 
1828
        self.call = params
 
1829
        import traceback
 
1830
        # The last 5 frames are the __init__, the hook frame, and 3 smart
 
1831
        # client frames. Beyond this we could get more clever, but this is good
 
1832
        # enough for now.
 
1833
        stack = traceback.extract_stack()[prefix_length:-5]
 
1834
        self.stack = ''.join(traceback.format_list(stack))
 
1835
 
 
1836
    def __str__(self):
 
1837
        return self.call.method
 
1838
 
 
1839
    def __repr__(self):
 
1840
        return self.call.method
 
1841
 
 
1842
    def stack(self):
 
1843
        return self.stack
 
1844
 
 
1845
 
1823
1846
class TestCaseWithMemoryTransport(TestCase):
1824
1847
    """Common test class for tests that do not need disk resources.
1825
1848
 
2115
2138
        """Sets up a smart server as the transport server with a call log."""
2116
2139
        self.transport_server = server.SmartTCPServer_for_testing
2117
2140
        self.hpss_calls = []
 
2141
        import traceback
 
2142
        # Skip the current stack down to the caller of
 
2143
        # setup_smart_server_with_call_log
 
2144
        prefix_length = len(traceback.extract_stack()) - 2
2118
2145
        def capture_hpss_call(params):
2119
 
            import traceback
2120
 
            self.hpss_calls.append((params, traceback.format_stack()))
 
2146
            self.hpss_calls.append(
 
2147
                CapturedCall(params, prefix_length))
2121
2148
        client._SmartClient.hooks.install_named_hook(
2122
2149
            'call', capture_hpss_call, None)
2123
2150