def test_copy_if_changed_directory_destination(self): self.fs.CreateFile(os.path.join('tmp', 'foo'), contents='foo') self.fs.CreateFile('foo', contents='bar') copy_if_changed('foo', 'tmp') with open(os.path.join('tmp', 'foo'), 'r') as f: self.assertEqual(f.read(), 'bar')
def test_copy_if_changed(self): file1 = self.fs.CreateFile(os.path.join('file1'), contents='foo') file2 = self.fs.CreateFile(os.path.join('file2'), contents='foo') file3 = self.fs.CreateFile(os.path.join('file3'), contents='bar') file1.st_mtime = 1 file2.st_mtime = 2 file3.st_mtime = 3 copy_if_changed('file2', 'file1') self.assertEqual(os.path.getmtime('file1'), 1) with open('file1', 'r') as f: self.assertEqual(f.read(), 'foo') copy_if_changed('file3', 'file1') self.assertEqual(os.path.getmtime('file1'), 3) with open('file1', 'r') as f: self.assertEqual(f.read(), 'bar')