diff -r 4afe9faeb1f9 Lib/test/test_filecmp.py --- a/Lib/test/test_filecmp.py Sat Jul 26 19:40:31 2014 -0400 +++ b/Lib/test/test_filecmp.py Sat Jul 26 23:50:21 2014 -0400 @@ -3,6 +3,7 @@ import shutil import tempfile import unittest +import time from test import support @@ -19,12 +20,23 @@ with open(self.name_diff, 'a+') as output: output.write('An extra line.\n') + + # Create file of the same length with 'data' in all uppercase + # so size is the same but content is different + self.name_uppercase = support.TESTFN + '-uppercase' + # sleep one second to ensure that they have different creation times + time.sleep(1) + # write uppercase file + with open(self.name_uppercase, 'w+') as output: + output.write(data.upper()) + self.dir = tempfile.gettempdir() def tearDown(self): os.unlink(self.name) os.unlink(self.name_same) os.unlink(self.name_diff) + os.unlink(self.name_uppercase) def test_matching(self): self.assertTrue(filecmp.cmp(self.name, self.name_same), @@ -42,6 +54,21 @@ self.assertFalse(filecmp.cmp(self.name, self.dir), "File and directory compare as equal") + self.assertFalse(filecmp.cmp(self.name, self.name_uppercase), + "Shallow comparison to 'uppercase' is equal") + + self.assertFalse(filecmp.cmp(self.name, self.name_uppercase, shallow=False), + "Non-shallow comparison to 'uppercase' is equal") + + # Set the access time of self.name and self.name_uppercase to be the same + atime = time.time() + os.utime(self.name, (atime,atime)) + os.utime(self.name_uppercase, (atime,atime)) + self.assertTrue(filecmp.cmp(self.name, self.name_uppercase), + "Shallow comparison to 'uppercase' with same atime/mtime is unequal") + self.assertFalse(filecmp.cmp(self.name, self.name_uppercase, shallow=False), + "Non-shallow comparison to 'uppercase' with same atime/mtime is equal") + def test_cache_clear(self): first_compare = filecmp.cmp(self.name, self.name_same, shallow=False) second_compare = filecmp.cmp(self.name, self.name_diff, shallow=False)