How to use append_text method in PyHamcrest

Best Python code snippet using PyHamcrest_python

pyxmlsec-demo.py

Source:pyxmlsec-demo.py Github

copy

Full Screen

...115 self.buffer.get_tag_table().add(tag)116 def clear(self):117 start, end = self.get_buffer().get_bounds()118 self.buffer.delete(start, end)119 def append_text(self, text, nb_tab=0):120 if text == '': return121 iter = self.buffer.get_end_iter()122 if nb_tab:123 tab = '\n' + ' ' * nb_tab124 text = ' ' * nb_tab + string.replace(text, '\n', tab)125 self.buffer.insert_with_tags_by_name(iter, text+'\n', "monospace")126 # self.buffer.insert(iter, text+'\n')127def quit(widget=None, *args):128 gtk.main_quit()129def interface():130 global ntb, tview_exec, tview_src131 # window132 window = gtk.Window()133 window.set_wmclass(PACKAGE, PACKAGE)134 window.set_title(PACKAGE)135 window.resize(800, 600)136 window.set_resizable(True)137 window.connect('destroy', quit)138 # HPaned139 vpaned = gtk.VPaned()140 window.add(vpaned)141 # ScrolledWindow for clist142 sw_clist = gtk.ScrolledWindow()143 sw_clist.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)144 vpaned.pack1 (sw_clist, False, False)145 # CList to launch examples146 clist = CList(cols = [('Examples (double click for demo)', gobject.TYPE_STRING, 0, 0, 0, 0)],147 cbs = [('row-activated', on_clist_row_doubleclicked)])148 clist.get_selection().connect('changed', on_clist_row_clicked)149 clist.set_rules_hint(True)150 clist.append_row(['Signing a template file'])151 clist.append_row(['Signing a file with a dynamicaly created template'])152 clist.append_row(['Signing a file with a dynamicaly created template and an X509 certificate'])153 clist.append_row(['Verifying a file using a single key'])154 clist.append_row(['Verifying a file using keys manager'])155 clist.append_row(['Verifying a file signed with X509 certificate'])156 clist.append_row(['Verifying a signature with additional restrictions'])157 clist.append_row(['Encrypting data using a template file'])158 clist.append_row(['Encrypting XML file with a dynamicaly created template'])159 clist.append_row(['Encrypting XML file with a session key and dynamicaly created template'])160 clist.append_row(['Decrypting an encrypted file using a single key'])161 clist.append_row(['Decrypting an encrypted file using keys manager'])162 clist.append_row(['Decrypting an encrypted file using a custom keys manager'])163 sw_clist.add(clist)164 # Notebook165 ntb = gtk.Notebook()166 vpaned.pack2 (ntb, False, False)167 # ScrolledWindow for TextView Source168 sw_tview_src = gtk.ScrolledWindow()169 sw_tview_src.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)170 ntb.append_page (sw_tview_src, gtk.Label("Source"))171 # TextView Source172 tview_src = TView()173 sw_tview_src.add(tview_src)174 # ScrolledWindow for TextView Execution175 sw_tview_exec = gtk.ScrolledWindow()176 sw_tview_exec.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)177 ntb.append_page (sw_tview_exec, gtk.Label("Execution"))178 # TextView Execution179 tview_exec = TView()180 sw_tview_exec.add(tview_exec)181 # Show all widgets182 window.show_all()183def on_clist_row_clicked(selection):184 ntb.set_current_page(0)185 tview_src.clear()186 tview_exec.clear()187 model, iter = selection.get_selected()188 row = model.get_path(iter)[0]189 if row == 0:190 tview_src.append_text(commands.getoutput('cat ./sign1.py'))191 elif row == 1:192 tview_src.append_text(commands.getoutput('cat ./sign2.py'))193 elif row == 2:194 tview_src.append_text(commands.getoutput('cat ./sign3.py'))195 elif row == 3:196 tview_src.append_text(commands.getoutput('cat ./verify1.py'))197 elif row == 4:198 tview_src.append_text(commands.getoutput('cat ./verify2.py'))199 elif row == 5:200 tview_src.append_text(commands.getoutput('cat ./verify3.py'))201 elif row == 6:202 tview_src.append_text(commands.getoutput('cat ./verify4.py'))203 elif row == 7:204 tview_src.append_text(commands.getoutput('cat ./encrypt1.py'))205 elif row == 8:206 tview_src.append_text(commands.getoutput('cat ./encrypt2.py'))207 elif row == 9:208 tview_src.append_text(commands.getoutput('cat ./encrypt3.py'))209 elif row == 10:210 tview_src.append_text(commands.getoutput('cat ./decrypt1.py'))211 elif row == 11:212 tview_src.append_text(commands.getoutput('cat ./decrypt2.py'))213 elif row == 12:214 tview_src.append_text(commands.getoutput('cat ./decrypt3.py'))215def on_clist_row_doubleclicked(treeview, path, treeviewcolumn):216 ntb.set_current_page(1)217 tview_exec.clear()218 row = path[0]219 if row == 0:220 tview_exec.append_text('Signing a template file')221 tview_exec.append_text('-----------------------')222 tview_exec.append_text('Template file sign1-tmpl.xml', 1)223 tview_exec.append_text('----------------------------', 1)224 tview_exec.append_text(commands.getoutput('cat ./sign1-tmpl.xml'), 2)225 tview_exec.append_text('Result', 1)226 tview_exec.append_text('------', 1)227 tview_exec.append_text(commands.getoutput('./sign1.py sign1-tmpl.xml rsakey.pem'), 2)228 elif row == 1:229 tview_exec.append_text('Signing a file with a dynamicaly created template')230 tview_exec.append_text('-------------------------------------------------')231 tview_exec.append_text('Doc file sign2-doc.xml', 1)232 tview_exec.append_text('----------------------', 1)233 tview_exec.append_text(commands.getoutput('cat ./sign2-doc.xml'), 2)234 tview_exec.append_text('Result', 1)235 tview_exec.append_text('------', 1)236 tview_exec.append_text(commands.getoutput('./sign2.py sign2-doc.xml rsakey.pem'), 2)237 elif row == 2:238 tview_exec.append_text('Signing a file with a dynamicaly created template and an X509 certificate')239 tview_exec.append_text('-------------------------------------------------------------------------')240 tview_exec.append_text('Doc file sign3-doc.xml', 1)241 tview_exec.append_text('----------------------', 1)242 tview_exec.append_text(commands.getoutput('cat ./sign3-doc.xml'), 2)243 tview_exec.append_text('Result', 1)244 tview_exec.append_text('------', 1)245 tview_exec.append_text(commands.getoutput('./sign3.py sign3-doc.xml rsakey.pem rsacert.pem'), 2)246 elif row == 3:247 tview_exec.append_text('Verifying a file using a single key')248 tview_exec.append_text('-----------------------------------')249 tview_exec.append_text('Doc file sign1-res.xml', 1)250 tview_exec.append_text('----------------------', 1)251 tview_exec.append_text(commands.getoutput('cat ./sign1-res.xml'), 2)252 tview_exec.append_text('Result', 1)253 tview_exec.append_text('------', 1)254 tview_exec.append_text(commands.getoutput('./verify1.py sign1-res.xml rsapub.pem'), 2)255 elif row == 4:256 tview_exec.append_text('Verifying a file using keys manager')257 tview_exec.append_text('-----------------------------------')258 tview_exec.append_text('Doc file sign2-res.xml', 1)259 tview_exec.append_text('----------------------', 1)260 tview_exec.append_text(commands.getoutput('cat ./sign2-res.xml'), 2)261 tview_exec.append_text('Result', 1)262 tview_exec.append_text('------', 1)263 tview_exec.append_text(commands.getoutput('./verify2.py sign2-res.xml rsapub.pem'), 2)264 elif row == 5:265 tview_exec.append_text('Verifying a file signed with X509 certificate')266 tview_exec.append_text('---------------------------------------------')267 tview_exec.append_text('Doc file sign3-res.xml', 1)268 tview_exec.append_text('----------------------', 1)269 tview_exec.append_text(commands.getoutput('cat ./sign3-res.xml'), 2)270 tview_exec.append_text('Result', 1)271 tview_exec.append_text('------', 1)272 tview_exec.append_text(commands.getoutput('./verify3.py sign3-res.xml rootcert.pem'), 2)273 elif row == 6:274 tview_exec.append_text('Verifying a signature with additional restrictions')275 tview_exec.append_text('--------------------------------------------------')276 tview_exec.append_text('Doc file verify4-res.xml', 1)277 tview_exec.append_text('------------------------', 1)278 tview_exec.append_text(commands.getoutput('cat ./verify4-res.xml'), 2)279 tview_exec.append_text('Result', 1)280 tview_exec.append_text('------', 1)281 tview_exec.append_text(commands.getoutput('./verify4.py verify4-res.xml rootcert.pem'), 2)282 elif row == 7:283 tview_exec.append_text('Encrypting data using a template file')284 tview_exec.append_text('-------------------------------------')285 tview_exec.append_text('Template file encrypt1-tmpl.xml', 1)286 tview_exec.append_text('-------------------------------', 1)287 tview_exec.append_text(commands.getoutput('cat ./encrypt1-tmpl.xml'), 2)288 tview_exec.append_text('Result', 1)289 tview_exec.append_text('------', 1)290 tview_exec.append_text(commands.getoutput('./encrypt1.py encrypt1-tmpl.xml deskey.bin'), 2)291 elif row == 8:292 tview_exec.append_text('Encrypting XML file with a dynamicaly created template')293 tview_exec.append_text('------------------------------------------------------')294 tview_exec.append_text('Doc file encrypt2-doc.xml', 1)295 tview_exec.append_text('-------------------------', 1)296 tview_exec.append_text(commands.getoutput('cat ./encrypt2-doc.xml'), 2)297 tview_exec.append_text('Result', 1)298 tview_exec.append_text('------', 1)299 tview_exec.append_text(commands.getoutput('./encrypt2.py encrypt2-doc.xml deskey.bin'), 2)300 elif row == 9:301 tview_exec.append_text('Encrypting XML file with a session key and dynamicaly created template')302 tview_exec.append_text('----------------------------------------------------------------------')303 tview_exec.append_text('Doc file encrypt3-doc.xml', 1)304 tview_exec.append_text('-------------------------', 1)305 tview_exec.append_text(commands.getoutput('cat ./encrypt3-doc.xml'), 2)306 tview_exec.append_text('Result', 1)307 tview_exec.append_text('------', 1)308 tview_exec.append_text(commands.getoutput('./encrypt3.py encrypt3-doc.xml rsakey.pem'), 2)309 elif row == 10:310 tview_exec.append_text('Decrypting an encrypted file using a single key')311 tview_exec.append_text('-----------------------------------------------')312 tview_exec.append_text('Doc file encrypt1-res.xml', 1)313 tview_exec.append_text('-------------------------', 1)314 tview_exec.append_text(commands.getoutput('cat ./encrypt1-res.xml'), 2)315 tview_exec.append_text('Result', 1)316 tview_exec.append_text('------', 1)317 tview_exec.append_text(commands.getoutput('./decrypt1.py encrypt1-res.xml deskey.bin'), 2)318 elif row == 11:319 tview_exec.append_text('Decrypting an encrypted file using keys manager')320 tview_exec.append_text('-----------------------------------------------')321 tview_exec.append_text('Doc file encrypt2-res.xml', 1)322 tview_exec.append_text('-------------------------', 1)323 tview_exec.append_text(commands.getoutput('cat ./encrypt2-res.xml'), 2)324 tview_exec.append_text('Result', 1)325 tview_exec.append_text('------', 1)326 tview_exec.append_text(commands.getoutput('./decrypt2.py encrypt2-res.xml deskey.bin'), 2)327 elif row == 12:328 tview_exec.append_text('Decrypting an encrypted file using a custom keys manager')329 tview_exec.append_text('-----------------------------------------------')330 tview_exec.append_text('Doc file encrypt1-res.xml', 1)331 tview_exec.append_text('-------------------------', 1)332 tview_exec.append_text(commands.getoutput('cat ./encrypt1-res.xml'), 2)333 tview_exec.append_text('Result', 1)334 tview_exec.append_text('------', 1)335 tview_exec.append_text(commands.getoutput('./decrypt3.py encrypt1-res.xml'), 2)336if __name__ == '__main__':337 interface()...

