~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2010-03-10 09:33:04 UTC
  • mto: (5082.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5083.
  • Revision ID: v.ladeuil+lp@free.fr-20100310093304-4245t4tazd4sxoav
Cleanup test from overly cautious checks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2016 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
import errno
21
21
import os
22
22
import re
23
 
import select
24
23
import socket
 
24
import stat
25
25
import sys
26
 
import tempfile
27
26
import time
28
27
 
29
28
from bzrlib import (
30
29
    errors,
31
 
    lazy_regex,
32
30
    osutils,
33
 
    symbol_versioning,
34
31
    tests,
35
32
    trace,
36
33
    win32utils,
37
34
    )
38
35
from bzrlib.tests import (
39
 
    features,
40
36
    file_utils,
41
37
    test__walkdirs_win32,
42
38
    )
43
 
from bzrlib.tests.scenarios import load_tests_apply_scenarios
44
 
 
45
 
 
46
 
class _UTF8DirReaderFeature(features.Feature):
 
39
 
 
40
 
 
41
class _UTF8DirReaderFeature(tests.Feature):
47
42
 
48
43
    def _probe(self):
49
44
        try:
56
51
    def feature_name(self):
57
52
        return 'bzrlib._readdir_pyx'
58
53
 
59
 
UTF8DirReaderFeature = features.ModuleAvailableFeature('bzrlib._readdir_pyx')
 
54
UTF8DirReaderFeature = _UTF8DirReaderFeature()
60
55
 
61
 
term_ios_feature = features.ModuleAvailableFeature('termios')
 
56
term_ios_feature = tests.ModuleAvailableFeature('termios')
62
57
 
63
58
 
64
59
def _already_unicode(s):
99
94
    return scenarios
100
95
 
101
96
 
102
 
load_tests = load_tests_apply_scenarios
 
97
def load_tests(basic_tests, module, loader):
 
98
    suite = loader.suiteClass()
 
99
    dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
 
100
        basic_tests, tests.condition_isinstance(TestDirReader))
 
101
    tests.multiply_tests(dir_reader_tests, dir_reader_scenarios(), suite)
 
102
    suite.addTest(remaining_tests)
 
103
    return suite
103
104
 
104
105
 
105
106
class TestContainsWhitespace(tests.TestCase):
106
107
 
107
108
    def test_contains_whitespace(self):
108
 
        self.assertTrue(osutils.contains_whitespace(u' '))
109
 
        self.assertTrue(osutils.contains_whitespace(u'hello there'))
110
 
        self.assertTrue(osutils.contains_whitespace(u'hellothere\n'))
111
 
        self.assertTrue(osutils.contains_whitespace(u'hello\nthere'))
112
 
        self.assertTrue(osutils.contains_whitespace(u'hello\rthere'))
113
 
        self.assertTrue(osutils.contains_whitespace(u'hello\tthere'))
 
109
        self.failUnless(osutils.contains_whitespace(u' '))
 
110
        self.failUnless(osutils.contains_whitespace(u'hello there'))
 
111
        self.failUnless(osutils.contains_whitespace(u'hellothere\n'))
 
112
        self.failUnless(osutils.contains_whitespace(u'hello\nthere'))
 
113
        self.failUnless(osutils.contains_whitespace(u'hello\rthere'))
 
114
        self.failUnless(osutils.contains_whitespace(u'hello\tthere'))
114
115
 
115
116
        # \xa0 is "Non-breaking-space" which on some python locales thinks it
116
117
        # is whitespace, but we do not.
117
 
        self.assertFalse(osutils.contains_whitespace(u''))
118
 
        self.assertFalse(osutils.contains_whitespace(u'hellothere'))
119
 
        self.assertFalse(osutils.contains_whitespace(u'hello\xa0there'))
 
118
        self.failIf(osutils.contains_whitespace(u''))
 
119
        self.failIf(osutils.contains_whitespace(u'hellothere'))
 
120
        self.failIf(osutils.contains_whitespace(u'hello\xa0there'))
120
121
 
121
122
 
122
123
class TestRename(tests.TestCaseInTempDir):
136
137
        # This should work everywhere
137
138
        self.create_file('a', 'something in a\n')
138
139
        self._fancy_rename('a', 'b')
139
 
        self.assertPathDoesNotExist('a')
140
 
        self.assertPathExists('b')
 
140
        self.failIfExists('a')
 
141
        self.failUnlessExists('b')
141
142
        self.check_file_contents('b', 'something in a\n')
142
143
 
143
144
        self.create_file('a', 'new something in a\n')
150
151
        self.create_file('target', 'data in target\n')
151
152
        self.assertRaises((IOError, OSError), self._fancy_rename,
152
153
                          'missingsource', 'target')
153
 
        self.assertPathExists('target')
 
154
        self.failUnlessExists('target')
154
155
        self.check_file_contents('target', 'data in target\n')
155
156
 
156
157
    def test_fancy_rename_fails_if_source_and_target_missing(self):
161
162
        # Rename should be semi-atomic on all platforms
162
163
        self.create_file('a', 'something in a\n')
163
164
        osutils.rename('a', 'b')
164
 
        self.assertPathDoesNotExist('a')
165
 
        self.assertPathExists('b')
 
165
        self.failIfExists('a')
 
166
        self.failUnlessExists('b')
166
167
        self.check_file_contents('b', 'something in a\n')
167
168
 
168
169
        self.create_file('a', 'new something in a\n')
180
181
        # we can't use failUnlessExists on case-insensitive filesystem
181
182
        # so try to check shape of the tree
182
183
        shape = sorted(os.listdir('.'))
183
 
        self.assertEqual(['A', 'B'], shape)
184
 
 
185
 
    def test_rename_exception(self):
186
 
        try:
187
 
            osutils.rename('nonexistent_path', 'different_nonexistent_path')
188
 
        except OSError, e:
189
 
            self.assertEqual(e.old_filename, 'nonexistent_path')
190
 
            self.assertEqual(e.new_filename, 'different_nonexistent_path')
191
 
            self.assertTrue('nonexistent_path' in e.strerror)
192
 
            self.assertTrue('different_nonexistent_path' in e.strerror)
 
184
        self.assertEquals(['A', 'B'], shape)
193
185
 
194
186
 
195
187
class TestRandChars(tests.TestCase):
222
214
                         (['src'], SRC_FOO_C),
223
215
                         (['src'], 'src'),
