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

  • Committer: Vincent Ladeuil
  • Date: 2009-04-16 16:57:28 UTC
  • mto: (4331.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4332.
  • Revision ID: v.ladeuil+lp@free.fr-20090416165728-lnobbei6iew38g2d
Test and implements osutils.readlink().

* bzrlib/tests/test_osutils.py:
(TestDirReader.test_symlink): Fix typo.
(TestReadLink): Explain the need for osutils.readlink().

* bzrlib/osutils.py:
(readlink): Reliable version handling unicode paths only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1707
1707
 
1708
1708
    def test_symlink(self):
1709
1709
        self.requireFeature(tests.SymlinkFeature)
1710
 
        target = u'target\n{Euro Sign}'
1711
 
        link_name = u'l\n{Euro Sign}nk'
 
1710
        target = u'target\N{Euro Sign}'
 
1711
        link_name = u'l\N{Euro Sign}nk'
1712
1712
        os.symlink(target, link_name)
1713
1713
        target_utf8 = target.encode('UTF-8')
1714
1714
        link_name_utf8 = link_name.encode('UTF-8')
1719
1719
                 )]
1720
1720
        result = list(osutils._walkdirs_utf8('.'))
1721
1721
        self.assertEqual(expected_dirblocks, self._filter_out(result))
 
1722
 
 
1723
 
 
1724
class TestReadLink(tests.TestCaseInTempDir):
 
1725
    """Exposes os.readlink() problems and the osutils solution.
 
1726
 
 
1727
    The only guarantee offered by os.readlink(), starting with 2.6, is that a
 
1728
    unicode string will be returned if a unicode string is passed.
 
1729
 
 
1730
    But prior python versions failed to properly encode a the passed unicode
 
1731
    string.
 
1732
    """
 
1733
 
 
1734
    def setUp(self):
 
1735
        super(tests.TestCaseInTempDir, self).setUp()
 
1736
        self.link = u'l\N{Euro Sign}ink'
 
1737
        self.target = u'targe\N{Euro Sign}t'
 
1738
        os.symlink(self.target, self.link)
 
1739
 
 
1740
    def test_os_readlink_link_encoding(self):
 
1741
        if sys.version_info < (2, 6):
 
1742
            self.assertRaises(UnicodeEncodeError, os.readlink, self.link)
 
1743
        else:
 
1744
            self.assertEquals(self.target,  os.readlink(self.link))
 
1745
 
 
1746
    def test_os_readlink_link_decoding(self):
 
1747
        self.assertEquals(self.target.encode(osutils._fs_enc),
 
1748
                          os.readlink(self.link.encode(osutils._fs_enc)))