Full Screen

Full Screen

debug.py

Source:debug.py Github

copy

Full Screen

1LB = '\n' # line break2TXT = ''3DBG = ''4def append_text(TXT, TXT_TMP, SB, EB):5 TXT = TXT + SB + TXT_TMP + EB6 return TXT7def prompt_message(DBG, TXT_TMP, SB, EB):8 DBG = DBG + SB + TXT_TMP + EB9 from chimera import replyobj10 replyobj.error(TXT_TMP)11 return DBG12TXT_TMP = 'Debug analysis'13DBG = append_text(DBG, TXT_TMP, LB, LB)14TXT_TMP = 'Debug log for EMAN\'s Chimera modules'15TXT = append_text(TXT, TXT_TMP, LB, LB)16TXT_TMP = 'Lavu Sridhar'17TXT = append_text(TXT, TXT_TMP, LB, LB)18DBG = append_text(DBG, TXT_TMP, LB, LB)19TXT_TMP = 'Chimera version = -%s-' % (chimera.version.version)20TXT = append_text(TXT, TXT_TMP, LB, '')21TXT_TMP = 'Chimera build = -%s-' % (chimera.version.release)22TXT = append_text(TXT, TXT_TMP, LB, '')23import os24import sys25# check for OS platform26TXT_TMP = 'Platform = -%s-' % (sys.platform)27TXT = append_text(TXT, TXT_TMP, LB, '')28TXT_TMP = 'OS name = -%s-' % (chimera.operating_system())29TXT = append_text(TXT, TXT_TMP, LB, '')30# check for Python version31TXT_TMP = 'Python = -%s-' % (sys.version)32TXT = append_text(TXT, TXT_TMP, LB, '')33# check for current directory34TXT_TMP = 'Working dir = -%s-' % os.getcwd()35TXT = append_text(TXT, TXT_TMP, LB, '')36# check for EMANDIR environment varaible37TXT_TMP = 'Searching for EMANDIR environment variable...'38TXT = append_text(TXT, TXT_TMP, LB + LB, '')39if os.environ.has_key('EMANDIR'):40 TXT_TMP = 'EMANDIR value = -%s-' % (os.environ['EMANDIR'])41 TXT = append_text(TXT, TXT_TMP, LB, '')42else:43 TXT_TMP = 'Did not find EMANDIR environment variable!'44 TXT = append_text(TXT, TXT_TMP, LB, '')45 TXT_TMP = 'Add EMANDIR to environment variables'46 TXT = append_text(TXT, TXT_TMP, LB, '')47 DBG = prompt_message(DBG, TXT_TMP, LB, '')48# check for PYHTONPATH environment variable49TXT_TMP = 'Searching for PYTHONPATH Chimera varaible..'50TXT = append_text(TXT, TXT_TMP, LB + LB, '')51if os.environ.has_key('PYTHONPATH'):52 TXT_TMP = 'Default PYTHONPATH in Chimera = -%s-' % (os.environ['PYTHONPATH'])53 TXT = append_text(TXT,TXT_TMP, LB, '')54else:55 TXT_TMP = 'PYHTONPATH not found in Chimera'56 TXT = append_text(TXT,TXT_TMP, LB, '')57 58 # DBG = prompt_message(DBG, TXT_TMP, LB, '')59# first try to import EMAN60TXT_TMP = 'First attempt to import EMAN...'61TXT = append_text(TXT, TXT_TMP, LB + LB, '')62try:63 import EMAN64 TXT_TMP = 'EMAN import successfful'65 TXT = append_text(TXT, TXT_TMP, LB, '')66 67except:68 TXT_TMP = 'EMAN import failed...'69 TXT = append_text(TXT, TXT_TMP, LB, '')70 # adding EMAN lib to PYHTONPATH71 TXT_TMP = 'Adding EMAN lib to PYTHONPATH ...'72 TXT = append_text(TXT, TXT_TMP, LB + LB, LB)73 if os.environ.has_key('EMANDIR'):74 # add directory (EMAN lib) to python path75 emandir = os.environ['EMANDIR']76 emanpy = os.path.join(emandir, 'lib')77 if sys.platform == 'win32':78 sep = ';' # Windows separator79 else:80 sep = ':' # Unix separator81 if (os.environ.has_key('PYTHONPATH') and82 os.environ['PYTHONPATH'] != ''):83 pypath = os.environ['PYTHONPATH'] + sep + emanpy84 TXT_TMP = '...Adding ENAN lib = -%s- ' % (emanpy)85 TXT = append_text(TXT, TXT_TMP, LB, '')86 TXT_TMP = '...to PYTHONPATH in Chimera = -%s-' % (os.environ['PYTHONPATH'])87 TXT = append_text(TXT, TXT_TMP, LB, '')88 else:89 pypath = emanpy90 TXT_TMP = '...Setting PYTHONPATH in Chimera'91 TXT = append_text(TXT, TXT_TMP, LB, '')92 TXT_TMP = '...to ENAN lib = -%s- ' % (emanpy)93 TXT = append_text(TXT, TXT_TMP, LB, '')94 os.environ['PYTHONPATH'] = pypath95 sys.path.append(emanpy)96 TXT_TMP = 'Final PYTHONPATH in Chimera = -%s-' % (os.environ['PYTHONPATH'])97 TXT = append_text(TXT, TXT_TMP, LB, '')98 else:99 TXT_TMP = 'EMANDIR enviroment variable not found!'100 TMP = append_text(TXT, TXT_TMP, LB, '')101 102 TXT_TMP = 'Add EMANDIR environment variable!\n'103 TMP = append_text(TXT, TXT_TMP, LB, '')104 DBG = prompt_message(DBG, TXT_TMP, LB, '')105# second try to import EMAN106TXT_TMP = 'Second attempt to import EMAN...'107TXT = append_text(TXT, TXT_TMP, LB + LB, '')108try:109 import EMAN110 TXT_TMP = 'EMAN import succefful'111 TXT = append_text(TXT, TXT_TMP, LB, '')112except:113 TXT_TMP = 'EMAN import failed!'114 TXT = append_text(TXT, TXT_TMP, LB, '')115 DBG = prompt_message(DBG, TXT_TMP, LB, '')116# check if Segment modules can be imported117TXT_TMP = 'Try to import Segment modules...'118TXT = append_text(TXT, TXT_TMP, LB + LB, '')119try:120 import SegmentMask121 TXT_TMP = 'module import successful'122 TXT = append_text(TXT, TXT_TMP, LB, '')123 124except:125 TXT_TMP = 'module import failed!'126 TXT = append_text(TXT, TXT_TMP, LB, '')127 import sys128 TXT_TMP = 'System path = -%s-' % (sys.path)129 TXT = append_text(TXT, TXT_TMP, LB, '')130 131 TXT_TMP = 'add Segment directory to Chimera Tools path'132 TXT = append_text(TXT, TXT_TMP, LB, '')133 DBG = prompt_message(DBG, TXT_TMP, LB, '')134# try import 1st sample program135TXT_TMP = 'Try to import sample program (maskmain)...'136TXT = append_text(TXT, TXT_TMP, LB + LB, '')137try:138 from SegmentMask import maskmain139 TXT_TMP = 'maskmain import successful!'140 TXT = append_text(TXT, TXT_TMP, LB, '')141except:142 TXT_TMP = 'maskmain import failed!'143 TXT = append_text(TXT, TXT_TMP, LB, '')144 DBG = prompt_message(DBG, TXT_TMP, LB, '')145 146# try import 2nd sample program147TXT_TMP = 'Try to import sample program (maskedit)...'148TXT = append_text(TXT, TXT_TMP, LB + LB, '')149try:150 from SegmentMask import maskedit151 TXT_TMP = 'maskedit import successful!'152 TXT = append_text(TXT, TXT_TMP, LB, '')153except:154 TXT_TMP = 'maskedit import failed!'155 TXT = append_text(TXT, TXT_TMP, LB, '')156 DBG = prompt_message(DBG, TXT_TMP, LB, '')157# try opening sample dialog (mask dialog - mg)158TXT_TMP = 'Attempting to display dialog...'159TXT = append_text(TXT, TXT_TMP, LB + LB, '')160try:161 mg = maskmain.seg_mask_dialog(1)162 TXT_TMP = 'mask dialog open successful!'163 TXT = append_text(TXT, TXT_TMP, LB, '')164except:165 TXT_TMP = 'mask dialog open failed!'166 TXT = append_text(TXT, TXT_TMP, LB, '')167 DBG = prompt_message(DBG, TXT_TMP, LB, '')168# create some dummy mask data:169TXT_TMP = 'Attempting to create dummy data...'170TXT = append_text(TXT, TXT_TMP, LB + LB, '')171# data 64x64x64 with cube 20x20x20172mask_dir = os.getcwd()173mask_files = ['debugTestFile.mrc',]174mask_file = mask_files[0]175mst = mg.mask_type_choices[0] # cube176p0, p1, p2 = [20,20,20] # size 20177mask_path = os.path.join(mask_dir, mask_file)178mask_origin = (0.,0.,0.) # data origin179mask_size = (64,64,64) # data size180mask_step = (1.,1.,1.) # ang per pix181talign = (0.,0.,0.) # translate182ralign = (0.,0.,0.) # rotate (EMAN Euler)183radial = 0 # step function184msg = maskedit.create_mask(mst, p0,p1,p2, mask_path,185 mask_origin, mask_size, mask_step,186 talign, ralign, radial)187TXT_TMP = msg188TXT = append_text(TXT, TXT_TMP, LB, '')189# check if dummy data created190TXT_TMP = 'Checking for mask output file...'191TXT = append_text(TXT, TXT_TMP, LB + LB, '')192try:193 os.path.isfile(mask_path)194 TXT_TMP = 'mask output file found'195 TXT = append_text(TXT, TXT_TMP, LB, '')196except:197 TXT_TMP = 'mask out file missing!'198 TXT = append_text(TXT, TXT_TMP, LB, '')199 DBG = prompt_message(DBG, TXT_TMP, LB, '')200# open dummy data with Chiemra201TXT_TMP = 'Attempt to open file with Chimera...'202TXT = append_text(TXT, TXT_TMP, LB + LB, '')203try:204 cms = chimera.openModels.open(mask_path)205 TXT_TMP = 'mask output file opened'206 TXT = append_text(TXT, TXT_TMP, LB, '')207except:208 TXT_TMP = 'file unreadable or missing!'209 TXT = append_text(TXT, TXT_TMP, LB, '')210 DBG = prompt_message(DBG, TXT_TMP, LB, '')211# open dummy data with dialog212TXT_TMP = 'Attempt to open file with dialog...'213TXT = append_text(TXT, TXT_TMP, LB + LB, '')214try:215 mg.open_output_data_items(mask_dir, mask_files)216 TXT_TMP = 'mask output file opened'217 TXT = append_text(TXT, TXT_TMP, LB, '')218except:219 TXT_TMP = 'mask out file unreadable or error!'220 TXT = append_text(TXT, TXT_TMP, LB, '')221 DBG = prompt_message(DBG, TXT_TMP, LB, '')222# show dummy data223TXT_TMP = 'Attempt to display data from dialog...'224TXT = append_text(TXT, TXT_TMP, LB + LB, '')225try:226 mg.output_panel.data_show_cb()227 TXT_TMP = 'mask file display successful'228 TXT = append_text(TXT, TXT_TMP, LB, '')229except:230 TXT_TMP = 'mask file display failed!'231 TXT = append_text(TXT, TXT_TMP, LB, '')232 DBG = prompt_message(DBG, TXT_TMP, LB, '')233TXT_TMP = LB + '-'*30 + LB + LB + \234 'Do you see a 20x20x20 mask cube at the ' + LB + \235 'center of a 64x64x64 data file?' + LB + '-'*30 + LB236print TXT_TMP237 238TXT_TMP = 'If you check Model Panel under Favorites menu ' + LB + \239 'Chimera, there should be 2 models with file ' + LB + \240 'name debugTestFile.mrc' + LB + '-'*30 + LB241print TXT_TMP242TXT_TMP = 'If NOT, pleae type "print TXT" and send us ' + LB + \243 'the output along with any other error messages' + LB + \244 '-'*30 + LB245print TXT_TMP