224
216
                         ]:
225
 
            self.assertTrue(osutils.is_inside_any(dirs, fn))
 
217
            self.assert_(osutils.is_inside_any(dirs, fn))
226
218
        for dirs, fn in [(['src'], 'srccontrol'),
227
219
                         (['src'], 'srccontrol/foo')]:
228
220
            self.assertFalse(osutils.is_inside_any(dirs, fn))
234
226
                         (['src/bar.c', 'bla/foo.c'], 'src'),
235
227
                         (['src'], 'src'),
236
228
                         ]:
237
 
            self.assertTrue(osutils.is_inside_or_parent_of_any(dirs, fn))
 
229
            self.assert_(osutils.is_inside_or_parent_of_any(dirs, fn))
238
230
 
239
231
        for dirs, fn in [(['src'], 'srccontrol'),
240
232
                         (['srccontrol/foo.c'], 'src'),
242
234
            self.assertFalse(osutils.is_inside_or_parent_of_any(dirs, fn))
243
235
 
244
236
 
245
 
class TestLstat(tests.TestCaseInTempDir):
246
 
 
247
 
    def test_lstat_matches_fstat(self):
248
 
        # On Windows, lstat and fstat don't always agree, primarily in the
249
 
        # 'st_ino' and 'st_dev' fields. So we force them to be '0' in our
250
 
        # custom implementation.
251
 
        if sys.platform == 'win32':
252
 
            # We only have special lstat/fstat if we have the extension.
253
 
            # Without it, we may end up re-reading content when we don't have
254
 
            # to, but otherwise it doesn't effect correctness.
255
 
            self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
256
 
        f = open('test-file.txt', 'wb')
257
 
        self.addCleanup(f.close)
258
 
        f.write('some content\n')
259
 
        f.flush()
260
 
        self.assertEqualStat(osutils.fstat(f.fileno()),
261
 
                             osutils.lstat('test-file.txt'))
262
 
 
263
 
 
264
237
class TestRmTree(tests.TestCaseInTempDir):
265
238
 
266
239
    def test_rmtree(self):
278
251
 
279
252
        osutils.rmtree('dir')
280
253
 
281
 
        self.assertPathDoesNotExist('dir/file')
282
 
        self.assertPathDoesNotExist('dir')
 
254
        self.failIfExists('dir/file')
 
255
        self.failIfExists('dir')
283
256
 
284
257
 
285
258
class TestDeleteAny(tests.TestCaseInTempDir):
298
271
 
299
272
    def test_file_kind(self):
300
273
        self.build_tree(['file', 'dir/'])
301
 
        self.assertEqual('file', osutils.file_kind('file'))
302
 
        self.assertEqual('directory', osutils.file_kind('dir/'))
 
274
        self.assertEquals('file', osutils.file_kind('file'))
 
275
        self.assertEquals('directory', osutils.file_kind('dir/'))
303
276
        if osutils.has_symlinks():
304
277
            os.symlink('symlink', 'symlink')
305
 
            self.assertEqual('symlink', osutils.file_kind('symlink'))
 
278
            self.assertEquals('symlink', osutils.file_kind('symlink'))
306
279
 
307
280
        # TODO: jam 20060529 Test a block device
308
281
        try:
311
284
            if e.errno not in (errno.ENOENT,):
312
285
                raise
313
286
        else:
314
 
            self.assertEqual('chardev', osutils.file_kind('/dev/null'))
 
287
            self.assertEquals('chardev', osutils.file_kind('/dev/null'))
315
288
 
316
289
        mkfifo = getattr(os, 'mkfifo', None)
317
290
        if mkfifo:
318
291
            mkfifo('fifo')
319
292
            try:
320
 
                self.assertEqual('fifo', osutils.file_kind('fifo'))
 
293
                self.assertEquals('fifo', osutils.file_kind('fifo'))
321
294
            finally:
322
295
                os.remove('fifo')
323
296
 
326
299
            s = socket.socket(AF_UNIX)
327
300
            s.bind('socket')
328
301
            try:
329
 
                self.assertEqual('socket', osutils.file_kind('socket'))
 
302
                self.assertEquals('socket', osutils.file_kind('socket'))
330
303
            finally:
331
304
                os.remove('socket')
332
305
 
437
410
        self.assertTrue(-eighteen_hours < offset < eighteen_hours)
438
411
 
439
412
 
440
 
class TestFdatasync(tests.TestCaseInTempDir):
441
 
 
442
 
    def do_fdatasync(self):
443
 
        f = tempfile.NamedTemporaryFile()
444
 
        osutils.fdatasync(f.fileno())
445
 
        f.close()
446
 
 
447
 
    @staticmethod
448
 
    def raise_eopnotsupp(*args, **kwargs):
449
 
        raise IOError(errno.EOPNOTSUPP, os.strerror(errno.EOPNOTSUPP))
450
 
 
451
 
    @staticmethod
452
 
    def raise_enotsup(*args, **kwargs):
453
 
        raise IOError(errno.ENOTSUP, os.strerror(errno.ENOTSUP))
454
 
 
455
 
    def test_fdatasync_handles_system_function(self):
456
 
        self.overrideAttr(os, "fdatasync")
457
 
        self.do_fdatasync()
458
 
 
459
 
    def test_fdatasync_handles_no_fdatasync_no_fsync(self):
460
 
        self.overrideAttr(os, "fdatasync")
461
 
        self.overrideAttr(os, "fsync")
462
 
        self.do_fdatasync()
463
 
 
464
 
    def test_fdatasync_handles_no_EOPNOTSUPP(self):
465
 
        self.overrideAttr(errno, "EOPNOTSUPP")
466
 
        self.do_fdatasync()
467
 
 
468
 
    def test_fdatasync_catches_ENOTSUP(self):
469
 
        enotsup = getattr(errno, "ENOTSUP", None)
470
 
        if enotsup is None:
471
 
            raise tests.TestNotApplicable("No ENOTSUP on this platform")
472
 
        self.overrideAttr(os, "fdatasync", self.raise_enotsup)
473
 
        self.do_fdatasync()
474
 
 
475
 
    def test_fdatasync_catches_EOPNOTSUPP(self):
476
 
        enotsup = getattr(errno, "EOPNOTSUPP", None)
477
 
        if enotsup is None:
478
 
            raise tests.TestNotApplicable("No EOPNOTSUPP on this platform")
479
 
        self.overrideAttr(os, "fdatasync", self.raise_eopnotsupp)
480
 
        self.do_fdatasync()
481
 
 
482
 
 
483
413
class TestLinks(tests.TestCaseInTempDir):
484
414
 
485
415
    def test_dereference_path(self):
486
 
        self.requireFeature(features.SymlinkFeature)
 
416
        self.requireFeature(tests.SymlinkFeature)
487
417
        cwd = osutils.realpath('.')
488
418
        os.mkdir('bar')
489
419
        bar_path = osutils.pathjoin(cwd, 'bar')
536
466
 
537
467
class TestCanonicalRelPath(tests.TestCaseInTempDir):
538
468
 
539
 
    _test_needs_features = [features.CaseInsCasePresFilenameFeature]
 
469
    _test_needs_features = [tests.CaseInsCasePresFilenameFeature]
540
470
 
541
471
    def test_canonical_relpath_simple(self):
542
472
        f = file('MixedCaseName', 'w')
543
473
        f.close()
544
474
        actual = osutils.canonical_relpath(self.test_base_dir, 'mixedcasename')
545
 
        self.assertEqual('work/MixedCaseName', actual)
 
475
        self.failUnlessEqual('work/MixedCaseName', actual)
546
476
 
547
477
    def test_canonical_relpath_missing_tail(self):
548
478
        os.mkdir('MixedCaseParent')
549
479
        actual = osutils.canonical_relpath(self.test_base_dir,
550
480
                                           'mixedcaseparent/nochild')
551
 
        self.assertEqual('work/MixedCaseParent/nochild', actual)
 
481
        self.failUnlessEqual('work/MixedCaseParent/nochild', actual)
552
482
 
553
483
 
554
484
class Test_CICPCanonicalRelpath(tests.TestCaseWithTransport):
598
528
    """Test pumpfile method."""
599
529
 
600
530
    def setUp(self):
601
 
        super(TestPumpFile, self).setUp()
 
531
        tests.TestCase.setUp(self)
602
532
        # create a test datablock
603
533
        self.block_size = 512
604
534
        pattern = '0123456789ABCDEF'
872
802
        self.assertEqual(None, osutils.safe_file_id(None))
873
803
 
874
804
 
875
 
class TestSendAll(tests.TestCase):
876
 
 
877
 
    def test_send_with_disconnected_socket(self):
878
 
        class DisconnectedSocket(object):
879
 
            def __init__(self, err):
880
 
                self.err = err
881
 
            def send(self, content):
882
 
                raise self.err
883
 
            def close(self):
884
 
                pass
885
 
        # All of these should be treated as ConnectionReset
886
 
        errs = []
887
 
        for err_cls in (IOError, socket.error):
888
 
            for errnum in osutils._end_of_stream_errors:
889
 
                errs.append(err_cls(errnum))
890
 
        for err in errs:
891
 
            sock = DisconnectedSocket(err)
892
 
            self.assertRaises(errors.ConnectionReset,
893
 
                osutils.send_all, sock, 'some more content')
894
 
 
895
 
    def test_send_with_no_progress(self):
896
 
        # See https://bugs.launchpad.net/bzr/+bug/1047309
897
 
        # It seems that paramiko can get into a state where it doesn't error,
898
 
        # but it returns 0 bytes sent for requests over and over again.
899
 
        class NoSendingSocket(object):
900
 
            def __init__(self):
901
 
                self.call_count = 0
902
 
            def send(self, bytes):
903
 
                self.call_count += 1
904
 
                if self.call_count > 100:
905
 
                    # Prevent the test suite from hanging
906
 
                    raise RuntimeError('too many calls')
907
 
                return 0
908
 
        sock = NoSendingSocket()
909
 
        self.assertRaises(errors.ConnectionReset,
910
 
                          osutils.send_all, sock, 'content')
911
 
        self.assertEqual(1, sock.call_count)
912
 
 
913
 
 
914
 
class TestPosixFuncs(tests.TestCase):
915
 
    """Test that the posix version of normpath returns an appropriate path
916
 
       when used with 2 leading slashes."""
917
 
 
918
 
    def test_normpath(self):
919
 
        self.assertEqual('/etc/shadow', osutils._posix_normpath('/etc/shadow'))
920
 
        self.assertEqual('/etc/shadow', osutils._posix_normpath('//etc/shadow'))
921
 
        self.assertEqual('/etc/shadow', osutils._posix_normpath('///etc/shadow'))
922
 
 
923
 
 
924
805
class TestWin32Funcs(tests.TestCase):
925
806
    """Test that _win32 versions of os utilities return appropriate paths."""
926
807
 
927
808
    def test_abspath(self):
928
 
        self.requireFeature(features.win32_feature)
929
809
        self.assertEqual('C:/foo', osutils._win32_abspath('C:\\foo'))
930
810
        self.assertEqual('C:/foo', osutils._win32_abspath('C:/foo'))
931
811
        self.assertEqual('//HOST/path', osutils._win32_abspath(r'\\HOST\path'))
944
824
                         osutils._win32_pathjoin('path/to', 'C:/foo'))
