How to use _is_in_task method in avocado

Best Python code snippet using avocado_python

repo.py

Source:repo.py Github

copy

Full Screen

...134 return {key: len(value) for key, value in self._by_result.items()}135 def get_task_status(self, task_id):136 return self._status.get(task_id, (None, None))[0]137 @staticmethod138 def _is_in_task(tasks, task_ids):139 """Returns True if any of the tasks is in task_ids."""140 return any([True for task_id in task_ids if task_id in tasks])141 def get_result_set_for_tasks(self, task_ids):142 """Returns a set of results for the given tasks."""143 results = [144 key145 for key, value in self._by_result.items()146 if self._is_in_task(value, task_ids)147 ]...

Full Screen

Full Screen

DataSerializerPackage.py

Source:DataSerializerPackage.py Github

copy

Full Screen

1import json2import lzma3import os4import threading5import SPMUtil as spmu6class DataSerializerPackage:7 def __init__(self, path, custom_ext=".xzp"):8 self.path = path9 self._ext = custom_ext10 self.dataSerializers = {}11 self.JsonEncoder = spmu.NdarrayEncoder12 self.JsonDecoder = spmu.NdarrayDecoder13 self._is_in_task = False14 @property15 def datas_name_list(self) -> list:16 return list(self.dataSerializers.keys())17 def get_dataSerializer(self, key) -> spmu.DataSerializer:18 if type(key) == bytes:19 key = key.decode()20 if key in self.dataSerializers:21 return self.dataSerializers[key]22 else:23 raise ValueError("Wrong key: " + key)24 def add_data_serializer(self, data_serializer:spmu.DataSerializer, overwrite=False, save=False):25 fileName = os.path.basename(data_serializer.path).split('.')[0]26 if fileName in self.dataSerializers:27 if overwrite:28 self.dataSerializers.pop(fileName)29 self.dataSerializers[fileName] = data_serializer30 else:31 self.dataSerializers[fileName] = data_serializer32 if save:33 self.save()34 def remove_data_serializer(self, data_serializer:spmu.DataSerializer, save=False):35 fileName = os.path.basename(data_serializer.path).split('.')[0]36 if fileName in self.dataSerializers:37 self.dataSerializers.pop(fileName)38 if save:39 self.save()40 def save(self, enable_multi_thread=False):41 if self._is_in_task:42 print("Save Command disposed: this class is running another task")43 if enable_multi_thread:44 self._is_in_task = True45 thread = threading.Thread(target=self._save_task(), args=())46 thread.start()47 else:48 self._save_task()49 def save_from_folder(self, folder_path, file_ext=".pkl", enable_multi_thread=False):50 files = [file for file in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, file))]51 for fileName in files:52 extension = os.path.splitext(fileName)[1]53 if extension == file_ext:54 dataSerializer = spmu.DataSerializer(os.path.join(folder_path, fileName))55 dataSerializer.load()56 self.add_data_serializer(dataSerializer)57 self.save(enable_multi_thread)58 def extract_to_folder(self, folder_path):59 for key in self.dataSerializers.keys():60 self.dataSerializers[key].path = os.path.join(folder_path, self.dataSerializers[key].path)61 self.dataSerializers[key].save()62 def load(self, enable_multi_thread=False):63 if self._is_in_task:64 print("Load Command disposed: this class is running another task")65 if enable_multi_thread:66 self._is_in_task = True67 thread = threading.Thread(target=self._load_task(), args=())68 thread.start()69 else:70 self._load_task()71 def _save_task(self):72 print("DataSerializerPacgkage: save begin...(it will take a lot of time)")73 data_dict = {}74 for it in self.dataSerializers.keys():75 data_dict[it] = self.dataSerializers[it].data_dict76 bytes_data = json.dumps(data_dict, indent=2, cls=self.JsonEncoder).encode('utf-8')77 filename, file_extension = os.path.splitext(self.path)78 with lzma.open(filename + self._ext, "wb") as f:79 f.write(lzma.compress(bytes_data))80 f.flush()81 print("save to", filename + self._ext)82 self._is_in_task = False83 def _load_task(self):84 filename, file_extension = os.path.splitext(self.path)85 if file_extension != self._ext:86 filename = self.path87 with lzma.open(filename + self._ext, 'rb') as f:88 print("DataSerializerPacgkage: load begin...")89 datas = json.loads(lzma.decompress(f.read()), cls=self.JsonDecoder)90 for it in datas.keys():91 dataSerializer = spmu.DataSerializer(path=it)92 dataSerializer.data_dict = datas[it]93 self.add_data_serializer(dataSerializer, overwrite=True)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful