Best Python code snippet using pyatom_python
table.py
Source:table.py  
1#!/usr/bin/env python2#3#  Linux Desktop Testing Project http://www.gnomebangalore.org/ldtp4#5#  Description:6#  This set of test scripts will test the LDTP framework for correct7#  functioning of its APIs. This is a Regression Suite.8#9#  Author:10#     Prashanth Mohan  <prashmohan@gmail.com>11#12#13#  This test script is free software; you can redistribute it and/or14#  modify it under the terms of the GNU Library General Public15#  License as published by the Free Software Foundation; either16#  version 2 of the License, or (at your option) any later version.17#18#  This library is distributed in the hope that it will be useful,19#  but WITHOUT ANY WARRANTY; without even the implied warranty of20#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU21#  Library General Public License for more details.22#23#  You should have received a copy of the GNU Library General Public24#  License along with this library; if not, write to the25#  Free Software Foundation, Inc., 59 Temple Place - Suite 330,26#  Boston, MA 02111-1307, USA.27#28from regression import *29import random, os30try:31    open_evo ()32except:33    raise34data_object     = LdtpDataFileParser (datafilename)35rows            = data_object.gettagvalue ('rowcount')36evo_win  = '*Evolution*'37pref     = '*EvolutionPreferences'38acnt_tab = 'tblMailAccounts'39log ('getrowcount','teststart')40try:41    selectmenuitem (evo_win, 'mnuEdit;mnuPreferences')42    if waittillguiexist (pref) == 0:43        log ('Preferences Window not open yet','cause')44        raise LdtpExecutionError (str (traceback.format_exc ()))45    row_count = getrowcount (pref, acnt_tab)46    if rows != [] and rows != row_count:47        log ('No of rows does not match with input','cause')48        raise LdtpExecutionError (str (traceback.format_exc ()))49except:50    testfail ('getrowcount')51    raise LdtpExecutionError (str (traceback.format_exc ()))52testpass ('getrowcount')53acnts = []54log ('getcellvalue', 'teststart')55try:56    for index in range (row_count):57        val = getcellvalue (pref, acnt_tab, index, 1)58## http://bugzilla.gnome.org/show_bug.cgi?id=35222059#         if verifytablecell (pref, acnt_tab, index, 1, val) == 0:60#             log ('problem in getcellvalue','cause')61#             raise LdtpExecutionError (str (traceback.format_exc ()))62        acnts.append (val)63except:64    testfail ('getcellvalue')65    raise LdtpExecutionError (str (traceback.format_exc ()))66testpass ('getcellvalue')67log ('selectrowindex','teststart')68try:69    for index in range (row_count):70        if selectrowindex (pref, acnt_tab, index) != 1:71            log ('Unable to select index','cause')72            raise LdtpExecutionError (str (traceback.format_exc ()))73        #time.sleep (1)74        if gettablerowindex (pref, acnt_tab, acnts[index]) != index:75            log ('Index not selected','cause')76            raise LdtpExecutionError (str (traceback.format_exc ()))77except:78    testfail ('selectrowindex')79    raise LdtpExecutionError (str (traceback.format_exc ()))80testpass ('selectrowindex')81log ('selectrow','teststart')82try:83    index = 084    for acnt in acnts:85        if doesrowexist (pref, acnt_tab, acnt) == 1 and selectrow (pref, acnt_tab, acnt) != 1:86            log ('Unable to select row','cause')87            raise LdtpExecutionError (str (traceback.format_exc ()))88        #time.sleep (1)89        if gettablerowindex (pref, acnt_tab, acnt) != index:90            log ('Index not selected','cause')91            raise LdtpExecutionError (str (traceback.format_exc ()))92        index += 193except:94    testfail ('selectrow')95    raise LdtpExecutionError (str (traceback.format_exc ()))96testpass ('selectrow')97log ('selectlastrow','teststart')98try:99    if selectlastrow (pref,acnt_tab) != 1:100        log ('selectlastrow failed','cause')101        raise LdtpExecutionError (str (traceback.format_exc ()))102    #time.sleep (1)103    if gettablerowindex (pref, acnt_tab, acnt) != (len (acnts)-1):104        log ('Index not selected','cause')105        raise LdtpExecutionError (str (traceback.format_exc ()))106except:107    testfail ('selectlastrow')108    raise LdtpExecutionError (str (traceback.format_exc ()))109testpass ('selectlastrow')110log ('checkrow','teststart')111try:112    for index in range (row_count):113        if uncheckrow (pref, acnt_tab, index) == 0:114            log ('Unable to uncheck row','cause')115            raise LdtpExecutionError (str (traceback.format_exc ()))116        #time.sleep (2)117        if checkrow (pref, acnt_tab, index) == 0:118            log ('Unable to check row','cause')119            raise LdtpExecutionError (str (traceback.format_exc ()))120except:121    testfail ('checkrow')122    raise LdtpExecutionError (str (traceback.format_exc ()))123testpass ('checkrow')...Assigned_Task_modify.py
Source:Assigned_Task_modify.py  
1#!/usr/bin/env python2#3#  Linux Desktop Testing Project http://ldtp.freedesktop.org4#5#  Author:6#     Venkateswaran S <wenkat.s@gmail.com>7#     Prashanth Mohan  <prashmohan@gmail.com>8#9#  Copyright 2004 Novell, Inc.10#11#  This test script is free software; you can redistribute it and/or12#  modify it under the terms of the GNU Library General Public13#  License as published by the Free Software Foundation; either14#  version 2 of the License, or (at your option) any later version.15#16#  This library is distributed in the hope that it will be useful,17#  but WITHOUT ANY WARRANTY; without even the implied warranty of18#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU19#  Library General Public License for more details.20#21#  You should have received a copy of the GNU Library General Public22#  License along with this library; if not, write to the23#  Free Software Foundation, Inc., 59 Temple Place - Suite 330,24#  Boston, MA 02111-1307, USA.25#26# This script will create a new task.27from ldtp import *28from ldtputils import *29from task import *30from meeting import addattendees31def getrowindex(subject):32   try:33       noofchild=getrowcount ('frmEvolution-Tasks','tblTasks')34       for ind in range (noofchild):35           if getcellvalue('frmEvolution-Tasks','tblTasks',ind,2) == subject:36               return ind37       if ind == noofchild-1:38           log ('Message not present','cause')39           raise LdtpExecutionError (0)40   except:41       log ('Unable to get index of message','error')42       raise LdtpExecutionError (0)43def modify_task():44   """ Routine to modify a task """ 	45   46   # read the row index from the user and delete that particular task.47   try:48      log('Modify an assigned task','teststart')49      Group, Summary, Desc, Start_date, Start_time, \50             End_date, End_time, Time_zone, Categories, \51             addr_book, attendee, email = read_assignedtask_data (datafilename)52      selectrow ('frmEvolution-Tasks', 'tblTasks', Summary[0])53      selectmenuitem('frmEvolution-Tasks', 'mnuFile;mnuOpenTask')54      waittillguiexist('frmAssignedTask-*')55      window_id = 'frmAssignedTask-*'56      log('The window opened' ,'info')57   except:58      log('modify an assigned task','fail')59      log('Modify an assigned task','testend')60      raise LdtpExecutionError(0)61   62   # Modifies the task according to users wish.63   try:64      fill_task (Group, Summary, Desc, Start_date, Start_time,65                 End_date, End_time, Time_zone, Categories,66                 window_id)67      print 'Filled in the details'68      time.sleep(2)69      addattendees (attendee, email, addr_book, window_id)70      time.sleep(2)71      log('User data Loaded','info')72      73      if stateenabled (window_id,'btnSave')==1:74         click(window_id,'btnSave')75         log('The required task list has been modified','info')76      else:77         log('The Task is not modified because of no change in summary','info')78         click(window_id,'btnClose')79      time.sleep(2)80         81      if guiexist('dlgEvolutionQuery'):82         click('dlgEvolutionQuery','btnDonotSend')83         log('Task has been modified successfully','info')84         print 'The Assigned task has been modifed'85      if selectrow('frmEvolution-Tasks','tblTasks',Summary[0]) == 1:86         verify_task (Group, Summary, Desc, Start_date, Start_time,87                      End_date,End_time, Time_zone, Categories, window_id)88         click (window_id,'btnClose')89      else:90         click (window_id,'btnClose')91         raise LdtpExecutionError (0)92   except:93      log('Unable to load the user data','error')94      log('modify an assigned task','fail')95      log('Modify an assigned task','testend')96      raise LdtpExecutionError(0)97   log('modify an assigned task','pass')98   log('modify an assigned task','testend')99   100#    #Change the Progress of the task.101#    try:102      103#       Row_no = getrowindex(Summary[0])104#       if Progress[0] == 'complete':105#          checkrow ('frmEvolution-Tasks', 'tblTaskTable', Row_no, 1)106#       elif Progress[0] == 'Not started':107#          uncheckrow ('frmEvolution-Tasks', 'tblTaskTable', Row_no, 1)108#          log('progress of the task has been modified','info')109#          print 'The Progress has been modified'110#    except:111#       log('unable to change the progress of the task','error')112#       log('Modify an assigned task','testend')113#       #undoremap('evolution','frmEvolution-Tasks')114#       raise LdtpExecutionError(0)115   ...change_label_status.py
Source:change_label_status.py  
1# -*- coding: utf-8 -*-2""" change_label status Lambda module3Questo modulo contiene l'handler che effettua la modifica4dello stato di una label all'interno del file resume5Contenuto:6    * lambda_handler - l'handler principale per la lambda7"""8# imports url and media manager layer9import urllib.parse10import json11import boto312# definizione della risorsa s313s3 = boto3.resource('s3')14def lambda_handler(event, context):15    """16        Handler che riceve l'evento che fa scaturire l'esecuzione,17        e che contiene l'indice della label da aggiungere18        Args:19            event: L'evento che ha fatto scaturire l'avvio dell'handler20            context: Il dizionario rappresentante le variabili di contesto21                d'esecuzione22        Returns:23            True se l'esecuzione è andata a buon fine False altrimenti24        """25    print('Executing :' + context.function_name)26    sns = boto3.client('sns')27    try:28        # Preleva oggetto s3 contenente il resume29        content = event["Records"][0]["Sns"]30        resume = s3.Object('ahlconsolebucket', 'tmp/modified-resume.json')31        resume_res = resume.get()32        resume_content = json.loads(resume_res['Body'].read().decode('utf-8'))33        # Controlla il contenuto del messaggio34        message = content['Message']35        if message == "checkRow" or message == "uncheckRow":36            attributes = content['MessageAttributes']37            index = int(attributes['target']['Value'])38            resume_content[index]['show'] = "true" if attributes['check']['Value'] == "True" else "false"39            b_to_write = json.dumps(resume_content)40            resume.put(Body=b_to_write)41            # notifies of addLabel done status42            sns.publish(43                TopicArn='arn:aws:sns:us-east-2:693949087897:editLabels',44                Message='update'45            )46            return True47        return False48    except Exception as err:49        print(err)50        print('Impossibile modificare lo stato della label ')...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!!
