~jelmer/ubuntu/maverick/bzr/2.2.5

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-03-10 14:11:59 UTC
  • mfrom: (1.2.1 upstream) (3.1.68 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090310141159-lwzzo5c1fwrtzgj4
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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
16
16
 
17
17
"""Tests for the osutils wrapper."""
18
18
 
 
19
from cStringIO import StringIO
19
20
import errno
20
21
import os
21
22
import socket
22
23
import stat
23
24
import sys
 
25
import time
24
26
 
25
 
import bzrlib
26
27
from bzrlib import (
27
28
    errors,
28
29
    osutils,
 
30
    tests,
29
31
    win32utils,
30
32
    )
31
33
from bzrlib.errors import BzrBadParameterNotUnicode, InvalidURL
33
35
        is_inside_any,
34
36
        is_inside_or_parent_of_any,
35
37
        pathjoin,
 
38
        pumpfile,
 
39
        pump_string_file,
 
40
        canonical_relpath,
36
41
        )
37
42
from bzrlib.tests import (
 
43
        Feature,
38
44
        probe_unicode_in_user_encoding,
39
45
        StringIOWrapper,
40
46
        SymlinkFeature,
 
47
        CaseInsCasePresFilenameFeature,
41
48
        TestCase,
42
49
        TestCaseInTempDir,
43
50
        TestSkipped,
44
51
        )
 
52
from bzrlib.tests.file_utils import (
 
53
    FakeReadFile,
 
54
    )
 
55
from bzrlib.tests.test__walkdirs_win32 import Win32ReadDirFeature
 
56
 
 
57
 
 
58
class _UTF8DirReaderFeature(Feature):
 
59
 
 
60
    def _probe(self):
 
61
        try:
 
62
            from bzrlib import _readdir_pyx
 
63
            self.reader = _readdir_pyx.UTF8DirReader
 
64
            return True
 
65
        except ImportError:
 
66
            return False
 
67
 
 
68
    def feature_name(self):
 
69
        return 'bzrlib._readdir_pyx'
 
70
 
 
71
UTF8DirReaderFeature = _UTF8DirReaderFeature()
45
72
 
46
73
 
47
74
class TestOSUtils(TestCaseInTempDir):
141
168
                         (['src'], 'src'),
142
169
                         ]:
143
170
            self.assert_(is_inside_or_parent_of_any(dirs, fn))
144
 
            
 
171
 
145
172
        for dirs, fn in [(['src'], 'srccontrol'),
146
173
                         (['srccontrol/foo.c'], 'src'),
147
174
                         (['src'], 'srccontrol/foo')]:
172
199
        if osutils.has_symlinks():
173
200
            os.symlink('symlink', 'symlink')
174
201
            self.assertEquals('symlink', osutils.file_kind('symlink'))
175
 
        
 
202
 
176
203
        # TODO: jam 20060529 Test a block device
177
204
        try:
178
205
            os.lstat('/dev/null')
263
290
    def test_format_date(self):
264
291
        self.assertRaises(errors.UnsupportedTimezoneFormat,
265
292
            osutils.format_date, 0, timezone='foo')
 
293
        self.assertIsInstance(osutils.format_date(0), str)
 
294
        self.assertIsInstance(osutils.format_local_date(0), unicode)
 
295
        # Testing for the actual value of the local weekday without
 
296
        # duplicating the code from format_date is difficult.
 
297
        # Instead blackbox.test_locale should check for localized
 
298
        # dates once they do occur in output strings.
266
299
 
267
300
    def test_dereference_path(self):
268
301
        self.requireFeature(SymlinkFeature)
274
307
        self.assertEqual(bar_path, osutils.realpath('./bar'))
275
308
        os.symlink('bar', 'foo')
276
309
        self.assertEqual(bar_path, osutils.realpath('./foo'))
277
 
        
 
310
 
278
311
        # Does not dereference terminal symlinks
279
312
        foo_path = osutils.pathjoin(cwd, 'foo')
280
313
        self.assertEqual(foo_path, osutils.dereference_path('./foo'))
318
351
        self.assertEqual("@", osutils.kind_marker("symlink"))
319
352
        self.assertRaises(errors.BzrError, osutils.kind_marker, "unknown")
320
353
 
 
354
    def test_host_os_dereferences_symlinks(self):
 
