def test_get_all_when_file_deleted(self): self.source.start() block_until_synchronised_files_data_source_started(self.source) change_lock = Lock() change_lock.acquire() def on_change(change: FileSystemChange): if change == FileSystemChange.DELETE: change_lock.release() self.source.add_listener(on_change) to_delete_file_path = glob.glob("%s/*" % self.temp_directory)[0] deleted_data = extract_data_from_file(to_delete_file_path, parser=lambda data: int(data), separator='\n') os.remove(to_delete_file_path) change_lock.acquire() self.assertCountEqual(self.source.get_all(), [x for x in self.data if x not in deleted_data])
def test_get_all_when_file_modified(self): self.source.start() block_until_synchronised_files_data_source_started(self.source) change_lock = Lock() change_lock.acquire() def on_change(change: FileSystemChange): if change == FileSystemChange.MODIFY: change_lock.release() self.source.add_listener(on_change) to_modify_file_path = glob.glob("%s/*" % self.temp_directory)[0] to_modify = extract_data_from_file(to_modify_file_path, parser=lambda data: int(data), separator='\n') modified = to_modify[0: -1] with open(to_modify_file_path, 'w') as file: file.write('\n'.join([str(x) for x in modified])) change_lock.acquire() self.assertCountEqual(self.source.get_all(), [x for x in self.data if x not in to_modify] + modified)
def extract_adapter(file_path: str) -> Any: return extract_data_from_file(file_path, parser=lambda data: int(data), separator='\n')