/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: Martin
  • Date: 2010-01-06 19:59:02 UTC
  • mto: (4934.1.9 2.1.0rc1-set-mtime)
  • mto: This revision was merged to the branch mainline in revision 4940.
  • Revision ID: gzlist@googlemail.com-20100106195902-vi1ckfsu2wurtt8v
Rearrange osutils.fset_mtime tests a little and make them robust on FAT filesystems

Show diffs side-by-side

added added

removed removed

Lines of Context:
2008
2008
 
2009
2009
class TestFSetMtime(tests.TestCaseInTempDir):
2010
2010
 
2011
 
    def test__utime_fset_mtime(self):
 
2011
    def _check_fset_mtime(self, func):
2012
2012
        f = open('test', 'wb')
2013
2013
        try:
2014
2014
            mtime = os.fstat(f.fileno()).st_mtime
2015
2015
            new_mtime = mtime - 20
2016
 
            osutils._utime_fset_mtime(f, new_mtime)
2017
 
        finally:
2018
 
            f.close()
2019
 
        self.assertEqual(int(new_mtime), int(os.lstat('test').st_mtime))
2020
 
 
2021
 
    def test_fset_mtime(self):
2022
 
        f = open('test', 'wb')
2023
 
        new_mtime = time.time()-20.0
2024
 
        try:
2025
 
            mtime = os.fstat(f.fileno()).st_mtime
2026
 
            osutils.fset_mtime(f, new_mtime)
 
2016
            func(f, new_mtime)
2027
2017
        finally:
2028
2018
            f.close()
2029
2019
        self.assertNotEqual(mtime, new_mtime)
2030
 
        # We don't guarantee any better than 1s resolution, though we try to
 
2020
        set_mtime = os.lstat('test').st_mtime
 
2021
        # We don't guarantee any better than 2s resolution, due to timestamp
 
2022
        # precision limitations on older filesystems such as FAT, but try to
2031
2023
        # use functions that have at least microsecond resolution (1us on
2032
2024
        # POSIX, 100ns on Windows)
2033
 
        self.assertEqual(int(new_mtime), int(os.lstat('test').st_mtime))
 
2025
        self.assertFalse(int((new_mtime - set_mtime) / 2),
 
2026
            "%r != %r within two seconds" % (new_mtime, set_mtime))
 
2027
 
 
2028
    def test_fset_mtime(self):
 
2029
        self._check_fset_mtime(osutils.fset_mtime)
 
2030
        if osutils.fset_mtime is not osutils._utime_fset_mtime:
 
2031
            self._check_fset_mtime(osutils._utime_fset_mtime)