945
825
        self.assertEqual('path/to/foo',
946
826
                         osutils._win32_pathjoin('path/to/', 'foo'))
947
 
 
948
 
    def test_pathjoin_late_bugfix(self):
949
 
        if sys.version_info < (2, 7, 6):
950
 
            expected = '/foo'
951
 
        else:
952
 
            expected = 'C:/foo'
953
 
        self.assertEqual(expected,
 
827
        self.assertEqual('/foo',
954
828
                         osutils._win32_pathjoin('C:/path/to/', '/foo'))
955
 
        self.assertEqual(expected,
 
829
        self.assertEqual('/foo',
956
830
                         osutils._win32_pathjoin('C:\\path\\to\\', '\\foo'))
957
831
 
958
832
    def test_normpath(self):
978
852
        self.assertEqual('C:\\foo', osutils._win32_fixdrive('c:\\foo'))
979
853
 
980
854
    def test_win98_abspath(self):
981
 
        self.requireFeature(features.win32_feature)
982
855
        # absolute path
983
856
        self.assertEqual('C:/foo', osutils._win98_abspath('C:\\foo'))
984
857
        self.assertEqual('C:/foo', osutils._win98_abspath('C:/foo'))
987
860
        self.assertEqual('//HOST/path', osutils._win98_abspath('//HOST/path'))
988
861
        # relative path
989
862
        cwd = osutils.getcwd().rstrip('/')
990
 
        drive = osutils.ntpath.splitdrive(cwd)[0]
 
863
        drive = osutils._nt_splitdrive(cwd)[0]
991
864
        self.assertEqual(cwd+'/path', osutils._win98_abspath('path'))
992
865
        self.assertEqual(drive+'/path', osutils._win98_abspath('/path'))
993
866
        # unicode path
999
872
    """Test win32 functions that create files."""
1000
873
 
1001
874
    def test_getcwd(self):
1002
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
875
        self.requireFeature(tests.UnicodeFilenameFeature)
1003
876
        os.mkdir(u'mu-\xb5')
1004
877
        os.chdir(u'mu-\xb5')
1005
878
        # TODO: jam 20060427 This will probably fail on Mac OSX because
1035
908
        b.close()
1036
909
 
1037
910
        osutils._win32_rename('b', 'a')
1038
 
        self.assertPathExists('a')
1039
 
        self.assertPathDoesNotExist('b')
 
911
        self.failUnlessExists('a')
 
912
        self.failIfExists('b')
1040
913
        self.assertFileEqual('baz\n', 'a')
1041
914
 
1042
915
    def test_rename_missing_file(self):
1095
968
    """Test mac special functions that require directories."""
1096
969
 
1097
970
    def test_getcwd(self):
1098
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
971
        self.requireFeature(tests.UnicodeFilenameFeature)
1099
972
        os.mkdir(u'B\xe5gfors')
1100
973
        os.chdir(u'B\xe5gfors')
1101
974
        self.assertEndsWith(osutils._mac_getcwd(), u'B\xe5gfors')
1102
975
 
1103
976
    def test_getcwd_nonnorm(self):
1104
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
977
        self.requireFeature(tests.UnicodeFilenameFeature)
1105
978
        # Test that _mac_getcwd() will normalize this path
1106
979
        os.mkdir(u'Ba\u030agfors')
1107
980
        os.chdir(u'Ba\u030agfors')
1190
1063
        self.assertExpectedBlocks(expected_dirblocks[1:], result)
1191
1064
 
1192
1065
    def test_walkdirs_os_error(self):
1193
 
        # <https://bugs.launchpad.net/bzr/+bug/338653>
 
1066
        # <https://bugs.edge.launchpad.net/bzr/+bug/338653>
1194
1067
        # Pyrex readdir didn't raise useful messages if it had an error
1195
1068
        # reading the directory
1196
1069
        if sys.platform == 'win32':
1197
1070
            raise tests.TestNotApplicable(
1198
1071
                "readdir IOError not tested on win32")
1199
 
        self.requireFeature(features.not_running_as_root)
1200
1072
        os.mkdir("test-unreadable")
1201
1073
        os.chmod("test-unreadable", 0000)
1202
1074
        # must chmod it back so that it can be removed
1205
1077
        # (It would be ok if it happened earlier but at the moment it
1206
1078
        # doesn't.)
1207
1079
        e = self.assertRaises(OSError, list, osutils._walkdirs_utf8("."))
1208
 
        self.assertEqual('./test-unreadable', e.filename)
1209
 
        self.assertEqual(errno.EACCES, e.errno)
 
1080
        self.assertEquals('./test-unreadable', e.filename)
 
1081
        self.assertEquals(errno.EACCES, e.errno)
1210
1082
        # Ensure the message contains the file name
1211
1083
        self.assertContainsRe(str(e), "\./test-unreadable")
1212
1084
 
1213
 
 
1214
 
    def test_walkdirs_encoding_error(self):
1215
 
        # <https://bugs.launchpad.net/bzr/+bug/488519>
1216
 
        # walkdirs didn't raise a useful message when the filenames
1217
 
        # are not using the filesystem's encoding
1218
 
 
1219
 
        # require a bytestring based filesystem
1220
 
        self.requireFeature(features.ByteStringNamedFilesystem)
1221
 
 
1222
 
        tree = [
1223
 
            '.bzr',
1224
 
            '0file',
1225
 
            '1dir/',
1226
 
            '1dir/0file',
1227
 
            '1dir/1dir/',
1228
 
            '1file'
1229
 
            ]
1230
 
 
1231
 
        self.build_tree(tree)
1232
 
 
1233
 
        # rename the 1file to a latin-1 filename
1234
 
        os.rename("./1file", "\xe8file")
1235
 
        if "\xe8file" not in os.listdir("."):
1236
 
            self.skip("Lack filesystem that preserves arbitrary bytes")
1237
 
 
1238
 
        self._save_platform_info()
1239
 
        win32utils.winver = None # Avoid the win32 detection code
1240
 
        osutils._fs_enc = 'UTF-8'
1241
 
 
1242
 
        # this should raise on error
1243
 
        def attempt():
1244
 
            for dirdetail, dirblock in osutils.walkdirs('.'):
1245
 
                pass
1246
 
 
1247
 
        self.assertRaises(errors.BadFilenameEncoding, attempt)
1248
 
 
1249
1085
    def test__walkdirs_utf8(self):
1250
1086
        tree = [
1251
1087
            '.bzr',
1317
1153
        self.requireFeature(UTF8DirReaderFeature)
1318
1154
        self._save_platform_info()
1319
1155
        win32utils.winver = None # Avoid the win32 detection code
1320
 
        osutils._fs_enc = 'utf-8'
1321
 
        self.assertDirReaderIs(
1322
 
            UTF8DirReaderFeature.module.UTF8DirReader)
 
1156
        osutils._fs_enc = 'UTF-8'
 
1157
        self.assertDirReaderIs(UTF8DirReaderFeature.reader)
1323
1158
 
1324
1159
    def test_force_walkdirs_utf8_fs_ascii(self):
1325
1160
        self.requireFeature(UTF8DirReaderFeature)
1326
1161
        self._save_platform_info()
1327
1162
        win32utils.winver = None # Avoid the win32 detection code
1328
 
        osutils._fs_enc = 'ascii'
1329
 
        self.assertDirReaderIs(
1330
 
            UTF8DirReaderFeature.module.UTF8DirReader)
 
1163
        osutils._fs_enc = 'US-ASCII'
 
1164
        self.assertDirReaderIs(UTF8DirReaderFeature.reader)
 
1165
 
 
1166
    def test_force_walkdirs_utf8_fs_ANSI(self):
 
1167
        self.requireFeature(UTF8DirReaderFeature)
 
1168
        self._save_platform_info()
 
1169
        win32utils.winver = None # Avoid the win32 detection code
 
1170
        osutils._fs_enc = 'ANSI_X3.4-1968'
 
1171
        self.assertDirReaderIs(UTF8DirReaderFeature.reader)
1331
1172
 
1332
1173
    def test_force_walkdirs_utf8_fs_latin1(self):
1333
1174
        self._save_platform_info()
1334
1175
        win32utils.winver = None # Avoid the win32 detection code
1335
 
        osutils._fs_enc = 'iso-8859-1'
 
1176
        osutils._fs_enc = 'latin1'
1336
1177
        self.assertDirReaderIs(osutils.UnicodeDirReader)
1337
1178
 
1338
1179
    def test_force_walkdirs_utf8_nt(self):
1351
1192
 
1352
1193
    def test_unicode_walkdirs(self):
1353
1194
        """Walkdirs should always return unicode paths."""
1354
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
1195
        self.requireFeature(tests.UnicodeFilenameFeature)
1355
1196
        name0 = u'0file-\xb6'
1356
1197
        name1 = u'1dir-\u062c\u0648'
1357
1198
        name2 = u'2file-\u0633'
1394
1235
 
1395
1236
        The abspath portion might be in unicode or utf-8
1396
1237
        """
1397
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
1238
        self.requireFeature(tests.UnicodeFilenameFeature)
1398
1239
        name0 = u'0file-\xb6'
1399
1240
        name1 = u'1dir-\u062c\u0648'
1400
1241
        name2 = u'2file-\u0633'
1455
1296
 
1456
1297
        The abspath portion should be in unicode
1457
1298
        """
1458
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
1299
        self.requireFeature(tests.UnicodeFilenameFeature)
1459
1300
        # Use the unicode reader. TODO: split into driver-and-driven unit
1460
1301
        # tests.
1461
1302
        self._save_platform_info()
1502
1343
 
1503
1344
    def test__walkdirs_utf8_win32readdir(self):
1504
1345
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1505
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
1346
        self.requireFeature(tests.UnicodeFilenameFeature)
1506
1347
        from bzrlib._walkdirs_win32 import Win32ReadDir
1507
1348
        self._save_platform_info()
1508
1349
        osutils._selected_dir_reader = Win32ReadDir()
1559
1400
    def test__walkdirs_utf_win32_find_file_stat_file(self):
1560
1401
        """make sure our Stat values are valid"""
1561
1402
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1562
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
1403
        self.requireFeature(tests.UnicodeFilenameFeature)
1563
1404
        from bzrlib._walkdirs_win32 import Win32ReadDir
1564
1405
        name0u = u'0file-\xb6'
1565
1406
        name0 = name0u.encode('utf8')
1583
1424
    def test__walkdirs_utf_win32_find_file_stat_directory(self):
1584
1425
        """make sure our Stat values are valid"""
1585
1426
        self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
1586
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
1427
        self.requireFeature(tests.UnicodeFilenameFeature)
1587
1428
        from bzrlib._walkdirs_win32 import Win32ReadDir
1588
1429
        name0u = u'0dir-\u062c\u0648'
1589
1430
        name0 = name0u.encode('utf8')
1689
1530
        self.assertEqual(['c'], os.listdir('target/b'))
1690
1531
 
1691
1532
    def test_copy_tree_symlinks(self):
1692
 
        self.requireFeature(features.SymlinkFeature)
 
1533
        self.requireFeature(tests.SymlinkFeature)
1693
1534
        self.build_tree(['source/'])
1694
1535
        os.symlink('a/generic/path', 'source/lnk')
1695
1536
        osutils.copy_tree('source', 'target')
1720
1561
                          ('d', 'source/b', 'target/b'),
1721
1562
                          ('f', 'source/b/c', 'target/b/c'),
1722
1563
                         ], processed_files)
1723
 
        self.assertPathDoesNotExist('target')
 
1564
        self.failIfExists('target')
1724
1565
        if osutils.has_symlinks():
1725
1566
            self.assertEqual([('source/lnk', 'target/lnk')], processed_links)
1726
1567
 
1772
1613
        old = osutils.set_or_unset_env('BZR_TEST_ENV_VAR', None)
1773
1614
        self.assertEqual('foo', old)
1774
1615
        self.assertEqual(None, os.environ.get('BZR_TEST_ENV_VAR'))
1775
 
        self.assertFalse('BZR_TEST_ENV_VAR' in os.environ)
 
1616
        self.failIf('BZR_TEST_ENV_VAR' in os.environ)
1776
1617
 
1777
1618
 
1778
1619
class TestSizeShaFile(tests.TestCaseInTempDir):
1829
1670
 
1830
1671
class TestReCompile(tests.TestCase):
1831
1672
 
1832
 
    def _deprecated_re_compile_checked(self, *args, **kwargs):
1833
 
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1834
 
            osutils.re_compile_checked, *args, **kwargs)
