diff options
Diffstat (limited to 'Lib/test/test_clinic.py')
-rw-r--r-- | Lib/test/test_clinic.py | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 80b9aec..4aa9691 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -795,17 +795,29 @@ class ClinicExternalTest(TestCase): maxDiff = None def test_external(self): + # bpo-42398: Test that the destination file is left unchanged if the + # content does not change. Moreover, check also that the file + # modification time does not change in this case. source = support.findfile('clinic.test') with open(source, 'r', encoding='utf-8') as f: - original = f.read() - with os_helper.temp_dir() as testdir: - testfile = os.path.join(testdir, 'clinic.test.c') + orig_contents = f.read() + + with os_helper.temp_dir() as tmp_dir: + testfile = os.path.join(tmp_dir, 'clinic.test.c') with open(testfile, 'w', encoding='utf-8') as f: - f.write(original) - clinic.parse_file(testfile, force=True) + f.write(orig_contents) + old_mtime_ns = os.stat(testfile).st_mtime_ns + + clinic.parse_file(testfile) + with open(testfile, 'r', encoding='utf-8') as f: - result = f.read() - self.assertEqual(result, original) + new_contents = f.read() + new_mtime_ns = os.stat(testfile).st_mtime_ns + + self.assertEqual(new_contents, orig_contents) + # Don't change the file modification time + # if the content does not change + self.assertEqual(new_mtime_ns, old_mtime_ns) if __name__ == "__main__": |