From 9d9f13a4403d3e74655fb6ba2ae8964adcac313b Mon Sep 17 00:00:00 2001 From: Nikolaus Schulz Date: Mon, 29 Sep 2008 03:05:57 +0200 Subject: test suite: account for lacking precision of os.utime() os.utime() uses the utimes(2) system call to set file timestamps. utimes(2) has a microsecond resolution, but stat(2) may return timestamps with nanosecond resolution. So, the check that we have properly reset the mbox file timestamp must allow a minor deviation. --- test_archivemail.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test_archivemail.py b/test_archivemail.py index 8cbf152..01f2c01 100755 --- a/test_archivemail.py +++ b/test_archivemail.py @@ -69,6 +69,9 @@ except ImportError: print "Try renaming it from 'archivemail' to 'archivemail.py'." sys.exit(1) +# precision of os.utime() when restoring mbox timestamps +utimes_precision = 5 + class TestCaseInTempdir(unittest.TestCase): """Base class for testcases that need to create temporary files. @@ -642,8 +645,8 @@ class TestArchiveMboxTimestamp(TestCaseInTempdir): assert(os.path.exists(self.mbox_name)) new_atime = os.path.getatime(self.mbox_name) new_mtime = os.path.getmtime(self.mbox_name) - self.assertEqual(self.mtime, new_mtime) - self.assertEqual(self.atime, new_atime) + self.assertAlmostEqual(self.mtime, new_mtime, utimes_precision) + self.assertAlmostEqual(self.atime, new_atime, utimes_precision) def testMixed(self): """mbox timestamps should not change after semi-archival""" @@ -663,8 +666,8 @@ class TestArchiveMboxTimestamp(TestCaseInTempdir): assert(os.path.exists(self.mbox_name)) new_atime = os.path.getatime(self.mbox_name) new_mtime = os.path.getmtime(self.mbox_name) - self.assertEqual(self.mtime, new_mtime) - self.assertEqual(self.atime, new_atime) + self.assertAlmostEqual(self.mtime, new_mtime, utimes_precision) + self.assertAlmostEqual(self.atime, new_atime, utimes_precision) def testOld(self): """mbox timestamps should not change after archival""" @@ -684,8 +687,8 @@ class TestArchiveMboxTimestamp(TestCaseInTempdir): assert(os.path.exists(self.mbox_name)) new_atime = os.path.getatime(self.mbox_name) new_mtime = os.path.getmtime(self.mbox_name) - self.assertEqual(self.mtime, new_mtime) - self.assertEqual(self.atime, new_atime) + self.assertAlmostEqual(self.mtime, new_mtime, utimes_precision) + self.assertAlmostEqual(self.atime, new_atime, utimes_precision) def tearDown(self): archivemail.options.quiet = 0 -- cgit v1.2.3