Best Python code snippet using avocado_python
gallery.py
Source:gallery.py
...131 return self._content_type132 @content_type.setter133 def content_type(self, value):134 self._content_type = value135 def enable_paginator(self, val):136 self.btn_check_all.setEnabled(val)137 self.btn_uncheck_all.setEnabled(val)138 self.btn_next_page.setEnabled(val)139 self.btn_prev_page.setEnabled(val)140 self.btn_last_page.setEnabled(val)141 self.btn_first_page.setEnabled(val)142 def setup_paginator(self):143 self.grid_actions_layout.addWidget(self.btn_check_all)144 self.grid_actions_layout.addWidget(self.btn_uncheck_all)145 self.btn_next_page.clicked.connect(self.btn_next_page_on_click)146 self.btn_prev_page.clicked.connect(self.btn_prev_page_on_click)147 self.btn_last_page.clicked.connect(self.btn_last_page_on_click)148 self.btn_first_page.clicked.connect(self.btn_first_page_on_click)149 self.btn_first_page.setIcon(GUIUtilities.get_icon("first.png"))150 self.btn_prev_page.setIcon(GUIUtilities.get_icon("left.png"))151 self.btn_next_page.setIcon(GUIUtilities.get_icon("right.png"))152 self.btn_last_page.setIcon(GUIUtilities.get_icon("last.png"))153 self.btn_first_page.setStyleSheet('QPushButton{border: 0px solid;}')154 self.btn_prev_page.setStyleSheet('QPushButton{border: 0px solid;}')155 self.btn_last_page.setStyleSheet('QPushButton{border: 0px solid;}')156 self.btn_next_page.setStyleSheet('QPushButton{border: 0px solid;}')157 self.grid_actions_layout.setAlignment(QtCore.Qt.AlignCenter)158 @property159 def tag(self):160 return self._tag161 @tag.setter162 def tag(self, value):163 self._tag = value164 @property165 def items(self):166 return self._items167 @items.setter168 def items(self, value):169 self._items = value170 @property171 def page_size(self):172 return self._page_size173 @page_size.setter174 def page_size(self, value):175 self._page_size = value176 self.update_pager()177 @property178 def current_page(self):179 return self._curr_page + 1180 @current_page.setter181 def current_page(self, val):182 self._curr_page = val183 self._curr_page = self._curr_page % self.total_pages184 self.lbl_current_page.setText(str(self.current_page))185 self.bind()186 @property187 def total_pages(self):188 return len(self._pages)189 def update_pager(self):190 self._pages = list(MiscUtilities.chunk(self._items, self._page_size))191 self.lbl_total_pages.setText("{}".format(len(self._pages)))192 self.lbl_current_page.setText(str(self.current_page))193 def btn_next_page_on_click(self):194 if len(self._pages) == 0:195 return196 self._curr_page += 1197 self.current_page = self._curr_page198 def btn_last_page_on_click(self):199 if len(self._pages) == 0:200 return201 self.current_page = len(self._pages) - 1202 def btn_first_page_on_click(self):203 if len(self._pages) == 0:204 return205 self.current_page = 0206 def btn_prev_page_on_click(self):207 if len(self._pages) == 0:208 return209 self._curr_page -= 1210 self.current_page = self._curr_page211 def dragEnterEvent(self, event: QtGui.QDragEnterEvent) -> None:212 data = event.mimeData()213 if data.hasUrls():214 if any(url.isLocalFile() for url in data.urls()):215 event.accept()216 return217 else:218 event.ignore()219 def dragMoveEvent(self, event: QtGui.QDragMoveEvent) -> None:220 if event.mimeData().hasUrls:221 event.setDropAction(QtCore.Qt.CopyAction)222 event.accept()223 return224 else:225 event.ignore()226 def dropEvent(self, event: QtGui.QDropEvent) -> None:227 valid_files = []228 files = [u.toLocalFile() for u in event.mimeData().urls()]229 for f in files:230 if os.path.isfile(f):231 mime_type, encoding = mimetypes.guess_type(f) # magic.from_file(f,mime=True)232 if mime_type.find("video") != -1 and self.content_type == "Videos":233 valid_files.append(f)234 elif mime_type.find("image") != -1 and self.content_type == "Images":235 valid_files.append(f)236 valid_files = sorted(valid_files, key=lambda v: os.path.basename(v))237 self.filesDropped.emit(valid_files)238 def load_images(self):239 def do_work():240 page = self._curr_page241 items = self._pages[page]242 def create_thumbnail(item):243 file_path = item.file_path244 if os.path.isfile(file_path):245 image = cv2.imread(file_path)246 h, w, _ = np.shape(image)247 if w > h:248 thumbnail_array = imutils.resize(image, width=150)249 else:250 thumbnail_array = imutils.resize(image, height=150)251 thumbnail_array = cv2.cvtColor(thumbnail_array, cv2.COLOR_BGR2RGB)252 thumbnail = GUIUtilities.array_to_qimage(thumbnail_array)253 thumbnail = QPixmap.fromImage(thumbnail)254 del thumbnail_array255 del image256 return item, h, w, thumbnail, os.path.getsize(file_path), False257 thumbnail = GUIUtilities.get_image("placeholder.png")258 thumbnail = thumbnail.scaledToHeight(100)259 h, w = thumbnail.height(), thumbnail.width()260 return item, h, w, thumbnail, 0, True261 delayed_tasks = [dask.delayed(create_thumbnail)(item) for item in items]262 images = dask.compute(*delayed_tasks)263 return images264 def done_work(images):265 for img in images:266 if img:267 item, h, w, thumbnail, file_size, is_broken = img268 image_card = ImageCard()269 image_card.is_broken = is_broken270 image_card.tag = item271 image_card.source = thumbnail272 image_card.file_path = item.file_path273 image_size_str = size(file_size, system=alternative) if file_size > 0 else "0 MB"274 image_card.label.setText("\n ({0}px / {1}px) \n {2}".format(w, h, image_size_str))275 image_card.setFixedHeight(240)276 image_card.doubleClicked.connect(self.gallery_card_double_click)277 image_card.add_buttons(self.actions)278 if self.actions:279 image_card.actionClicked.connect(lambda name, item: self.cardActionClicked.emit(name, item))280 self.center_layout.add_item(image_card)281 def finished_work():282 self._loading_dialog.close()283 self.enable_paginator(True)284 worker = Worker(do_work)285 worker.signals.result.connect(done_work)286 worker.signals.finished.connect(finished_work)287 self._thread_pool.start(worker)288 self.enable_paginator(False)289 self._loading_dialog.show()290 def bind(self):291 self.update_pager()292 if len(self._pages) > 0:293 self.center_widget = QWidget()294 self.center_layout = GalleryLayout()295 self.center_widget.setLayout(self.center_layout)296 self.center_layout.setAlignment(QtCore.Qt.AlignTop)297 self.scrollArea.setWidget(self.center_widget)298 self.center_layout.initialize(n_items=self.page_size)299 if self.content_type == "Images":300 self.load_images()301 else:302 raise NotImplementedError...
test_output.py
Source:test_output.py
...15 std = output.StdOutput()16 with unittest.mock.patch('avocado.utils.path.find_command',17 side_effect=utils_path.CmdNotFoundError('just',18 ['mocking'])):19 std.enable_paginator()20 self.assertEqual(self.stdout, sys.stdout)21 self.assertEqual(self.stderr, sys.stderr)22if __name__ == '__main__':...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!