/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/per_uifactory/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
# Plugins that add new UIFactorys can create their own subclasses.
34
34
 
35
35
 
36
 
from cStringIO import StringIO
37
36
import unittest
38
37
 
39
 
 
40
 
from bzrlib import (
 
38
from ... import (
41
39
    tests,
42
40
    transport,
43
41
    ui,
44
42
    )
45
43
 
 
44
from ..ui_testing import (
 
45
    StringIOWithEncoding,
 
46
    StringIOAsTTY,
 
47
    )
 
48
 
46
49
 
47
50
class UIFactoryTestMixin(object):
48
51
    """Common tests for UIFactories.
121
124
 
122
125
    def setUp(self):
123
126
        super(TestTextUIFactory, self).setUp()
124
 
        self.stdin = StringIO()
125
 
        self.stdout = StringIO()
126
 
        self.stderr = StringIO()
 
127
        self.stdin = StringIOWithEncoding()
 
128
        self.stdout = StringIOWithEncoding()
 
129
        self.stderr = StringIOWithEncoding()
127
130
        self.factory = ui.text.TextUIFactory(self.stdin, self.stdout,
128
131
            self.stderr)
129
132
 
172
175
    def setUp(self):
173
176
        super(TestTTYTextUIFactory, self).setUp()
174
177
 
175
 
        class TTYStringIO(object):
176
 
            """Thunk over to StringIO() for everything but 'isatty'"""
177
 
 
178
 
            def __init__(self):
179
 
                self.__dict__['_sio'] = StringIO()
180
 
 
181
 
            def isatty(self):
182
 
                return True
183
 
 
184
 
            def __getattr__(self, name):
185
 
                return getattr(self._sio, name)
186
 
 
187
 
            def __setattr__(self, name, value):
188
 
                return setattr(self._sio, name, value)
189
 
 
190
178
        # Remove 'TERM' == 'dumb' which causes us to *not* treat output as a
191
179
        # real terminal, even though isatty returns True
192
180
        self.overrideEnv('TERM', None)
193
 
        self.stderr = TTYStringIO()
194
 
        self.stdout = TTYStringIO()
 
181
        self.stderr = StringIOAsTTY()
 
182
        self.stdout = StringIOAsTTY()
195
183
        self.factory = ui.text.TextUIFactory(self.stdin, self.stdout,
196
184
            self.stderr)
197
185