355
        osutils.host_os_dereferences_symlinks()
 
356
 
 
357
 
 
358
class TestCanonicalRelPath(TestCaseInTempDir):
 
359
 
 
360
    _test_needs_features = [CaseInsCasePresFilenameFeature]
 
361
 
 
362
    def test_canonical_relpath_simple(self):
 
363
        f = file('MixedCaseName', 'w')
 
364
        f.close()
 
365
        self.failUnlessEqual(
 
366
            canonical_relpath(self.test_base_dir, 'mixedcasename'),
 
367
            'work/MixedCaseName')
 
368
 
 
369
    def test_canonical_relpath_missing_tail(self):
 
370
        os.mkdir('MixedCaseParent')
 
371
        self.failUnlessEqual(
 
372
            canonical_relpath(self.test_base_dir, 'mixedcaseparent/nochild'),
 
373
            'work/MixedCaseParent/nochild')
 
374
 
 
375
 
 
376
class TestPumpFile(TestCase):
 
377
    """Test pumpfile method."""
 
378
    def setUp(self):
 
379
        # create a test datablock
 
380
        self.block_size = 512
 
381
        pattern = '0123456789ABCDEF'
 
382
        self.test_data = pattern * (3 * self.block_size / len(pattern))
 
383
        self.test_data_len = len(self.test_data)
 
384
 
 
385
    def test_bracket_block_size(self):
 
386
        """Read data in blocks with the requested read size bracketing the
 
387
        block size."""
 
388
        # make sure test data is larger than max read size
 
389
        self.assertTrue(self.test_data_len > self.block_size)
 
390
 
 
391
        from_file = FakeReadFile(self.test_data)
 
392
        to_file = StringIO()
 
393
 
 
394
        # read (max / 2) bytes and verify read size wasn't affected
 
395
        num_bytes_to_read = self.block_size / 2
 
396
        pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
 
397
        self.assertEqual(from_file.get_max_read_size(), num_bytes_to_read)
 
398
        self.assertEqual(from_file.get_read_count(), 1)
 
399
 
 
400
        # read (max) bytes and verify read size wasn't affected
 
401
        num_bytes_to_read = self.block_size
 
402
        from_file.reset_read_count()
 
403
        pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
 
404
        self.assertEqual(from_file.get_max_read_size(), num_bytes_to_read)
 
405
        self.assertEqual(from_file.get_read_count(), 1)
 
406
 
 
407
        # read (max + 1) bytes and verify read size was limited
 
408
        num_bytes_to_read = self.block_size + 1
 
409
        from_file.reset_read_count()
 
410
        pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
 
411
        self.assertEqual(from_file.get_max_read_size(), self.block_size)
 
412
        self.assertEqual(from_file.get_read_count(), 2)
 
413
 
 
414
        # finish reading the rest of the data
 
415
        num_bytes_to_read = self.test_data_len - to_file.tell()
 
416
        pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
 
417
 
 
418
        # report error if the data wasn't equal (we only report the size due
 
419
        # to the length of the data)
 
420
        response_data = to_file.getvalue()
 
421
        if response_data != self.test_data:
 
422
            message = "Data not equal.  Expected %d bytes, received %d."
 
423
            self.fail(message % (len(response_data), self.test_data_len))
 
424
 
 
425
    def test_specified_size(self):
 
426
        """Request a transfer larger than the maximum block size and verify
 
427
        that the maximum read doesn't exceed the block_size."""
 
428
        # make sure test data is larger than max read size
 
429
        self.assertTrue(self.test_data_len > self.block_size)
 
430
 
 
431
        # retrieve data in blocks
 
432
        from_file = FakeReadFile(self.test_data)
 
433
        to_file = StringIO()
 
434
        pumpfile(from_file, to_file, self.test_data_len, self.block_size)
 
435
 
 
436
        # verify read size was equal to the maximum read size
 
437
        self.assertTrue(from_file.get_max_read_size() > 0)
 
438
        self.assertEqual(from_file.get_max_read_size(), self.block_size)
 
439
        self.assertEqual(from_file.get_read_count(), 3)
 
440
 
 
441
        # report error if the data wasn't equal (we only report the size due
 
442
        # to the length of the data)
 
443
        response_data = to_file.getvalue()
 
