Best Python code snippet using yandex-tank
PhantomProperties.py
Source:PhantomProperties.py  
1# -*- coding: utf-8 -*-2"""3Created on Sat Nov 09 11:00:01 20134Reads in and display Phantom properties5Uses ROIPropertiesGui.py created from PhantomPropertiesGui.ui by QT46execute   "designer\pyuic4 designer\PhantomPropertiesGui.ui -o PhantomViewer\PhantomPropertiesGui.py" from system shell to regenerate ROIPropertiesGui.py from ROIPropertiesGui.ui7@author: stephen russek8"""9import sys10try:11  from PyQt4 import QtGui, QtCore12except:13  from PyQt5 import QtGui, QtCore14from PhantomPropertiesGui import Ui_PhantomPropertiesGui15import numpy as np16import VPhantom17class PhantomProperties(QtGui.QMainWindow):18  def __init__(self ,phantom, parent = None):19    super(PhantomProperties, self).__init__()20    self.ui = Ui_PhantomPropertiesGui()21    self.ui.setupUi(self)22    self.setWindowTitle('Phantom Properties')23    self.Phantom= phantom24    25  #signals and slots26    self.ui.actionOpen_Phantom_File.triggered.connect(self.openPhantomFile)27    self.ui.actionSave_Phantom_File.triggered.connect(self.savePhantomFile)28    self.showPhantomInfo(self.Phantom)29 30  def openPhantomFile (self, direct =''):31    self.Phantom.T1ROIs.ROIs = []   #reset ROI list32    if direct == False:33        direct = ''34    self.fileName = QtGui.QFileDialog.getOpenFileName(self,"Open ROI File", direct, "ROI File (*.dat)")35    if not self.fileName:  #if cancel is pressed return36      return None37    f = open(str(self.fileName), 'r')38    for line in f:39      parameter = line[:line.find('=')]40      values=line[line.find('=')+1:]41      if parameter == "PhantomName":42        self.ui.txtPhantomName.setText(str(values))43      if parameter == "B0":44        self.ui.txtField.setText(str(values))45      if parameter == "Temperature":46        self.ui.txtTemperature.setText(str(values))47      if parameter == "Comment":48        self.ui.txtComment.setText(str(values))49      if parameter == "NumberofROIsets":50        self.ui.txtnROIsets.setText(str(values))51      if parameter == "ROIName":52        ROIName = parameter53      if parameter == "T1Array-nROIs":54        self.Phantom.T1ROIs.nROIs=int(values)55        for i in range(int(values)):    #create a list of T1 ROIs56            self.Phantom.T1ROIs.ROIs.append(VPhantom.ROI())57            self.Phantom.T1ROIs.ROIs[-1].Type= "T1"58            self.Phantom.T1ROIs.ROIs[-1].Index = i+159            self.Phantom.T1ROIs.ROIs[-1].Name = "T1-" +str(i+1)60      for te in self.tblT1:61        if parameter == te:     #cycle through T1 table entries62          data = np.fromstring(values, sep=',')63          for i in range(data.size):64            self.ui.tblT1.setItem(self.tblT1[te],i,QtGui.QTableWidgetItem(str(data[i])))65            self.Phantom.T1ROIs.SetROIsParameter( i, self.T1parameter[self.tblT1[te]], data[i])66#            print "Set T1 parameter=" + self.T1parameter[self.tblT1[te]] + " =" + str(data[i]) + "; ROI number=" + str(i)67#            if te == "T1CustomROIT1(ms)":68#                self.ui.tblT1.setItem(self.tblT1[te]+1,i,QtGui.QTableWidgetItem("{:.3f}".format(1000/data[i]))) #Set R169      for te in self.tblT2:70        if parameter == te:     #cycle through T2 table entries71          data = np.fromstring(values, sep=',')72          for i in range(data.size):73            self.ui.tblT2.setItem(self.tblT2[te],i,QtGui.QTableWidgetItem(str(data[i])))74#            if te == "T2CustomROIT2(ms)":75#                self.ui.tblT2.setItem(self.tblT2[te]+1,i,QtGui.QTableWidgetItem("{:.3f}".format(1000/data[i])))  76  77 78  def savePhantomFile (self,phantom):79      fileName = QtGui.QFileDialog.getSaveFileName(parent=None, caption="Report File Name", directory = '', selectedFilter = ".dat")80      if not fileName:  #if cancel is pressed return81        return None82      f= open(fileName, 'w')83      s = self.Phantom.printROIinfo()84      f.write(s)85      f.close()86      print (s)87            88  def showPhantomInfo (self, phantom):89    self.Phantom=phantom90    self.ui.txtPhantomName.setText(self.Phantom.phantomName)91    self.ui.txtComment.setText(self.Phantom.Comment)92    self.ui.txtTemperature.setText(str(self.Phantom.Temperature))93    self.ui.txtnROIsets.setText(str(len(self.Phantom.ROIsets)))94    self.ui.txtField.setText(str(self.Phantom.B0))95    self.ui.txtPhantomProperties.setText(self.Phantom.printROIinfo())96    self.ui.lblPhantomImage.setPixmap(QtGui.QPixmap(self.Phantom.phantomImage))97    self.ui.lblPhantomImage.setScaledContents(True)98    self.ui.lblPhantomImage.show()99 100                  101if __name__ == '__main__':102    app = QtGui.QApplication(sys.argv)103    test = PhantomProperties()104    test.show()...phantom_util.py
Source:phantom_util.py  
...25def _create_phantom_user_id():26    rs = os.urandom(20)27    random_string = hashlib.md5(rs).hexdigest()28    return PHANTOM_ID_EMAIL_PREFIX+random_string29def create_phantom(method):30    '''Decorator used to create phantom users if necessary.31    Warning:32    - Only use on get methods where a phantom user should be created.33    '''34    @wraps(method)35    def wrapper(self, *args, **kwargs):36        user_data = models.UserData.current()37        if not user_data:38            user_id = _create_phantom_user_id()39            user_data = models.UserData.insert_for(user_id, user_id)40            # we set just a 20 digit random string as the cookie,41            # not the entire fake email42            cookie = user_id.split(PHANTOM_ID_EMAIL_PREFIX)[1]43            # set the cookie on the user's computer44            self.set_cookie(PHANTOM_MORSEL_KEY, cookie)45            # make it appear like the cookie was already set46            set_request_cookie(PHANTOM_MORSEL_KEY, str(cookie))47            # Bust the cache so later calls to models.UserData.current() return48            # the phantom user49            models.UserData.current(bust_cache=True)50        return method(self, *args, **kwargs)51    return wrapper52def api_create_phantom(method):53    '''Decorator used to create phantom users in api calls if necessary.'''54    @wraps(method)55    def wrapper(*args, **kwargs):56        if models.UserData.current():57            return method(*args, **kwargs)58        else:59            # This mirrors create_phantom above, see there for clarification60            user_id = _create_phantom_user_id()61            user_data = models.UserData.insert_for(user_id, user_id)62            cookie = user_data.email.split(PHANTOM_ID_EMAIL_PREFIX)[1]63            set_request_cookie(PHANTOM_MORSEL_KEY, str(cookie))64            user_data = models.UserData.current(bust_cache=True)65            if not user_data:66                logging.warning("api_create_phantom failed to create user_data properly")...phantom.py
Source:phantom.py  
...7		self.height = 1108		self.width = 409		self.shellAttenuation = 110		self.cavityAttenuation = 0.511	def create_phantom(self):12		# Create phantom with default size of 20013		rows = 200 if max(self.height, self.width) <= 200 else max(self.height, self.width) + 2014		columns = rows15		phantom = np.zeros((rows, columns, columns))16		cavityHeight = self.height - (self.thickness * 2) 17		cavityWidth = self.width - (self.thickness * 2) 18		phantom[19				rows // 2 - self.height // 2 : rows // 2 + self.height // 2,20				columns // 2 - self.width // 2 : columns // 2 + self.width // 2,21				columns // 2 - self.width // 2 : columns // 2 + self.width // 222			] = self.shellAttenuation23		phantom[24				rows // 2 - cavityHeight // 2 : rows // 2 + cavityHeight // 2,25				columns // 2 - cavityWidth // 2 : columns // 2 + cavityWidth // 2,...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!!