1835
 
 
1836
1673
    def test_re_compile_checked(self):
1837
 
        r = self._deprecated_re_compile_checked(r'A*', re.IGNORECASE)
 
1674
        r = osutils.re_compile_checked(r'A*', re.IGNORECASE)
1838
1675
        self.assertTrue(r.match('aaaa'))
1839
1676
        self.assertTrue(r.match('aAaA'))
1840
1677
 
1841
1678
    def test_re_compile_checked_error(self):
1842
1679
        # like https://bugs.launchpad.net/bzr/+bug/251352
1843
 
 
1844
 
        # Due to possible test isolation error, re.compile is not lazy at
1845
 
        # this point. We re-install lazy compile.
1846
 
        lazy_regex.install_lazy_compile()
1847
1680
        err = self.assertRaises(
1848
1681
            errors.BzrCommandError,
1849
 
            self._deprecated_re_compile_checked, '*', re.IGNORECASE, 'test case')
 
1682
            osutils.re_compile_checked, '*', re.IGNORECASE, 'test case')
1850
1683
        self.assertEqual(
1851
 
            'Invalid regular expression in test case: '
1852
 
            '"*" nothing to repeat',
 
1684
            "Invalid regular expression in test case: '*': "
 
1685
            "nothing to repeat",
1853
1686
            str(err))
