def exercise_file_utils(): dir_name = "tmp_files_%d" % os.getpid() if (not os.path.exists(dir_name)): os.mkdir(dir_name) sorted_files = [] for prefix in ["XYZ", "abc", "qwerty", "123"]: file_name = os.path.join(dir_name, "%s.txt" % prefix) open(file_name, "w").write(prefix) sorted_files.append(file_name) time.sleep(1) # XXX the mtime resolution is in seconds :( f = open(os.path.join(dir_name, "hkl.log"), "w") f.write("hkl") f.close() file_names = utils.find_files(dir_name, pattern=".txt$") sorted_files_2 = utils.sort_files_by_mtime(file_names) assert (sorted_files_2 == sorted_files)
def exercise_file_utils () : dir_name = tempfile.mkdtemp() if (not os.path.exists(dir_name)) : os.mkdir(dir_name) sorted_files = [] for prefix in ["XYZ", "abc", "qwerty", "123"] : file_name = os.path.join(dir_name, "%s.txt" % prefix) open(file_name, "w").write(prefix) sorted_files.append(file_name) time.sleep(1) # XXX the mtime resolution is in seconds :( f = open(os.path.join(dir_name, "hkl.log"), "w") f.write("hkl") f.close() file_names = utils.find_files(dir_name, pattern=".txt$") sorted_files_2 = utils.sort_files_by_mtime(file_names) assert (sorted_files_2 == sorted_files)
def exercise_file_utils(): dir_name = tempfile.mkdtemp() if (not os.path.exists(dir_name)): os.mkdir(dir_name) sorted_files = [] for prefix in ["XYZ", "abc", "qwerty", "123"] : file_name = os.path.join(dir_name, "%s.txt" % prefix) with open(file_name, "w") as f: f.write(prefix) sorted_files.append(file_name) time.sleep(1) # XXX the mtime resolution is in seconds :( f = open(os.path.join(dir_name, "hkl.log"), "w") f.write("hkl") f.close() file_names = utils.find_files(dir_name, pattern=".txt$") sorted_files_2 = utils.sort_files_by_mtime(file_names) assert (sorted_files_2 == sorted_files), ''' Files not in correct order: %s %s ''' % (sorted_files_2, sorted_files)