~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Aaron Bentley
  • Date: 2010-05-10 11:34:20 UTC
  • mfrom: (5218 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5221.
  • Revision ID: aaron@aaronbentley.com-20100510113420-toh2d5yioobb5uq1
Merged bzr.dev into transform-commit-full.

Show diffs side-by-side

added added

removed removed

Lines of Context:
184
184
        shape = sorted(os.listdir('.'))
185
185
        self.assertEquals(['A', 'B'], shape)
186
186
 
 
187
    def test_rename_error(self):
 
188
        # We wrap os.rename to make it give an error including the filenames
 
189
        # https://bugs.launchpad.net/bzr/+bug/491763
 
190
        err = self.assertRaises(OSError, osutils.rename,
 
191
            'nonexistent', 'target')
 
192
        self.assertContainsString(str(err), 'nonexistent')
 
193
 
187
194
 
188
195
class TestRandChars(tests.TestCase):
189
196
 
1990
1997
    def _dummy_chown(self, path, uid, gid):
1991
1998
        self.path, self.uid, self.gid = path, uid, gid
1992
1999
 
1993
 
    def test_mkdir_with_ownership_chown(self):
1994
 
        """Ensure that osutils.mkdir_with_ownership chowns correctly with ownership_src.
1995
 
        """
1996
 
        ownsrc = '/'
1997
 
        osutils.mkdir_with_ownership('foo', ownsrc)
1998
 
 
1999
 
        s = os.stat(ownsrc)
2000
 
        self.assertEquals(self.path, 'foo')
2001
 
        self.assertEquals(self.uid, s.st_uid)
2002
 
        self.assertEquals(self.gid, s.st_gid)
2003
 
 
2004
 
    def test_open_with_ownership_chown(self):
2005
 
        """Ensure that osutils.open_with_ownership chowns correctly with ownership_src.
2006
 
        """
2007
 
        ownsrc = '/'
2008
 
        f = osutils.open_with_ownership('foo', 'w', ownership_src=ownsrc)
2009
 
 
2010
 
        # do a test write and close
2011
 
        f.write('hello')
2012
 
        f.close()
2013
 
 
2014
 
        s = os.stat(ownsrc)
2015
 
        self.assertEquals(self.path, 'foo')
2016
 
        self.assertEquals(self.uid, s.st_uid)
2017
 
        self.assertEquals(self.gid, s.st_gid)
2018
 
 
 
2000
    def test_copy_ownership_from_path(self):
 
2001
        """copy_ownership_from_path test with specified src."""
 
2002
        ownsrc = '/'
 
2003
        f = open('test_file', 'wt')
 
2004
        osutils.copy_ownership_from_path('test_file', ownsrc)
 
2005
 
 
2006
        s = os.stat(ownsrc)
 
2007
        self.assertEquals(self.path, 'test_file')
 
2008
        self.assertEquals(self.uid, s.st_uid)
 
2009
        self.assertEquals(self.gid, s.st_gid)
 
2010
 
 
2011
    def test_copy_ownership_nonesrc(self):
 
2012
        """copy_ownership_from_path test with src=None."""
 
2013
        f = open('test_file', 'wt')
 
2014
        # should use parent dir for permissions
 
2015
        osutils.copy_ownership_from_path('test_file')
 
2016
 
 
2017
        s = os.stat('..')
 
2018
        self.assertEquals(self.path, 'test_file')
 
2019
        self.assertEquals(self.uid, s.st_uid)
 
2020
        self.assertEquals(self.gid, s.st_gid)
 
2021
 
 
2022
class TestGetuserUnicode(tests.TestCase):
 
2023
 
 
2024
    def test_ascii_user(self):
 
2025
        osutils.set_or_unset_env('LOGNAME', 'jrandom')
 
2026
        self.assertEqual(u'jrandom', osutils.getuser_unicode())
 
2027
 
 
2028
    def test_unicode_user(self):
 
2029
        ue = osutils.get_user_encoding()
 
2030
        osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
 
2031
        self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())