1854
1687
 
1855
1688
 
1856
1689
class TestDirReader(tests.TestCaseInTempDir):
1857
1690
 
1858
 
    scenarios = dir_reader_scenarios()
1859
 
 
1860
1691
    # Set by load_tests
1861
1692
    _dir_reader_class = None
1862
1693
    _native_to_unicode = None
1863
1694
 
1864
1695
    def setUp(self):
1865
 
        super(TestDirReader, self).setUp()
 
1696
        tests.TestCaseInTempDir.setUp(self)
1866
1697
        self.overrideAttr(osutils,
1867
1698
                          '_selected_dir_reader', self._dir_reader_class())
1868
1699
 
1962
1793
        return filtered_dirblocks
1963
1794
 
1964
1795
    def test_walk_unicode_tree(self):
1965
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
1796
        self.requireFeature(tests.UnicodeFilenameFeature)
1966
1797
        tree, expected_dirblocks = self._get_unicode_tree()
1967
1798
        self.build_tree(tree)
1968
1799
        result = list(osutils._walkdirs_utf8('.'))
1969
1800
        self.assertEqual(expected_dirblocks, self._filter_out(result))
1970
1801
 
1971
1802
    def test_symlink(self):
1972
 
        self.requireFeature(features.SymlinkFeature)
