~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils_encodings.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
 
76
76
    def setUp(self):
77
77
        TestCase.setUp(self)
78
 
        self._stdout = sys.stdout
79
 
        self._stderr = sys.stderr
80
 
        self._stdin = sys.stdin
81
 
        self._user_encoding = osutils._cached_user_encoding
82
 
 
83
 
        self.addCleanup(self._reset)
 
78
        self.overrideAttr(sys, 'stdin')
 
79
        self.overrideAttr(sys, 'stdout')
 
80
        self.overrideAttr(sys, 'stderr')
 
81
        self.overrideAttr(osutils, '_cached_user_encoding')
84
82
 
85
83
    def make_wrapped_streams(self,
86
84
                             stdout_encoding,
100
98
            fake_codec.add(stderr_encoding)
101
99
            fake_codec.add(stdin_encoding)
102
100
 
103
 
    def _reset(self):
104
 
        sys.stdout = self._stdout
105
 
        sys.stderr = self._stderr
106
 
        sys.stdin = self._stdin
107
 
        osutils._cached_user_encoding = self._user_encoding
108
 
 
109
101
    def test_get_terminal_encoding(self):
110
102
        self.make_wrapped_streams('stdout_encoding',
111
103
                                  'stderr_encoding',
158
150
 
159
151
    def setUp(self):
160
152
        TestCase.setUp(self)
161
 
        self._stderr = sys.stderr
162
 
        self._getpreferredencoding = locale.getpreferredencoding
163
 
        self.addCleanup(self._reset)
164
 
        sys.stderr = StringIOWrapper()
165
 
        # save $LANG
166
 
        self._LANG = os.environ.get('LANG')
167
 
 
168
 
    def _reset(self):
169
 
        locale.getpreferredencoding = self._getpreferredencoding
170
 
        sys.stderr = self._stderr
171
 
        # restore $LANG
172
 
        osutils.set_or_unset_env('LANG', self._LANG)
 
153
        self.overrideAttr(locale, 'getpreferredencoding')
 
154
        self.addCleanup(osutils.set_or_unset_env,
 
155
                        'LANG', os.environ.get('LANG'))
 
156
        self.overrideAttr(sys, 'stderr', StringIOWrapper())
173
157
 
174
158
    def test_get_user_encoding(self):
175
159
        def f():