~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-05 11:32:59 UTC
  • mfrom: (6336.2.3 is_environment_error)
  • Revision ID: pqm@pqm.ubuntu.com-20111205113259-ias55e1z6dsn2ksp
(gz) Add is_environment_error() to check if exceptions are due to the
 process environment (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import errno
21
21
import os
22
22
import re
 
23
import select
23
24
import socket
24
25
import sys
25
26
import time
2179
2180
        self.assertTrue(osutils.find_executable_on_path('sh') is not None)
2180
2181
        self.assertTrue(
2181
2182
            osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)
 
2183
 
 
2184
 
 
2185
class TestEnvironmentErrors(tests.TestCase):
 
2186
    """Test handling of environmental errors"""
 
2187
 
 
2188
    def test_is_oserror(self):
 
2189
        self.assertTrue(osutils.is_environment_error(
 
2190
            OSError(errno.EINVAL, "Invalid parameter")))
 
2191
 
 
2192
    def test_is_ioerror(self):
 
2193
        self.assertTrue(osutils.is_environment_error(
 
2194
            IOError(errno.EINVAL, "Invalid parameter")))
 
2195
 
 
2196
    def test_is_socket_error(self):
 
2197
        self.assertTrue(osutils.is_environment_error(
 
2198
            socket.error(errno.EINVAL, "Invalid parameter")))
 
2199
 
 
2200
    def test_is_select_error(self):
 
2201
        self.assertTrue(osutils.is_environment_error(
 
2202
            select.error(errno.EINVAL, "Invalid parameter")))
 
2203
 
 
2204
    def test_is_pywintypes_error(self):
 
2205
        self.requireFeature(features.pywintypes)
 
2206
        import pywintypes
 
2207
        self.assertTrue(osutils.is_environment_error(
 
2208
            pywintypes.error(errno.EINVAL, "Invalid parameter", "Caller")))