Best Python code snippet using grail_python
shot_review.py
Source:shot_review.py
1# -*- coding: utf-8 -*-2import os3import subprocess4from Qt.QtWidgets import *5from Qt.QtCore import *6from Qt.QtGui import *7import pipeGlobal8from miraLibs.pipeLibs import pipeFile9reload(pipeFile)10from miraLibs.dbLibs import db_api11class ListWidget(QListWidget):12 def __init__(self, removable=False, parent=None):13 super(ListWidget, self).__init__(parent)14 self.removable = removable15 self.setFocusPolicy(Qt.NoFocus)16 self.setSortingEnabled(True)17 self.setSelectionMode(QAbstractItemView.ExtendedSelection)18 self.init()19 def init(self):20 if self.removable:21 self.setContextMenuPolicy(Qt.CustomContextMenu)22 self.customContextMenuRequested.connect(self.show_step_menu)23 def show_step_menu(self, pos):24 global_pos = self.mapToGlobal(pos)25 menu = QMenu(self)26 remove_action = QAction("Remove", self)27 remove_action.triggered.connect(self.remove_selection)28 remove_all_action = QAction("Remove All", self)29 remove_all_action.triggered.connect(self.remove_all)30 menu.addAction(remove_action)31 menu.addAction(remove_all_action)32 menu.exec_(global_pos)33 def remove_selection(self):34 selected_items = self.selectedItems()35 if not selected_items:36 return37 for item in selected_items:38 self.takeItem(self.row(item))39 def remove_all(self):40 self.clear()41 def mousePressEvent(self, event):42 point = event.pos()43 item = self.itemAt(point)44 if not item:45 self.clearSelection()46 super(ListWidget, self).mousePressEvent(event)47class MyGroup(QGroupBox):48 def __init__(self, label_name=None, check_name=None, parent=None):49 super(MyGroup, self).__init__(parent)50 self.label_name = label_name51 self.check_name = check_name52 main_layout = QVBoxLayout(self)53 main_layout.setSpacing(5)54 main_layout.setContentsMargins(0, 0, 0, 0)55 name_label = QLabel()56 name_label.setText('<b>%s</b>' % self.label_name)57 name_label.setAlignment(Qt.AlignCenter)58 self.check_box = QCheckBox(self.check_name)59 self.list_widget = ListWidget(False, self)60 main_layout.addWidget(name_label)61 main_layout.addWidget(self.check_box)62 main_layout.addWidget(self.list_widget)63 self.check_box.stateChanged.connect(self.on_check_state_changed)64 def on_check_state_changed(self):65 if self.check_box.isChecked():66 self.list_widget.setEnabled(False)67 else:68 self.list_widget.setEnabled(True)69 self.list_widget.clearSelection()70class ShotReview(QDialog):71 def __init__(self, parent=None):72 super(ShotReview, self).__init__(parent)73 self.resize(800, 730)74 self.setWindowTitle("Shot Review")75 self.setWindowFlags(Qt.Window)76 self.__projects = pipeGlobal.projects77 self.current_project = pipeGlobal.current_project78 self.__db = db_api.DbApi(self.current_project).db_obj79 self.__shot_step = pipeGlobal.Project(self.current_project).shot_steps80 self.play_list = list()81 main_layout = QVBoxLayout(self)82 main_layout.setContentsMargins(0, 0, 0, 0)83 project_layout = QHBoxLayout()84 project_label = QLabel("Project")85 self.project_cbox = QComboBox()86 project_layout.addWidget(project_label)87 project_layout.addWidget(self.project_cbox)88 project_layout.setStretchFactor(project_label, 0)89 project_layout.setStretchFactor(self.project_cbox, 1)90 list_layout = QHBoxLayout()91 self.sequence_group = MyGroup("sequence", "All Sequences", self)92 self.sequence_group.check_box.setEnabled(False)93 self.sequence_group.list_widget.setSelectionMode(QListWidget.SingleSelection)94 self.shot_group = MyGroup("shot", "All Shots", self)95 self.step_group = MyGroup("step", "Latest", self)96 self.step_group.list_widget.setSelectionMode(QListWidget.SingleSelection)97 list_layout.addWidget(self.sequence_group)98 list_layout.addWidget(self.shot_group)99 list_layout.addWidget(self.step_group)100 btn_layout = QHBoxLayout()101 self.add_to_playlist_btn = QPushButton("Add to playlist")102 btn_layout.addStretch()103 btn_layout.addWidget(self.add_to_playlist_btn)104 self.play_list = ListWidget(True, self)105 play_layout = QHBoxLayout()106 self.play_btn = QPushButton("Play")107 play_layout.addStretch()108 play_layout.addWidget(self.play_btn)109 main_layout.addLayout(project_layout)110 main_layout.addLayout(list_layout)111 main_layout.addLayout(btn_layout)112 main_layout.addWidget(self.play_list)113 main_layout.addLayout(play_layout)114 self.init_project()115 self.init_sequence()116 self.set_signals()117 self.set_style()118 def set_style(self):119 qss_path = os.path.abspath(os.path.join(__file__, "..", "style.qss"))120 qss_path = qss_path.replace("\\", "/")121 self.setStyle(QStyleFactory.create('plastique'))122 self.setStyleSheet(open(qss_path, 'r').read())123 def init_project(self):124 self.project_cbox.addItems(self.__projects)125 self.project_cbox.setCurrentIndex(self.project_cbox.findText(self.current_project))126 def init_sequence(self):127 sequences = self.__db.get_sequence()128 self.sequence_group.list_widget.clear()129 self.sequence_group.list_widget.addItems(sequences)130 def set_signals(self):131 self.project_cbox.currentIndexChanged.connect(self.change_project)132 self.sequence_group.list_widget.itemClicked.connect(self.on_sequence_clicked)133 self.shot_group.list_widget.itemClicked.connect(self.on_shot_clicked)134 self.shot_group.check_box.stateChanged.connect(self.on_shot_clicked)135 self.add_to_playlist_btn.clicked.connect(self.add_to_playlist)136 self.play_btn.clicked.connect(self.play)137 def change_project(self, index):138 self.current_project = self.__projects[index]139 self.__db = db_api.DbApi(self.current_project).db_obj140 self.init_sequence()141 self.shot_group.list_widget.clear()142 self.shot_group.check_box.setChecked(False)143 def on_sequence_clicked(self, item):144 self.step_group.check_box.setChecked(False)145 self.step_group.check_box.setEnabled(False)146 self.step_group.list_widget.clear()147 self.shot_group.check_box.setChecked(False)148 self.shot_group.list_widget.clear()149 shots = self.__db.get_all_shots(item.text())150 if shots:151 shot_names = [shot["code"] for shot in shots]152 self.shot_group.list_widget.addItems(shot_names)153 def on_shot_clicked(self):154 self.step_group.check_box.setEnabled(True)155 self.step_group.list_widget.clear()156 self.step_group.list_widget.addItems(self.__shot_step)157 def get_selected_in_group(self, custom_group):158 if custom_group.check_box.isChecked():159 if custom_group is self.step_group:160 return ["newest"]161 items = [custom_group.list_widget.item(i) for i in xrange(custom_group.list_widget.count())]162 else:163 items = custom_group.list_widget.selectedItems()164 if not items:165 return166 items = [str(item.text()) for item in items]167 items.sort()168 return items169 def parse_selected(self):170 play_list = list()171 project = str(self.project_cbox.currentText())172 sequence = self.get_selected_in_group(self.sequence_group)173 shots = self.get_selected_in_group(self.shot_group)174 step_list = self.get_selected_in_group(self.step_group)175 if not all((sequence, shots, step_list)):176 return177 for seq in sequence:178 for shot in shots:179 if step_list == ["newest"]:180 step_list = ["Comp", "CompLay", "Lgt", "LgtLay", "Sim", "Anim", "AnimLay"]181 for step in step_list:182 video = pipeFile.get_task_video_file(project, "Shot", seq, shot, step, step)183 if video and os.path.isfile(video):184 play_list.append(video)185 break186 return play_list187 def add_to_playlist(self):188 play_list = self.parse_selected()189 if not play_list:190 return191 all_items = [self.play_list.item(i).text() for i in xrange(self.play_list.count())]192 play_list = [i for i in play_list if i not in all_items]193 self.play_list.addItems(play_list)194 def play(self):195 items = [self.play_list.item(i) for i in xrange(self.play_list.count())]196 if not items:197 return198 play_list = [str(item.text()) for item in items]199 cmd_str = "rv %s" % " ".join(play_list)200 subprocess.Popen(cmd_str, shell=True)201if __name__ == "__main__":202 import sys203 app = QApplication(sys.argv)204 sr = ShotReview()205 sr.show()...
steps.py
Source:steps.py
1import sys2import traceback3from unittest import TestCase4import grail.settings as settings5import grail.state as state6from grail.step_info import StepInfo, StepResults7def _generate_step_stack():8 stack = traceback.extract_stack()9 step_index = next(i for i, e in enumerate(stack) if e[0].endswith('steps.py'))10 stack = stack[step_index - 1:]11 stack = filter(lambda e: not (e[0].endswith('steps.py') or e[0].endswith('step_info.py')), stack)12 return stack13class _RedirectOut(object):14 def __init__(self):15 self.temp = sys.stdout16 self.step_messages = []17 self.delimited_messages = []18 self.string = ''19 def write(self, s):20 if s.strip(' '):21 self.delimited_messages.append(s)22 if not s.strip('\n'):23 self.string = ''.join(self.delimited_messages)24 self.delimited_messages = []25 self.step_messages.append(self.string)26 def flush(self):27 pass28 def out_to_lst(self):29 sys.stdout = self30 def out_to_console(self):31 sys.stdout = self.temp32 def get_captured_output(self):33 def convert(line):34 final_line = state.indentation + line35 if isinstance(final_line, unicode):36 return final_line37 return unicode(final_line, errors='replace')38 return ''.join(map(convert, self.step_messages))39def _should_skip_step():40 if settings.disable_steps:41 return True42 if settings.export_mode:43 return False44 for filename, line_number, func_name, text in traceback.extract_stack():45 if func_name in settings.skip_func:46 return True47 if state.treat_nested_steps_as_methods_global and state.step_execution_started:48 return True49class GrailValidationException(Exception):50 pass51def _validate_step_info(step_info):52 if step_info.step_group and step_info.treat_nested_steps_as_methods:53 raise GrailValidationException('Step logic disabling is not applicable for step groups')54 if not step_info.step_group and state.step_execution_started:55 raise GrailValidationException('Step is called from another step (without group): %s' %56 step_info.function.func_name)57def _execute(step_info):58 if _should_skip_step():59 return step_info.run_function()60 redirected_out = _RedirectOut()61 redirected_out.out_to_lst()62 state.indentation = state.indentation + settings.indentation_const63 _validate_step_info(step_info)64 output, result, exception_instance = None, None, None65 def print_to_console():66 redirected_out.out_to_console()67 state.step_execution_started = False68 console_message = redirected_out.get_captured_output()69 state.indentation = state.indentation[:-len(settings.indentation_const)]70 print_message = step_info.get_description(output, result, exception_instance)71 if console_message:72 print_message += '\n'73 print_message += console_message.rstrip()74 print75 print_message76 try:77 if state.pending_step or state.step_first_error is not None:78 result = StepResults.IGNORED79 elif step_info.pending:80 result = StepResults.PENDING81 state.pending_step = True82 else:83 if step_info.step_group:84 output = step_info.run_function()85 if state.step_first_error:86 if isinstance(state.step_first_error, TestCase.failureException):87 result = StepResults.FAILED88 else:89 result = StepResults.ERROR90 elif state.pending_step:91 result = StepResults.PENDING92 else:93 result = StepResults.PASSED94 else:95 state.step_execution_started = True96 state.treat_nested_steps_as_methods_global = step_info.treat_nested_steps_as_methods97 if not settings.export_mode:98 output = step_info.run_function()99 result = StepResults.PASSED100 except Exception as inst:101 if isinstance(inst, TestCase.failureException):102 result = StepResults.FAILED103 else:104 result = StepResults.ERROR105 if not state.is_test_wrapped:106 print_to_console()107 raise108 if step_info.step_group:109 raise GrailValidationException('Unexpected exception from step group: %s' % inst)110 if isinstance(inst, GrailValidationException):111 raise112 if not state.step_first_error:113 state.step_first_error = inst114 state.step_stack = _generate_step_stack()115 state.step_exception_traceback = sys.exc_info()[2]116 exception_instance = inst117 print_to_console()118 return output119def step(func=None, description='', pending=False, step_group=False, format_description=False,120 treat_nested_steps_as_methods=False, log_output=True, log_input=True):121 step_info = StepInfo()122 def wrapper(*args, **kwargs):123 step_info.args = args124 step_info.kwargs = kwargs125 return _execute(step_info)126 def params_wrapper(function):127 step_info.function = function128 return wrapper129 if func is None:130 step_info.description = description131 step_info.pending = pending132 step_info.step_group = step_group133 step_info.format_description = format_description134 step_info.treat_nested_steps_as_methods = treat_nested_steps_as_methods135 step_info.log_output = log_output136 step_info.log_input = log_input137 return params_wrapper138 else:139 step_info.function = func...
rollout_step_py3.py
Source:rollout_step_py3.py
1# coding=utf-82# --------------------------------------------------------------------------3# Copyright (c) Microsoft Corporation. All rights reserved.4# Licensed under the MIT License. See License.txt in the project root for5# license information.6#7# Code generated by Microsoft (R) AutoRest Code Generator.8# Changes may cause incorrect behavior and will be lost if the code is9# regenerated.10# --------------------------------------------------------------------------11from msrest.serialization import Model12class RolloutStep(Model):13 """Defines a specific step on a target service unit.14 Variables are only populated by the server, and will be ignored when15 sending a request.16 All required parameters must be populated in order to send to Azure.17 :param name: Required. Name of the step.18 :type name: str19 :ivar status: Current state of the step.20 :vartype status: str21 :param step_group: The step group the current step is part of.22 :type step_group: str23 :ivar operation_info: Detailed information of specific action execution.24 :vartype operation_info:25 ~azure.mgmt.deploymentmanager.models.StepOperationInfo26 :ivar resource_operations: Set of resource operations that were performed,27 if any, on an Azure resource.28 :vartype resource_operations:29 list[~azure.mgmt.deploymentmanager.models.ResourceOperation]30 :ivar messages: Supplementary informative messages during rollout.31 :vartype messages: list[~azure.mgmt.deploymentmanager.models.Message]32 """33 _validation = {34 'name': {'required': True},35 'status': {'readonly': True},36 'operation_info': {'readonly': True},37 'resource_operations': {'readonly': True},38 'messages': {'readonly': True},39 }40 _attribute_map = {41 'name': {'key': 'name', 'type': 'str'},42 'status': {'key': 'status', 'type': 'str'},43 'step_group': {'key': 'stepGroup', 'type': 'str'},44 'operation_info': {'key': 'operationInfo', 'type': 'StepOperationInfo'},45 'resource_operations': {'key': 'resourceOperations', 'type': '[ResourceOperation]'},46 'messages': {'key': 'messages', 'type': '[Message]'},47 }48 def __init__(self, *, name: str, step_group: str=None, **kwargs) -> None:49 super(RolloutStep, self).__init__(**kwargs)50 self.name = name51 self.status = None52 self.step_group = step_group53 self.operation_info = None54 self.resource_operations = None...
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!!