444
        if response_data != self.test_data:
 
445
            message = "Data not equal.  Expected %d bytes, received %d."
 
446
            self.fail(message % (len(response_data), self.test_data_len))
 
447
 
 
448
    def test_to_eof(self):
 
449
        """Read to end-of-file and verify that the reads are not larger than
 
450
        the maximum read size."""
 
451
        # make sure test data is larger than max read size
 
452
        self.assertTrue(self.test_data_len > self.block_size)
 
453
 
 
454
        # retrieve data to EOF
 
455
        from_file = FakeReadFile(self.test_data)
 
456
        to_file = StringIO()
 
457
        pumpfile(from_file, to_file, -1, self.block_size)
 
458
 
 
459
        # verify read size was equal to the maximum read size
 
460
        self.assertEqual(from_file.get_max_read_size(), self.block_size)
 
461
        self.assertEqual(from_file.get_read_count(), 4)
 
462
 
 
463
        # report error if the data wasn't equal (we only report the size due
 
464
        # to the length of the data)
 
465
        response_data = to_file.getvalue()
 
466
        if response_data != self.test_data:
 
467
            message = "Data not equal.  Expected %d bytes, received %d."
 
468
            self.fail(message % (len(response_data), self.test_data_len))
 
469
 
 
470
    def test_defaults(self):
 
471
        """Verifies that the default arguments will read to EOF -- this
 
472
        test verifies that any existing usages of pumpfile will not be broken
 
473
        with this new version."""
 
474
        # retrieve data using default (old) pumpfile method
 
475
        from_file = FakeReadFile(self.test_data)
 
476
        to_file = StringIO()
 
477
        pumpfile(from_file, to_file)
 
478
 
 
479
        # report error if the data wasn't equal (we only report the size due
 
480
        # to the length of the data)
 
481
        response_data = to_file.getvalue()
 
482
        if response_data != self.test_data:
 
483
            message = "Data not equal.  Expected %d bytes, received %d."
 
484
            self.fail(message % (len(response_data), self.test_data_len))
 
485
 
 
486
    def test_report_activity(self):
 
487
        activity = []
 
488
        def log_activity(length, direction):
 
489
            activity.append((length, direction))
 
490
        from_file = StringIO(self.test_data)
 
491
        to_file = StringIO()
 
492
        pumpfile(from_file, to_file, buff_size=500,
 
493
                 report_activity=log_activity, direction='read')
 
494
        self.assertEqual([(500, 'read'), (500, 'read'), (500, 'read'),
 
495
                          (36, 'read')], activity)
 
496
 
 
497
        from_file = StringIO(self.test_data)
 
498
        to_file = StringIO()
 
499
        del activity[:]
 
500
        pumpfile(from_file, to_file, buff_size=500,
 
501
                 report_activity=log_activity, direction='write')
 
502
        self.assertEqual([(500, 'write'), (500, 'write'), (500, 'write'),
 
503
                          (36, 'write')], activity)
 
504
 
 
505
        # And with a limited amount of data
 
506
        from_file = StringIO(self.test_data)
 
507
        to_file = StringIO()
 
508
        del activity[:]
 
509
        pumpfile(from_file, to_file, buff_size=500, read_length=1028,
 
510
                 report_activity=log_activity, direction='read')
 
511
        self.assertEqual([(500, 'read'), (500, 'read'), (28, 'read')], activity)
 
512
 
 
513
 
 
514
 
 
515
class TestPumpStringFile(TestCase):
 
516
 
 
517
    def test_empty(self):
 
518
        output = StringIO()
 
519
        pump_string_file("", output)
 
520
        self.assertEqual("", output.getvalue())
 
521
 
 
522
    def test_more_than_segment_size(self):
 
523
        output = StringIO()
 
524
        pump_string_file("123456789", output, 2)
 
525
        self.assertEqual("123456789", output.getvalue())
 
526
 
 
527
    def test_segment_size(self):
 
528
        output = StringIO()
 
529
        pump_string_file("12", output, 2)
 
530
        self.assertEqual("12", output.getvalue())
 
531
 
 
532
    def test_segment_size_multiple(self):
 
533
        output = StringIO()
 
534
        pump_string_file("1234", output, 2)
 
535
        self.assertEqual("1234", output.getvalue())
 