Full Screen

Full Screen

wrapped_vc_validators.py

Source:wrapped_vc_validators.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""Functions wrapping data type validators."""3import datetime4from typing import Optional5from typing import Union6from uuid import UUID7from validator_collection import validators8from validator_collection.errors import CannotCoerceError9from validator_collection.errors import EmptyValueError10from validator_collection.errors import MaximumLengthError11from validator_collection.errors import MaximumValueError12from validator_collection.errors import MinimumLengthError13from validator_collection.errors import MinimumValueError14from validator_collection.errors import NotAnIntegerError15from .errors import ValidationCollectionCannotCoerceError16from .errors import ValidationCollectionEmptyValueError17from .errors import ValidationCollectionMaximumLengthError18from .errors import ValidationCollectionMaximumValueError19from .errors import ValidationCollectionMinimumLengthError20from .errors import ValidationCollectionMinimumValueError21from .errors import ValidationCollectionNotAnIntegerError22def validate_str(23 value: object,24 allow_null: bool = False,25 minimum_length: Optional[int] = None,26 maximum_length: Optional[int] = None,27 extra_error_msg: str = None,28) -> Union[None, str]:29 """Check that object is a valid string."""30 try:31 validated_value: str = validators.string(32 value,33 allow_empty=allow_null,34 minimum_length=minimum_length,35 maximum_length=maximum_length,36 )37 except EmptyValueError as e:38 raise ValidationCollectionEmptyValueError(e, append_text=extra_error_msg) from e39 except CannotCoerceError as e:40 raise ValidationCollectionCannotCoerceError(41 e, append_text=extra_error_msg42 ) from e43 except MinimumLengthError as e:44 raise ValidationCollectionMinimumLengthError(45 e, append_text=extra_error_msg46 ) from e47 except MaximumLengthError as e:48 raise ValidationCollectionMaximumLengthError(49 e, append_text=extra_error_msg50 ) from e51 return validated_value52def validate_uuid(53 value: object, allow_null: bool = False, extra_error_msg: str = None54) -> Union[UUID, None]:55 """Check that object is a valid UUID."""56 try:57 validated_value: UUID = validators.uuid(value, allow_empty=allow_null)58 except EmptyValueError as e:59 raise ValidationCollectionEmptyValueError(e, append_text=extra_error_msg) from e60 except CannotCoerceError as e:61 raise ValidationCollectionCannotCoerceError(62 e, append_text=extra_error_msg63 ) from e64 return validated_value65def validate_float(66 value: object,67 allow_null: bool = False,68 minimum: Optional[Union[float, int]] = None,69 maximum: Optional[Union[float, int]] = None,70 extra_error_msg: str = None,71) -> Union[float, None]:72 """Check that object is a valid float."""73 try:74 validated_value: float = validators.float(75 value, allow_empty=allow_null, minimum=minimum, maximum=maximum76 )77 except EmptyValueError as e:78 raise ValidationCollectionEmptyValueError(e, append_text=extra_error_msg) from e79 except CannotCoerceError as e:80 raise ValidationCollectionCannotCoerceError(81 e, append_text=extra_error_msg82 ) from e83 except MinimumValueError as e:84 raise ValidationCollectionMinimumValueError(85 e, append_text=extra_error_msg86 ) from e87 except MaximumValueError as e:88 raise ValidationCollectionMaximumValueError(89 e, append_text=extra_error_msg90 ) from e91 return validated_value92def validate_int(93 value: object,94 allow_null: bool = False,95 minimum: Optional[int] = None,96 maximum: Optional[int] = None,97 extra_error_msg: str = None,98) -> Union[int, None]:99 """Check that object is a valid int."""100 try:101 validated_value: int = validators.integer(102 value, allow_empty=allow_null, minimum=minimum, maximum=maximum103 )104 except EmptyValueError as e:105 raise ValidationCollectionEmptyValueError(e, append_text=extra_error_msg) from e106 except NotAnIntegerError as e:107 raise ValidationCollectionNotAnIntegerError(108 e, append_text=extra_error_msg109 ) from e110 except MinimumValueError as e:111 raise ValidationCollectionMinimumValueError(112 e, append_text=extra_error_msg113 ) from e114 except MaximumValueError as e:115 raise ValidationCollectionMaximumValueError(116 e, append_text=extra_error_msg117 ) from e118 except CannotCoerceError as e:119 raise ValidationCollectionCannotCoerceError(120 e, append_text=extra_error_msg121 ) from e122 return validated_value123def validate_datetime(124 value: object,125 allow_null: bool = False,126 minimum: Optional[datetime.datetime] = None,127 maximum: Optional[datetime.datetime] = None,128 extra_error_msg: str = None,129) -> Union[datetime.datetime, None]:130 """Check that object is a valid datetime."""131 try:132 validated_value: datetime.datetime = validators.datetime(133 value, allow_empty=allow_null, minimum=minimum, maximum=maximum134 )135 except EmptyValueError as e:136 raise ValidationCollectionEmptyValueError(e, append_text=extra_error_msg) from e137 except CannotCoerceError as e:138 raise ValidationCollectionCannotCoerceError(139 e, append_text=extra_error_msg140 ) from e141 except MinimumValueError as e:142 raise ValidationCollectionMinimumValueError(143 e, append_text=extra_error_msg144 ) from e145 except MaximumValueError as e:146 raise ValidationCollectionMaximumValueError(147 e, append_text=extra_error_msg148 ) from e...

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 PyHamcrest 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