~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-10 20:03:44 UTC
  • mto: This revision was merged to the branch mainline in revision 5376.
  • Revision ID: john@arbash-meinel.com-20100810200344-6muerwvkafqu7w47
Rework things a bit so the logic can be shared.

It turns out that some of the peak memory is actually during the inventory
to string to bundle translations. So re-use the refcount logic there.
This actually does show a decrease in peak memory.
Specifically 'cd bzr.dev; bzr send ../2.2' drops from 221MB peak to 156MB.

We don't speed anything up (16.5s both ways), but peak memory is quite
a bit better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
24
from StringIO import StringIO
25
25
 
26
26
from bzrlib import (
 
27
    config,
27
28
    errors,
28
29
    remote,
29
30
    repository,
33
34
from bzrlib.symbol_versioning import (
34
35
    deprecated_in,
35
36
    )
36
 
from bzrlib.tests import test_progress
 
37
from bzrlib.tests import (
 
38
    fixtures,
 
39
    test_progress,
 
40
    )
37
41
from bzrlib.ui import text as _mod_ui_text
38
42
 
39
43
 
 
44
class TestUIConfiguration(tests.TestCaseWithTransport):
 
45
 
 
46
    def test_output_encoding_configuration(self):
 
47
        enc = fixtures.generate_unicode_encodings().next()
 
48
        config.GlobalConfig().set_user_option('output_encoding',
 
49
            enc)
 
50
        ui = tests.TestUIFactory(stdin=None,
 
51
            stdout=tests.StringIOWrapper(),
 
52
            stderr=tests.StringIOWrapper())
 
53
        os = ui.make_output_stream()
 
54
        self.assertEquals(os.encoding, enc)
 
55
 
 
56
 
40
57
class TestTextUIFactory(tests.TestCase):
41
58
 
42
59
    def test_text_factory_ascii_password(self):
83
100
        finally:
84
101
            pb.finished()
85
102
 
86
 
    def test_progress_note(self):
87
 
        stderr = tests.StringIOWrapper()
88
 
        stdout = tests.StringIOWrapper()
89
 
        ui_factory = _mod_ui_text.TextUIFactory(stdin=tests.StringIOWrapper(''),
90
 
                                                stderr=stderr,
91
 
                                                stdout=stdout)
92
 
        pb = ui_factory.nested_progress_bar()
93
 
        try:
94
 
            result = self.applyDeprecated(deprecated_in((2, 1, 0)),
95
 
                pb.note,
96
 
                't')
97
 
            self.assertEqual(None, result)
98
 
            self.assertEqual("t\n", stdout.getvalue())
99
 
            # Since there was no update() call, there should be no clear() call
100
 
            self.failIf(re.search(r'^\r {10,}\r$',
101
 
                                  stderr.getvalue()) is not None,
102
 
                        'We cleared the stderr without anything to put there')
103
 
        finally:
104
 
            pb.finished()
105
 
 
106
 
    def test_progress_note_clears(self):
107
 
        stderr = test_progress._TTYStringIO()
108
 
        stdout = test_progress._TTYStringIO()
109
 
        # so that we get a TextProgressBar
110
 
        os.environ['TERM'] = 'xterm'
111
 
        ui_factory = _mod_ui_text.TextUIFactory(
112
 
            stdin=tests.StringIOWrapper(''),
113
 
            stdout=stdout, stderr=stderr)
114
 
        self.assertIsInstance(ui_factory._progress_view,
115
 
                              _mod_ui_text.TextProgressView)
116
 
        pb = ui_factory.nested_progress_bar()
117
 
        try:
118
 
            # Create a progress update that isn't throttled
119
 
            pb.update('x', 1, 1)
120
 
            result = self.applyDeprecated(deprecated_in((2, 1, 0)),
121
 
                pb.note, 't')
122
 
            self.assertEqual(None, result)
123
 
            self.assertEqual("t\n", stdout.getvalue())
124
 
            # the exact contents will depend on the terminal width and we don't
125
 
            # care about that right now - but you're probably running it on at
126
 
            # least a 10-character wide terminal :)
127
 
            self.assertContainsRe(stderr.getvalue(), r'\r {10,}\r$')
128
 
        finally:
129
 
            pb.finished()
130
 
 
131
103
    def test_text_ui_get_boolean(self):
132
104
        stdin = tests.StringIOWrapper("y\n" # True
133
105
                                      "n\n" # False
176
148
        factory = _mod_ui_text.TextUIFactory(
177
149
            stdin=tests.StringIOWrapper("yada\ny\n"),
178
150
            stdout=out, stderr=out)
 
151
        factory._avail_width = lambda: 79
179
152
        pb = factory.nested_progress_bar()
180
153
        pb.show_bar = False
181
154
        pb.show_spinner = False
187
160
                                               factory.get_boolean,
188
161
                                               "what do you want"))
189
162
        output = out.getvalue()
190
 
        self.assertContainsRe(factory.stdout.getvalue(),
191
 
            "foo *\r\r  *\r*")
192
 
        self.assertContainsRe(factory.stdout.getvalue(),
 
163
        self.assertContainsRe(output,
 
164
            "| foo *\r\r  *\r*")
 
165
        self.assertContainsRe(output,
193
166
            r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ")
194
167
        # stdin should have been totally consumed
195
168
        self.assertEqual('', factory.stdin.readline())
385
358
 
386
359
    def test_test_ui_factory_progress(self):
387
360
        # there's no output; we just want to make sure this doesn't crash -
388
 
        # see https://bugs.edge.launchpad.net/bzr/+bug/408201
 
361
        # see https://bugs.launchpad.net/bzr/+bug/408201
389
362
        ui = tests.TestUIFactory()
390
363
        pb = ui.nested_progress_bar()
391
364
        pb.update('hello')