def using_root_to_create_temporary_directories_creates_directories_under_root_path( ): with tempman.create_temp_dir() as parent_directory: root = tempman.root(parent_directory.path) with root.create_temp_dir() as directory: assert_equal([os.path.basename(directory.path)], os.listdir(parent_directory.path))
def _files_and_directories_older_than_timeout_are_deleted_when_cleaning_up( one_minute): with tempman.create_temp_dir() as parent_directory: root = tempman.root(parent_directory.path, timeout=one_minute) now = time.time() old_dir = os.path.join(parent_directory.path, "one") os.mkdir(old_dir) os.utime(old_dir, (now - 70, now - 70)) newer_dir = os.path.join(parent_directory.path, "two") os.mkdir(newer_dir) os.utime(newer_dir, (now - 10, now - 10)) old_file = os.path.join(parent_directory.path, 'file_one') with open(old_file, 'a'): os.utime(old_file, (now - 70, now - 70)) new_file = os.path.join(parent_directory.path, 'file_two') with open(new_file, 'a'): os.utime(new_file, (now - 10, now - 10)) temp_file = root.create_temp_file(prefix='prefix') root.cleanup() assert_equal( sorted([temp_file.path.split('/')[-1:][0], "file_two", "two"]), sorted(os.listdir(parent_directory.path)))
def cleanup_occurs_when_creating_directory_under_root(): with tempman.create_temp_dir() as parent_directory: root = tempman.root(parent_directory.path, timeout=60) now = time.time() old_dir = os.path.join(parent_directory.path, "one") os.mkdir(old_dir) os.utime(old_dir, (now - 70, now - 70)) with root.create_temp_dir() as directory: pass assert_equal([], os.listdir(parent_directory.path))
def _directories_older_than_timeout_are_deleted_when_cleaning_up(one_minute): with tempman.create_temp_dir() as parent_directory: root = tempman.root(parent_directory.path, timeout=one_minute) now = time.time() old_dir = os.path.join(parent_directory.path, "one") os.mkdir(old_dir) os.utime(old_dir, (now - 70, now - 70)) newer_dir = os.path.join(parent_directory.path, "two") os.mkdir(newer_dir) os.utime(newer_dir, (now - 10, now - 10)) root.cleanup() assert_equal(["two"], os.listdir(parent_directory.path))
def using_root_to_create_temporary_directories_creates_directories_under_root_path(): with tempman.create_temp_dir() as parent_directory: root = tempman.root(parent_directory.path) with root.create_temp_dir() as directory: assert_equal([os.path.basename(directory.path)], os.listdir(parent_directory.path))
def create_temp_dir(): temp_root = tempman.root( xdg.BaseDirectory.save_data_path("toodlepip/tmp"), timeout=timedelta(days=1) ) return temp_root.create_temp_dir()