~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils_encodings.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for the osutils wrapper."""
18
18
 
27
27
    )
28
28
from bzrlib.tests import (
29
29
        StringIOWrapper,
30
 
        TestCase, 
 
30
        TestCase,
31
31
        )
32
32
 
33
33
 
34
34
class FakeCodec(object):
35
35
    """Special class that helps testing over several non-existed encodings.
36
 
    
 
36
 
37
37
    Clients can add new encoding names, but because of how codecs is
38
38
    implemented they cannot be removed. Be careful with naming to avoid
39
39
    collisions between tests.
51
51
            self._registered = True
52
52
        if encoding_name is not None:
53
53
            self._enabled_encodings.add(encoding_name)
54
 
        
 
54
 
55
55
    def __call__(self, encoding_name):
56
56
        """Called indirectly by codecs module during lookup"""
57
57
        if encoding_name in self._enabled_encodings:
62
62
 
63
63
 
64
64
class TestFakeCodec(TestCase):
65
 
    
 
65
 
66
66
    def test_fake_codec(self):
67
67
        self.assertRaises(LookupError, codecs.lookup, 'fake')
68
68
 
74
74
    """Test the auto-detection of proper terminal encoding."""
75
75
 
76
76
    def setUp(self):
 
77
        TestCase.setUp(self)
77
78
        self._stdout = sys.stdout
78
79
        self._stderr = sys.stderr
79
80
        self._stdin = sys.stdin
81
82
 
82
83
        self.addCleanup(self._reset)
83
84
 
84
 
    def make_wrapped_streams(self, 
 
85
    def make_wrapped_streams(self,
85
86
                             stdout_encoding,
86
87
                             stderr_encoding,
87
88
                             stdin_encoding,
143
144
                                  'cp-unknown',
144
145
                                  user_encoding='latin-1',
145
146
                                  enable_fake_encodings=False)
146
 
        
 
147
 
147
148
        self.assertEqual('latin-1', osutils.get_terminal_encoding())
148
149
 
149
150
        # check stderr
150
151
        self.assertEquals('bzr: warning: unknown terminal encoding cp-unknown.\n'
151
 
                          '  Using encoding latin-1 instead.\n', 
 
152
                          '  Using encoding latin-1 instead.\n',
152
153
                          sys.stderr.getvalue())
153
154
 
154
155
 
155
156
class TestUserEncoding(TestCase):
156
157
    """Test detection of default user encoding."""
157
 
    
 
158
 
158
159
    def setUp(self):
 
160
        TestCase.setUp(self)
159
161
        self._stderr = sys.stderr
160
162
        self._getpreferredencoding = locale.getpreferredencoding
161
163
        self.addCleanup(self._reset)