1973
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
1803
        self.requireFeature(tests.SymlinkFeature)
 
1804
        self.requireFeature(tests.UnicodeFilenameFeature)
1974
1805
        target = u'target\N{Euro Sign}'
1975
1806
        link_name = u'l\N{Euro Sign}nk'
1976
1807
        os.symlink(target, link_name)
1994
1825
    But prior python versions failed to properly encode the passed unicode
1995
1826
    string.
1996
1827
    """
1997
 
    _test_needs_features = [features.SymlinkFeature, features.UnicodeFilenameFeature]
 
1828
    _test_needs_features = [tests.SymlinkFeature, tests.UnicodeFilenameFeature]
1998
1829
 
1999
1830
    def setUp(self):
2000
1831
        super(tests.TestCaseInTempDir, self).setUp()
2003
1834
        os.symlink(self.target, self.link)
2004
1835
 
2005
1836
    def test_os_readlink_link_encoding(self):
2006
 
        self.assertEqual(self.target,  os.readlink(self.link))
 
1837
        if sys.version_info < (2, 6):
 
1838
            self.assertRaises(UnicodeEncodeError, os.readlink, self.link)
 
1839
        else:
 
1840
            self.assertEquals(self.target,  os.readlink(self.link))
2007
1841
 
2008
1842
    def test_os_readlink_link_decoding(self):
2009
 
        self.assertEqual(self.target.encode(osutils._fs_enc),
 
1843
        self.assertEquals(self.target.encode(osutils._fs_enc),
2010
1844
                          os.readlink(self.link.encode(osutils._fs_enc)))
2011
1845
 
2012
1846
 
2021
1855
        self.assertIsInstance(concurrency, int)
2022
1856
 
2023
1857
    def test_local_concurrency_environment_variable(self):
2024
 
        self.overrideEnv('BZR_CONCURRENCY', '2')
 
1858
        os.environ['BZR_CONCURRENCY'] = '2'
2025
1859
        self.assertEqual(2, osutils.local_concurrency(use_cache=False))
2026
 
        self.overrideEnv('BZR_CONCURRENCY', '3')
 
1860
        os.environ['BZR_CONCURRENCY'] = '3'
2027
1861
        self.assertEqual(3, osutils.local_concurrency(use_cache=False))
2028
 
        self.overrideEnv('BZR_CONCURRENCY', 'foo')
 
1862
        os.environ['BZR_CONCURRENCY'] = 'foo'
2029
1863
        self.assertEqual(1, osutils.local_concurrency(use_cache=False))
2030
1864
 
2031
1865
    def test_option_concurrency(self):
2032
 
        self.overrideEnv('BZR_CONCURRENCY', '1')
 
1866
        os.environ['BZR_CONCURRENCY'] = '1'
2033
1867
        self.run_bzr('rocks --concurrency 42')
2034
 
        # Command line overrides environment variable
2035
 
        self.assertEqual('42', os.environ['BZR_CONCURRENCY'])
2036
 
        self.assertEqual(42, osutils.local_concurrency(use_cache=False))
 
1868
        # Command line overrides envrionment variable
 
1869
        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
 
1870
        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
2037
1871
 
2038
1872
 
2039
1873
class TestFailedToLoadExtension(tests.TestCase):
2052
1886
    def test_failure_to_load(self):
2053
1887
        self._try_loading()
2054
1888
        self.assertLength(1, osutils._extension_load_failures)
2055
 
        self.assertEqual(osutils._extension_load_failures[0],
 
1889
        self.assertEquals(osutils._extension_load_failures[0],
2056
1890
            "No module named _fictional_extension_py")
2057
1891
 
2058
1892
    def test_report_extension_load_failures_no_warning(self):
2075
1909
 
2076
1910
class TestTerminalWidth(tests.TestCase):
2077
1911
 
2078
 
    def setUp(self):
2079
 
        super(TestTerminalWidth, self).setUp()
2080
 
        self._orig_terminal_size_state = osutils._terminal_size_state
2081
 
        self._orig_first_terminal_size = osutils._first_terminal_size
2082
 
        self.addCleanup(self.restore_osutils_globals)
2083
 
        osutils._terminal_size_state = 'no_data'
2084
 
        osutils._first_terminal_size = None
2085
 
 
2086
 
    def restore_osutils_globals(self):
2087
 
        osutils._terminal_size_state = self._orig_terminal_size_state
2088
 
        osutils._first_terminal_size = self._orig_first_terminal_size
2089
 
 
2090
1912
    def replace_stdout(self, new):
2091
1913
        self.overrideAttr(sys, 'stdout', new)
2092
1914
 
2107
1929
    def test_defaults_to_BZR_COLUMNS(self):
2108
1930
        # BZR_COLUMNS is set by the test framework
2109
1931
        self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
2110
 
        self.overrideEnv('BZR_COLUMNS', '12')
 
1932
        os.environ['BZR_COLUMNS'] = '12'
2111
1933
        self.assertEqual(12, osutils.terminal_width())
2112
1934
 
2113
 
    def test_BZR_COLUMNS_0_no_limit(self):
2114
 
        self.overrideEnv('BZR_COLUMNS', '0')
2115
 
        self.assertEqual(None, osutils.terminal_width())
2116
 
 
2117
1935
    def test_falls_back_to_COLUMNS(self):
2118
 
        self.overrideEnv('BZR_COLUMNS', None)
 
1936
        del os.environ['BZR_COLUMNS']
2119
1937
        self.assertNotEqual('42', os.environ['COLUMNS'])
2120
1938
        self.set_fake_tty()
2121
 
        self.overrideEnv('COLUMNS', '42')
 
1939
        os.environ['COLUMNS'] = '42'
2122
1940
        self.assertEqual(42, osutils.terminal_width())
2123
1941
 
2124
1942
    def test_tty_default_without_columns(self):
2125
 
        self.overrideEnv('BZR_COLUMNS', None)
2126
 
        self.overrideEnv('COLUMNS', None)
 
1943
        del os.environ['BZR_COLUMNS']
 
1944
        del os.environ['COLUMNS']
2127
1945
 
2128
1946
        def terminal_size(w, h):
2129
1947
            return 42, 42
2136
1954
        self.assertEqual(42, osutils.terminal_width())
2137
1955
 
2138
1956
    def test_non_tty_default_without_columns(self):
2139
 
        self.overrideEnv('BZR_COLUMNS', None)
2140
 
        self.overrideEnv('COLUMNS', None)
 
1957
        del os.environ['BZR_COLUMNS']
 
1958
        del os.environ['COLUMNS']
2141
1959
        self.replace_stdout(None)
2142
1960
        self.assertEqual(None, osutils.terminal_width())
2143
1961
 
2153
1971
        else:
2154
1972
            self.overrideAttr(termios, 'TIOCGWINSZ')
2155
1973
            del termios.TIOCGWINSZ
2156
 
        self.overrideEnv('BZR_COLUMNS', None)
2157
 
        self.overrideEnv('COLUMNS', None)
 
1974
        del os.environ['BZR_COLUMNS']
 
1975
        del os.environ['COLUMNS']
2158
1976
        # Whatever the result is, if we don't raise an exception, it's ok.
2159
1977
        osutils.terminal_width()
2160
 
 
2161
 
 
2162
 
class TestCreationOps(tests.TestCaseInTempDir):
2163
 
    _test_needs_features = [features.chown_feature]
2164
 
 
2165
 
    def setUp(self):
2166
 
        super(TestCreationOps, self).setUp()
2167
 
        self.overrideAttr(os, 'chown', self._dummy_chown)
2168
 
 
2169
 
        # params set by call to _dummy_chown
2170
 
        self.path = self.uid = self.gid = None
2171
 
 
2172
 
    def _dummy_chown(self, path, uid, gid):
2173
 
        self.path, self.uid, self.gid = path, uid, gid
2174
 
 
2175
 
    def test_copy_ownership_from_path(self):
2176
 
        """copy_ownership_from_path test with specified src."""
2177
 
        ownsrc = '/'
2178
 
        f = open('test_file', 'wt')
2179
 
        osutils.copy_ownership_from_path('test_file', ownsrc)
2180
 
 
2181
 
        s = os.stat(ownsrc)
2182
 
        self.assertEqual(self.path, 'test_file')
2183
 
        self.assertEqual(self.uid, s.st_uid)
2184
 
        self.assertEqual(self.gid, s.st_gid)
2185
 
 
2186
 
    def test_copy_ownership_nonesrc(self):
2187
 
        """copy_ownership_from_path test with src=None."""
2188
 
        f = open('test_file', 'wt')
2189
 
        # should use parent dir for permissions
2190
 
        osutils.copy_ownership_from_path('test_file')
2191
 
 
2192
 
        s = os.stat('..')
2193
 
        self.assertEqual(self.path, 'test_file')
2194
 
        self.assertEqual(self.uid, s.st_uid)
2195
 
        self.assertEqual(self.gid, s.st_gid)
2196
 
 
2197
 
 
2198
 
class TestPathFromEnviron(tests.TestCase):
2199
 
 
2200
 
    def test_is_unicode(self):
2201
 
        self.overrideEnv('BZR_TEST_PATH', './anywhere at all/')
2202
 
        path = osutils.path_from_environ('BZR_TEST_PATH')
2203
 
        self.assertIsInstance(path, unicode)
2204
 
        self.assertEqual(u'./anywhere at all/', path)
2205
 
 
2206
 
    def test_posix_path_env_ascii(self):
2207
 
        self.overrideEnv('BZR_TEST_PATH', '/tmp')
2208
 
        home = osutils._posix_path_from_environ('BZR_TEST_PATH')
2209
 
        self.assertIsInstance(home, unicode)
2210
 
        self.assertEqual(u'/tmp', home)
2211
 
 
2212
 
    def test_posix_path_env_unicode(self):
2213
 
        self.requireFeature(features.ByteStringNamedFilesystem)
2214
 
        self.overrideEnv('BZR_TEST_PATH', '/home/\xa7test')
2215
 
        self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
2216
 
        self.assertEqual(u'/home/\xa7test',
2217
 
            osutils._posix_path_from_environ('BZR_TEST_PATH'))
2218
 
        osutils._fs_enc = "iso8859-5"
2219
 
        self.assertEqual(u'/home/\u0407test',
2220
 
            osutils._posix_path_from_environ('BZR_TEST_PATH'))
2221
 
        osutils._fs_enc = "utf-8"
2222
 
        self.assertRaises(errors.BadFilenameEncoding,
2223
 
            osutils._posix_path_from_environ, 'BZR_TEST_PATH')
2224
 
 
2225
 
 
2226
 
class TestGetHomeDir(tests.TestCase):
2227
 
 
2228
 
    def test_is_unicode(self):
2229
 
        home = osutils._get_home_dir()
2230
 
        self.assertIsInstance(home, unicode)
2231
 
 
2232
 
    def test_posix_homeless(self):
2233
 
        self.overrideEnv('HOME', None)
2234
 
        home = osutils._get_home_dir()
2235
 
        self.assertIsInstance(home, unicode)
2236
 
 
2237
 
    def test_posix_home_ascii(self):
2238
 
        self.overrideEnv('HOME', '/home/test')
2239
 
        home = osutils._posix_get_home_dir()
2240
 
        self.assertIsInstance(home, unicode)
2241
 
        self.assertEqual(u'/home/test', home)
2242
 
 
2243
 
    def test_posix_home_unicode(self):
2244
 
        self.requireFeature(features.ByteStringNamedFilesystem)
2245
 
        self.overrideEnv('HOME', '/home/\xa7test')
2246
 
        self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
2247
 
        self.assertEqual(u'/home/\xa7test', osutils._posix_get_home_dir())
2248
 
        osutils._fs_enc = "iso8859-5"
2249
 
        self.assertEqual(u'/home/\u0407test', osutils._posix_get_home_dir())
2250
 
        osutils._fs_enc = "utf-8"
2251
 
        self.assertRaises(errors.BadFilenameEncoding,
2252
 
            osutils._posix_get_home_dir)
2253
 
 
2254
 
 
2255
 
class TestGetuserUnicode(tests.TestCase):
2256
 
 
2257
 
    def test_is_unicode(self):
2258
 
        user = osutils.getuser_unicode()
2259
 
        self.assertIsInstance(user, unicode)
2260
 
 
2261
 
    def envvar_to_override(self):
2262
 
        if sys.platform == "win32":
2263
 
            # Disable use of platform calls on windows so envvar is used
2264
 
            self.overrideAttr(win32utils, 'has_ctypes', False)
2265
 
            return 'USERNAME' # only variable used on windows
2266
 
        return 'LOGNAME' # first variable checked by getpass.getuser()
2267
 
 
2268
 
    def test_ascii_user(self):
2269
 
        self.overrideEnv(self.envvar_to_override(), 'jrandom')
2270
 
        self.assertEqual(u'jrandom', osutils.getuser_unicode())
2271
 
 
2272
 
    def test_unicode_user(self):
2273
 
        ue = osutils.get_user_encoding()
2274
 
        uni_val, env_val = tests.probe_unicode_in_user_encoding()
2275
 
        if uni_val is None:
2276
 
            raise tests.TestSkipped(
2277
 
                'Cannot find a unicode character that works in encoding %s'
2278
 
                % (osutils.get_user_encoding(),))
2279
 
        uni_username = u'jrandom' + uni_val
2280
 
        encoded_username = uni_username.encode(ue)
2281
 
        self.overrideEnv(self.envvar_to_override(), encoded_username)
2282
 
        self.assertEqual(uni_username, osutils.getuser_unicode())
2283
 
 
2284
 
 
2285
 
class TestBackupNames(tests.TestCase):
2286
 
 
2287
 
    def setUp(self):
2288
 
        super(TestBackupNames, self).setUp()
2289
 
        self.backups = []
2290
 
 
2291
 
    def backup_exists(self, name):
2292
 
        return name in self.backups
2293
 
 
2294
 
    def available_backup_name(self, name):
2295
 
        backup_name = osutils.available_backup_name(name, self.backup_exists)
2296
 
        self.backups.append(backup_name)
2297
 
        return backup_name
2298
 
 
2299
 
    def assertBackupName(self, expected, name):
2300
 
        self.assertEqual(expected, self.available_backup_name(name))
2301
 
 
2302
 
    def test_empty(self):
2303
 
        self.assertBackupName('file.~1~', 'file')
2304
 
 
2305
 
    def test_existing(self):
2306
 
        self.available_backup_name('file')
2307
 
        self.available_backup_name('file')
2308
 
        self.assertBackupName('file.~3~', 'file')
2309
 
        # Empty slots are found, this is not a strict requirement and may be
2310
 
        # revisited if we test against all implementations.
2311
 
        self.backups.remove('file.~2~')
2312
 
        self.assertBackupName('file.~2~', 'file')
2313
 
 
2314
 
 
2315
 
class TestFindExecutableInPath(tests.TestCase):
2316
 
 
2317
 
    def test_windows(self):
2318
 
        if sys.platform != 'win32':
2319
 
            raise tests.TestSkipped('test requires win32')
2320
 
        self.assertTrue(osutils.find_executable_on_path('explorer') is not None)
2321
 
        self.assertTrue(
2322
 
            osutils.find_executable_on_path('explorer.exe') is not None)
2323
 
        self.assertTrue(
2324
 
            osutils.find_executable_on_path('EXPLORER.EXE') is not None)
2325
 
        self.assertTrue(
2326
 
            osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)
2327
 
        self.assertTrue(osutils.find_executable_on_path('file.txt') is None)
2328
 
        
2329
 
    def test_windows_app_path(self):
2330
 
        if sys.platform != 'win32':
2331
 
            raise tests.TestSkipped('test requires win32')
2332
 
        # Override PATH env var so that exe can only be found on App Path
2333
 
        self.overrideEnv('PATH', '')
2334
 
        # Internt Explorer is always registered in the App Path
2335
 
        self.assertTrue(osutils.find_executable_on_path('iexplore') is not None)
2336
 
 
2337
 
    def test_other(self):
2338
 
        if sys.platform == 'win32':
2339
 
            raise tests.TestSkipped('test requires non-win32')
2340
 
        self.assertTrue(osutils.find_executable_on_path('sh') is not None)
2341
 
        self.assertTrue(
2342
 
            osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)
2343
 
 
2344
 
 
2345
 
class TestEnvironmentErrors(tests.TestCase):
2346
 
    """Test handling of environmental errors"""
2347
 
 
2348
 
    def test_is_oserror(self):
2349
 
        self.assertTrue(osutils.is_environment_error(
2350
 
            OSError(errno.EINVAL, "Invalid parameter")))
2351
 
 
2352
 
    def test_is_ioerror(self):
2353
 
        self.assertTrue(osutils.is_environment_error(
2354
 
            IOError(errno.EINVAL, "Invalid parameter")))
2355
 
 
2356
 
    def test_is_socket_error(self):
2357
 
        self.assertTrue(osutils.is_environment_error(
2358
 
            socket.error(errno.EINVAL, "Invalid parameter")))
2359
 
 
2360
 
    def test_is_select_error(self):
2361
 
        self.assertTrue(osutils.is_environment_error(
2362
 
            select.error(errno.EINVAL, "Invalid parameter")))
2363
 
 
2364
 
    def test_is_pywintypes_error(self):
2365
 
        self.requireFeature(features.pywintypes)
2366
 
        import pywintypes
2367
 
        self.assertTrue(osutils.is_environment_error(
2368
 
            pywintypes.error(errno.EINVAL, "Invalid parameter", "Caller")))