536
 
321
537
 
322
538
class TestSafeUnicode(TestCase):
323
539
 
473
689
 
474
690
class TestWin32FuncsDirs(TestCaseInTempDir):
475
691
    """Test win32 functions that create files."""
476
 
    
 
692
 
477
693
    def test_getcwd(self):
478
694
        if win32utils.winver == 'Windows 98':
479
695
            raise TestSkipped('Windows 98 cannot handle unicode filenames')
585
801
        self.assertEndsWith(osutils._mac_getcwd(), u'B\xe5gfors')
586
802
 
587
803
 
 
804
class TestChunksToLines(TestCase):
 
805
 
 
806
    def test_smoketest(self):
 
807
        self.assertEqual(['foo\n', 'bar\n', 'baz\n'],
 
808
                         osutils.chunks_to_lines(['foo\nbar', '\nbaz\n']))
 
809
        self.assertEqual(['foo\n', 'bar\n', 'baz\n'],
 
810
                         osutils.chunks_to_lines(['foo\n', 'bar\n', 'baz\n']))
 
811
 
 
812
    def test_osutils_binding(self):
 
813
        from bzrlib.tests import test__chunks_to_lines
 
814
        if test__chunks_to_lines.CompiledChunksToLinesFeature.available():
 
815
            from bzrlib._chunks_to_lines_pyx import chunks_to_lines
 
816
        else:
 
817
            from bzrlib._chunks_to_lines_py import chunks_to_lines
 
818
        self.assertIs(chunks_to_lines, osutils.chunks_to_lines)
 
819
 
 
820
 
588
821
class TestSplitLines(TestCase):
589
822
 
590
823
    def test_split_unicode(self):
646
879
        self.assertEqual(expected_dirblocks[1:],
647
880
            [(dirinfo, [line[0:3] for line in block]) for dirinfo, block in result])
648
881
 
 
882
    def test_walkdirs_os_error(self):
 
883
        # <https://bugs.edge.launchpad.net/bzr/+bug/338653>
 
884
        # Pyrex readdir didn't raise useful messages if it had an error
 
885
        # reading the directory
 
886
        if sys.platform == 'win32':
 
887
            raise tests.TestNotApplicable(
 
888
                "readdir IOError not tested on win32")
 
889
        os.mkdir("test-unreadable")
 
890
        os.chmod("test-unreadable", 0000)
 
891
        # must chmod it back so that it can be removed
 
892
        self.addCleanup(lambda: os.chmod("test-unreadable", 0700))
 
893
        # The error is not raised until the generator is actually evaluated.
 
894
        # (It would be ok if it happened earlier but at the moment it
 
895
        # doesn't.)
 
896
        e = self.assertRaises(OSError, list,
 
897
            osutils._walkdirs_utf8("."))
 
898
        self.assertEquals(e.filename, './test-unreadable')
 
899
        self.assertEquals(str(e),
 
900
            "[Errno 13] chdir: Permission denied: './test-unreadable'")
 
901
 
649
902
    def test__walkdirs_utf8(self):
