605
605
self.assertEqual(expected_dirblocks[1:],
606
606
[(dirinfo, [line[0:3] for line in block]) for dirinfo, block in result])
608
def _filter_out_stat(self, result):
609
"""Filter out the stat value from the walkdirs result"""
610
for dirdetail, dirblock in result:
612
for info in dirblock:
613
# Ignore info[3] which is the stat
614
new_dirblock.append((info[0], info[1], info[2], info[4]))
615
dirblock[:] = new_dirblock
617
def test_unicode_walkdirs(self):
618
"""Walkdirs should always return unicode paths."""
619
name0 = u'0file-\xb6'
620
name1 = u'1dir-\u062c\u0648'
621
name2 = u'2file-\u0633'
626
name1 + '/' + name1 + '/',
630
self.build_tree(tree)
632
raise TestSkipped('Could not represent Unicode chars'
633
' in current encoding.')
634
expected_dirblocks = [
636
[(name0, name0, 'file', './' + name0),
637
(name1, name1, 'directory', './' + name1),
638
(name2, name2, 'file', './' + name2),
641
((name1, './' + name1),
642
[(name1 + '/' + name0, name0, 'file', './' + name1
644
(name1 + '/' + name1, name1, 'directory', './' + name1
648
((name1 + '/' + name1, './' + name1 + '/' + name1),
653
result = list(osutils.walkdirs('.'))
654
self._filter_out_stat(result)
655
self.assertEqual(expected_dirblocks, result)
656
result = list(osutils.walkdirs(u'./'+name1, name1))
657
self._filter_out_stat(result)
658
self.assertEqual(expected_dirblocks[1:], result)
660
def test_unicode__walkdirs_utf8(self):
661
"""Walkdirs_utf8 should always return utf8 paths.
663
The abspath portion might be in unicode or utf-8
665
name0 = u'0file-\xb6'
666
name1 = u'1dir-\u062c\u0648'
667
name2 = u'2file-\u0633'
672
name1 + '/' + name1 + '/',
676
self.build_tree(tree)
678
raise TestSkipped('Could not represent Unicode chars'
679
' in current encoding.')
680
name0 = name0.encode('utf8')
681
name1 = name1.encode('utf8')
682
name2 = name2.encode('utf8')
684
expected_dirblocks = [
686
[(name0, name0, 'file', './' + name0),
687
(name1, name1, 'directory', './' + name1),
688
(name2, name2, 'file', './' + name2),
691
((name1, './' + name1),
692
[(name1 + '/' + name0, name0, 'file', './' + name1
694
(name1 + '/' + name1, name1, 'directory', './' + name1
698
((name1 + '/' + name1, './' + name1 + '/' + name1),
704
# For ease in testing, if walkdirs_utf8 returns Unicode, assert that
705
# all abspaths are Unicode, and encode them back into utf8.
706
for dirdetail, dirblock in osutils._walkdirs_utf8('.'):
707
self.assertIsInstance(dirdetail[0], str)
708
if isinstance(dirdetail[1], unicode):
709
dirdetail[1] = dirdetail[1].encode('utf8')
710
for info in dirblock:
711
self.assertIsInstance(info[4], unicode)
712
info[4] = info[4].encode('utf8')
714
for info in dirblock:
715
self.assertIsInstance(info[0], str)
716
self.assertIsInstance(info[1], str)
717
self.assertIsInstance(info[4], str)
718
# Remove the stat information
719
new_dirblock.append((info[0], info[1], info[2], info[4]))
720
result.append((dirdetail, new_dirblock))
721
self.assertEqual(expected_dirblocks, result)
723
def test_unicode__walkdirs_unicode_to_utf8(self):
724
"""walkdirs_unicode_to_utf8 should be a safe fallback everywhere
726
The abspath portion should be in unicode
728
name0u = u'0file-\xb6'
729
name1u = u'1dir-\u062c\u0648'
730
name2u = u'2file-\u0633'
734
name1u + '/' + name0u,
735
name1u + '/' + name1u + '/',
739
self.build_tree(tree)
741
raise TestSkipped('Could not represent Unicode chars'
742
' in current encoding.')
743
name0 = name0u.encode('utf8')
744
name1 = name1u.encode('utf8')
745
name2 = name2u.encode('utf8')
747
# All of the abspaths should be in unicode, all of the relative paths
749
expected_dirblocks = [
751
[(name0, name0, 'file', './' + name0u),
752
(name1, name1, 'directory', './' + name1u),
753
(name2, name2, 'file', './' + name2u),
756
((name1, './' + name1u),
757
[(name1 + '/' + name0, name0, 'file', './' + name1u
759
(name1 + '/' + name1, name1, 'directory', './' + name1u
763
((name1 + '/' + name1, './' + name1u + '/' + name1u),
768
result = list(osutils._walkdirs_unicode_to_utf8('.'))
769
self._filter_out_stat(result)
770
self.assertEqual(expected_dirblocks, result)
608
772
def assertPathCompare(self, path_less, path_greater):
609
773
"""check that path_less and path_greater compare correctly."""
610
774
self.assertEqual(0, osutils.compare_paths_prefix_order(