/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/test_osutils_encodings.py

  • Committer: Michael Hudson
  • Date: 2009-02-26 22:28:08 UTC
  • mto: This revision was merged to the branch mainline in revision 4121.
  • Revision ID: michael.hudson@canonical.com-20090226222808-url1udsulbge2r28
_this_ works

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for the osutils wrapper."""
18
18
 
74
74
    """Test the auto-detection of proper terminal encoding."""
75
75
 
76
76
    def setUp(self):
77
 
        TestCase.setUp(self)
78
 
        self.overrideAttr(sys, 'stdin')
79
 
        self.overrideAttr(sys, 'stdout')
80
 
        self.overrideAttr(sys, 'stderr')
81
 
        self.overrideAttr(osutils, '_cached_user_encoding')
 
77
        self._stdout = sys.stdout
 
78
        self._stderr = sys.stderr
 
79
        self._stdin = sys.stdin
 
80
        self._user_encoding = osutils._cached_user_encoding
 
81
 
 
82
        self.addCleanup(self._reset)
82
83
 
83
84
    def make_wrapped_streams(self,
84
85
                             stdout_encoding,
98
99
            fake_codec.add(stderr_encoding)
99
100
            fake_codec.add(stdin_encoding)
100
101
 
 
102
    def _reset(self):
 
103
        sys.stdout = self._stdout
 
104
        sys.stderr = self._stderr
 
105
        sys.stdin = self._stdin
 
106
        osutils._cached_user_encoding = self._user_encoding
 
107
 
101
108
    def test_get_terminal_encoding(self):
102
109
        self.make_wrapped_streams('stdout_encoding',
103
110
                                  'stderr_encoding',
149
156
    """Test detection of default user encoding."""
150
157
 
151
158
    def setUp(self):
152
 
        TestCase.setUp(self)
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())
 
159
        self._stderr = sys.stderr
 
160
        self._getpreferredencoding = locale.getpreferredencoding
 
161
        self.addCleanup(self._reset)
 
162
        sys.stderr = StringIOWrapper()
 
163
        # save $LANG
 
164
        self._LANG = os.environ.get('LANG')
 
165
 
 
166
    def _reset(self):
 
167
        locale.getpreferredencoding = self._getpreferredencoding
 
168
        sys.stderr = self._stderr
 
169
        # restore $LANG
 
170
        osutils.set_or_unset_env('LANG', self._LANG)
157
171
 
158
172
    def test_get_user_encoding(self):
159
173
        def f():