650
903
        tree = [
651
904
            '.bzr',
701
954
                new_dirblock.append((info[0], info[1], info[2], info[4]))
702
955
            dirblock[:] = new_dirblock
703
956
 
 
957
    def _save_platform_info(self):
 
958
        cur_winver = win32utils.winver
 
959
        cur_fs_enc = osutils._fs_enc
 
960
        cur_dir_reader = osutils._selected_dir_reader
 
961
        def restore():
 
962
            win32utils.winver = cur_winver
 
963
            osutils._fs_enc = cur_fs_enc
 
964
            osutils._selected_dir_reader = cur_dir_reader
 
965
        self.addCleanup(restore)
 
966
 
 
967
    def assertReadFSDirIs(self, expected):
 
968
        """Assert the right implementation for _walkdirs_utf8 is chosen."""
 
969
        # Force it to redetect
 
970
        osutils._selected_dir_reader = None
 
971
        # Nothing to list, but should still trigger the selection logic
 
972
        self.assertEqual([(('', '.'), [])], list(osutils._walkdirs_utf8('.')))
 
973
        self.assertIsInstance(osutils._selected_dir_reader, expected)
 
974
 
 
975
    def test_force_walkdirs_utf8_fs_utf8(self):
 
976
        self.requireFeature(UTF8DirReaderFeature)
 
977
        self._save_platform_info()
 
978
        win32utils.winver = None # Avoid the win32 detection code
 
979
        osutils._fs_enc = 'UTF-8'
 
980
        self.assertReadFSDirIs(UTF8DirReaderFeature.reader)
 
981
 
 
982
    def test_force_walkdirs_utf8_fs_ascii(self):
 
983
        self.requireFeature(UTF8DirReaderFeature)
 
984
        self._save_platform_info()
 
985
        win32utils.winver = None # Avoid the win32 detection code
 
986
        osutils._fs_enc = 'US-ASCII'
 
987
        self.assertReadFSDirIs(UTF8DirReaderFeature.reader)
 
988
 
 
989
    def test_force_walkdirs_utf8_fs_ANSI(self):
 
990
        self.requireFeature(UTF8DirReaderFeature)
 
991
        self._save_platform_info()
 
992
        win32utils.winver = None # Avoid the win32 detection code
 
993
        osutils._fs_enc = 'ANSI_X3.4-1968'
 
994
        self.assertReadFSDirIs(UTF8DirReaderFeature.reader)
 
995
 
 
996
    def test_force_walkdirs_utf8_fs_latin1(self):
 
997
        self._save_platform_info()
 
998
        win32utils.winver = None # Avoid the win32 detection code
 
999
        osutils._fs_enc = 'latin1'
 
1000
        self.assertReadFSDirIs(osutils.UnicodeDirReader)
 
1001
 
 
1002
    def test_force_walkdirs_utf8_nt(self):
 
1003
        # Disabled because the thunk of the whole walkdirs api is disabled.
 
1004
        self.requireFeature(Win32ReadDirFeature)
 
1005
        self._save_platform_info()
 
1006
        win32utils.winver = 'Windows NT'
 
1007
        from bzrlib._walkdirs_win32 import Win32ReadDir
 
1008
        self.assertReadFSDirIs(Win32ReadDir)
 
1009
 
 
1010
    def test_force_walkdirs_utf8_98(self):
 
1011
        self.requireFeature(Win32ReadDirFeature)
 
1012
        self._save_platform_info()
 
1013
        win32utils.winver = 'Windows 98'
 
1014
        self.assertReadFSDirIs(osutils.UnicodeDirReader)
 
1015
 
704
1016
    def test_unicode_walkdirs(self):
705
1017
        """Walkdirs should always return unicode paths."""
706
1018
        name0 = u'0file-\xb6'
808
1120
            result.append((dirdetail, new_dirblock))
809
1121
        self.assertEqual(expected_dirblocks, result)
810
1122
 
811
 
    def test_unicode__walkdirs_unicode_to_utf8(self):
812
 
        """walkdirs_unicode_to_utf8 should be a safe fallback everywhere
 
1123
    def test__walkdirs_utf8_with_unicode_fs(self):
 
1124
        """UnicodeDirReader should be a safe fallback everywhere
813
1125
 
814
1126
        The abspath portion should be in unicode
815
1127
        """
 
1128
        # Use the unicode reader. TODO: split into driver-and-driven unit
 
1129
        # tests.
 
1130
        self._save_platform_info()
 
1131
        osutils._selected_dir_reader = osutils.UnicodeDirReader()
816
1132
        name0u = u'0file-\xb6'
817
1133
        name1u = u'1dir-\u062c\u0648'
818
1134
        name2u = u'2file-\u0633'
853
1169
                 ]
854
1170
                ),
855
1171
            ]
856
 
        result = list(osutils._walkdirs_unicode_to_utf8('.'))
857
 
        self._filter_out_stat(result)
858
 
        self.assertEqual(expected_dirblocks, result)
 
1172
        result = list(osutils._walkdirs_utf8('.'))
 
1173
        self._filter_out_stat(result)
 
1174
        self.assertEqual(expected_dirblocks, result)
 
1175
 
 
1176
    def test__walkdirs_utf8_win32readdir(self):
 
1177
        self.requireFeature(Win32ReadDirFeature)
 
1178
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1179
        from bzrlib._walkdirs_win32 import Win32ReadDir
 
1180
        self._save_platform_info()
 
1181
        osutils._selected_dir_reader = Win32ReadDir()
 
1182
        name0u = u'0file-\xb6'
 
1183
        name1u = u'1dir-\u062c\u0648'
 
1184
        name2u = u'2file-\u0633'
 
1185
        tree = [
 
1186
            name0u,
 
1187
            name1u + '/',
 
1188
            name1u + '/' + name0u,
 
1189
            name1u + '/' + name1u + '/',
 
1190
            name2u,
 
1191
            ]
 
1192
        self.build_tree(tree)
 
1193
        name0 = name0u.encode('utf8')
 
1194
        name1 = name1u.encode('utf8')
 
1195
        name2 = name2u.encode('utf8')
 
1196
 
 
1197
        # All of the abspaths should be in unicode, all of the relative paths
 
1198
        # should be in utf8
 
1199
        expected_dirblocks = [
 
1200
                (('', '.'),
 
1201
                 [(name0, name0, 'file', './' + name0u),
 
1202
                  (name1, name1, 'directory', './' + name1u),
 
1203
                  (name2, name2, 'file', './' + name2u),
 
1204
                 ]
 
1205
                ),
 
1206
                ((name1, './' + name1u),
 
1207
                 [(name1 + '/' + name0, name0, 'file', './' + name1u
 
1208
                                                        + '/' + name0u),
 
1209
                  (name1 + '/' + name1, name1, 'directory', './' + name1u
 
1210
                                                            + '/' + name1u),
 
1211
                 ]
 
1212
                ),
 
1213
                ((name1 + '/' + name1, './' + name1u + '/' + name1u),
 
1214
                 [
 
1215
                 ]
 
1216
                ),
 
1217
            ]
 
1218
        result = list(osutils._walkdirs_utf8(u'.'))
 
1219
        self._filter_out_stat(result)
 
1220
        self.assertEqual(expected_dirblocks, result)
 
1221
 
 
1222
    def assertStatIsCorrect(self, path, win32stat):
 
1223
        os_stat = os.stat(path)
 
1224
        self.assertEqual(os_stat.st_size, win32stat.st_size)
 
1225
        self.assertAlmostEqual(os_stat.st_mtime, win32stat.st_mtime, places=4)
 
1226
        self.assertAlmostEqual(os_stat.st_ctime, win32stat.st_ctime, places=4)
 
1227
        self.assertAlmostEqual(os_stat.st_atime, win32stat.st_atime, places=4)
 
1228
        self.assertEqual(os_stat.st_dev, win32stat.st_dev)
 
1229
        self.assertEqual(os_stat.st_ino, win32stat.st_ino)
 
1230
        self.assertEqual(os_stat.st_mode, win32stat.st_mode)
 
1231
 
 
1232
    def test__walkdirs_utf_win32_find_file_stat_file(self):
 
1233
        """make sure our Stat values are valid"""
 
1234
        self.requireFeature(Win32ReadDirFeature)
 
1235
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1236
        from bzrlib._walkdirs_win32 import Win32ReadDir
 
1237
        name0u = u'0file-\xb6'
 
1238
        name0 = name0u.encode('utf8')
 
1239
        self.build_tree([name0u])
 
1240
        # I hate to sleep() here, but I'm trying to make the ctime different
 
1241
        # from the mtime
 
1242
        time.sleep(2)
 
1243
        f = open(name0u, 'ab')
 
1244
        try:
 
1245
            f.write('just a small update')
 
1246
        finally:
 
1247
            f.close()
 
1248
 
 
1249
        result = Win32ReadDir().read_dir('', u'.')
 
1250
        entry = result[0]
 
1251
        self.assertEqual((name0, name0, 'file'), entry[:3])
 
1252
        self.assertEqual(u'./' + name0u, entry[4])
 
1253
        self.assertStatIsCorrect(entry[4], entry[3])
 
1254
        self.assertNotEqual(entry[3].st_mtime, entry[3].st_ctime)
 
1255
 
 
1256
    def test__walkdirs_utf_win32_find_file_stat_directory(self):
 
1257
        """make sure our Stat values are valid"""
 
1258
        self.requireFeature(Win32ReadDirFeature)
 
1259
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1260
        from bzrlib._walkdirs_win32 import Win32ReadDir
 
1261
        name0u = u'0dir-\u062c\u0648'
 
1262
        name0 = name0u.encode('utf8')
 
1263
        self.build_tree([name0u + '/'])
 
1264
 
 
1265
        result = Win32ReadDir().read_dir('', u'.')
 
1266
        entry = result[0]
 
1267
        self.assertEqual((name0, name0, 'directory'), entry[:3])
 
1268
        self.assertEqual(u'./' + name0u, entry[4])
 
1269
        self.assertStatIsCorrect(entry[4], entry[3])
859
1270
 
860
1271
    def assertPathCompare(self, path_less, path_greater):
861
1272
        """check that path_less and path_greater compare correctly."""
936
1347
 
937
1348
 
938
1349
class TestCopyTree(TestCaseInTempDir):
939
 
    
 
1350
 
940
1351
    def test_copy_basic_tree(self):
941
1352
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
942
1353
        osutils.copy_tree('source', 'target')
1021
1432
 
1022
1433
    def test_unicode(self):
1023
1434
        """Environment can only contain plain strings
1024
 
        
 
1435
 
1025
1436
        So Unicode strings must be encoded.
1026
1437
        """
1027
1438
        uni_val, env_val = probe_unicode_in_user_encoding()
1028
1439
        if uni_val is None:
1029
1440
            raise TestSkipped('Cannot find a unicode character that works in'
1030
 
                              ' encoding %s' % (bzrlib.user_encoding,))
 
1441
                              ' encoding %s' % (osutils.get_user_encoding(),))
1031
1442
 
1032
1443
        old = osutils.set_or_unset_env('BZR_TEST_ENV_VAR', uni_val)
1033
1444
        self.assertEqual(env_val, os.environ.get('BZR_TEST_ENV_VAR'))
1077
1488
        self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))
1078
1489
 
1079
1490
 
1080
 
_debug_text = \
1081
 
r'''# Copyright (C) 2005, 2006 Canonical Ltd
1082
 
#
1083
 
# This program is free software; you can redistribute it and/or modify
1084
 
# it under the terms of the GNU General Public License as published by
1085
 
# the Free Software Foundation; either version 2 of the License, or
1086
 
# (at your option) any later version.
1087
 
#
1088
 
# This program is distributed in the hope that it will be useful,
1089
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1090
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1091
 
# GNU General Public License for more details.
1092
 
#
1093
 
# You should have received a copy of the GNU General Public License
1094
 
# along with this program; if not, write to the Free Software
1095
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1096
 
 
1097
 
 
1098
 
# NOTE: If update these, please also update the help for global-options in
1099
 
#       bzrlib/help_topics/__init__.py
1100
 
 
1101
 
debug_flags = set()
1102
 
"""Set of flags that enable different debug behaviour.
1103
 
 
1104
 
These are set with eg ``-Dlock`` on the bzr command line.
1105
 
 
1106
 
Options include:
1107
 
 
1108
 
 * auth - show authentication sections used
1109
 
 * error - show stack traces for all top level exceptions
1110
 
 * evil - capture call sites that do expensive or badly-scaling operations.
1111
 
 * fetch - trace history copying between repositories
1112
 
 * graph - trace graph traversal information
1113
 
 * hashcache - log every time a working file is read to determine its hash
1114
 
 * hooks - trace hook execution
1115
 
 * hpss - trace smart protocol requests and responses
1116
 
 * http - trace http connections, requests and responses
1117
 
 * index - trace major index operations
1118
 
 * knit - trace knit operations
1119
 
 * lock - trace when lockdir locks are taken or released
1120
 
 * merge - emit information for debugging merges
1121
 
 * pack - emit information about pack operations
1122
 
 
1123
 
"""
1124
 
'''
1125
 
 
1126
 
 
1127
1491
class TestResourceLoading(TestCaseInTempDir):
1128
1492
 
1129
1493
    def test_resource_string(self):
1130
1494
        # test resource in bzrlib
1131
1495
        text = osutils.resource_string('bzrlib', 'debug.py')
1132
 
        self.assertEquals(_debug_text, text)
 
1496
        self.assertContainsRe(text, "debug_flags = set()")
1133
1497
        # test resource under bzrlib
1134
1498
        text = osutils.resource_string('bzrlib.ui', 'text.py')
1135
1499
        self.assertContainsRe(text, "class TextUIFactory")