How to use report_failure method in Testify

Best Python code snippet using Testify_python

test_backup.py

Source:test_backup.py Github

copy

Full Screen

1from unittest.mock import patch2from borg_summon import report, backup, borg3import logging4@patch('borg_summon.backup.report_failure')5@patch('borg_summon.backup.report_success')6@patch('borg_summon.borg.hook')7@patch('borg_summon.borg.create')8@patch('borg_summon.borg.init')9def test_filter_source_remote_do_nothing(init, create, hook, report_success, report_failure):10 # Setup11 arg_config = {12 'backup': {13 'sources': {14 's1': {15 'paths': ['/home'],16 },17 's2': {18 'paths': ['/etc'],19 'remote_list': [],20 },21 }22 }23 }24 arg_source = ['s2']25 arg_remote = []26 arg_create = True27 # Perform28 backup.main_inner(arg_config, arg_source, arg_remote, arg_create)29 # Assert30 assert init.call_count == 031 assert create.call_count == 032 assert hook.call_count == 033 assert report_success.call_count == 034 assert report_failure.call_count == 035@patch('borg_summon.backup.report_failure')36@patch('borg_summon.backup.report_success')37@patch('borg_summon.borg.hook')38@patch('borg_summon.borg.create')39@patch('borg_summon.borg.init')40def test_filter_remote_call_create_error(init, create, hook, report_success, report_failure):41 # Setup42 arg_config = {43 'backup': {44 'sources': {45 's1': {46 'paths': ['/home'],47 },48 }49 },50 'remotes': {51 'r1': { 'location': 'path1' },52 'r2': { 'location': 'path2' },53 }54 }55 arg_source = []56 arg_remote = ['r2']57 arg_create = True58 create.side_effect = Exception()59 # Perform60 backup.main_inner(arg_config, arg_source, arg_remote, arg_create)61 # Assert62 assert init.call_count == 063 assert create.call_count == 164 assert create.call_args[0][1] == 'r2'65 assert create.call_args[0][2] == 's1'66 assert hook.call_count == 067 assert report_success.call_count == 068 assert report_failure.call_count == 169 assert report_failure.call_args[0][0].action == 'create'70 assert report_failure.call_args[0][0].target == ('s1', 'r2')71@patch('borg_summon.backup.report_failure')72@patch('borg_summon.backup.report_success')73@patch('borg_summon.borg.hook')74@patch('borg_summon.borg.create')75@patch('borg_summon.borg.init')76def test_init_error(init, create, hook, report_success, report_failure):77 # Setup78 arg_config = {79 'backup': {80 'sources': {81 's1': {82 'paths': ['/home'],83 },84 }85 },86 'remotes': {87 'r1': { 'location': 'path1' },88 }89 }90 arg_source = []91 arg_remote = []92 arg_create = False93 init.side_effect = Exception()94 # Perform95 backup.main_inner(arg_config, arg_source, arg_remote, arg_create)96 # Assert97 assert init.call_count == 198 assert init.call_args[0][1] == 'r1'99 assert init.call_args[0][2] == 's1'100 assert create.call_count == 0101 assert hook.call_count == 0102 assert report_success.call_count == 0103 assert report_failure.call_count == 1104 assert report_failure.call_args[0][0].action == 'init'105 assert report_failure.call_args[0][0].target == ('s1', 'r1')106@patch('borg_summon.backup.report_failure')107@patch('borg_summon.backup.report_success')108@patch('borg_summon.borg.hook')109@patch('borg_summon.borg.create')110@patch('borg_summon.borg.init')111def test_pre_create_hook_error(init, create, hook, report_success, report_failure):112 # Setup113 arg_config = {114 'backup': {115 'sources': {116 's1': {117 'paths': ['/home'],118 'pre_create_hook': { 'command': 'true' },119 'post_create_hook': { 'command': 'true' },120 },121 's2': {122 'paths': ['/home'],123 },124 }125 },126 'remotes': {127 'r1': { 'location': 'path1' },128 },129 }130 arg_source = []131 arg_remote = []132 arg_create = True133 hook.side_effect = [Exception(), None]134 # Perform135 backup.main_inner(arg_config, arg_source, arg_remote, arg_create)136 # Assert137 assert init.call_count == 0138 assert create.call_count == 1139 assert hook.call_count == 1140 assert report_success.call_count == 1141 assert report_failure.call_count == 3142@patch('borg_summon.backup.report_failure')143@patch('borg_summon.backup.report_success')144@patch('borg_summon.borg.hook')145@patch('borg_summon.borg.create')146@patch('borg_summon.borg.init')147def test_post_create_hook_error(init, create, hook, report_success, report_failure):148 # Setup149 arg_config = {150 'backup': {151 'sources': {152 's1': {153 'paths': ['/home'],154 },155 }156 },157 'remotes': {158 'r1': { 'location': 'path1' },159 },160 'pre_create_hook': { 'command': 'true' },161 'post_create_hook': { 'command': 'true' },162 }163 arg_source = []164 arg_remote = []165 arg_create = True166 hook.side_effect = [None, Exception]167 # Perform168 backup.main_inner(arg_config, arg_source, arg_remote, arg_create)169 # Assert170 assert init.call_count == 0171 assert create.call_count == 1172 assert hook.call_count == 2173 assert report_success.call_count == 2...

Full Screen

Full Screen

gdalident.py

Source:gdalident.py Github

copy

Full Screen

1#!/usr/bin/env python2#******************************************************************************3# $Id: gdalident.py 24064 2012-03-04 00:34:19Z warmerdam $4# 5# Project: GDAL6# Purpose: Application to identify files by format.7# Author: Frank Warmerdam, warmerdam@pobox.com8# 9#******************************************************************************10# Copyright (c) 2007, Frank Warmerdam <warmerdam@pobox.com>11# 12# Permission is hereby granted, free of charge, to any person obtaining a13# copy of this software and associated documentation files (the "Software"),14# to deal in the Software without restriction, including without limitation15# the rights to use, copy, modify, merge, publish, distribute, sublicense,16# and/or sell copies of the Software, and to permit persons to whom the17# Software is furnished to do so, subject to the following conditions:18# 19# The above copyright notice and this permission notice shall be included20# in all copies or substantial portions of the Software.21# 22# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS23# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,24# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL25# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER26# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING27# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER28# DEALINGS IN THE SOFTWARE.29#******************************************************************************30#31try:32 from osgeo import gdal33except ImportError:34 import gdal35import sys36import stat37import os38# =============================================================================39# Usage()40# =============================================================================41def Usage():42 print('Usage: gdalident.py [-r] file(s)')43 sys.exit(1)44# =============================================================================45# ProcessTarget()46# =============================================================================47def ProcessTarget( target, recursive, report_failure, filelist = None ):48 if filelist is not None:49 driver = gdal.IdentifyDriver( target, filelist )50 else:51 driver = gdal.IdentifyDriver( target )52 if driver is not None:53 print('%s: %s' % (target, driver.ShortName))54 elif report_failure:55 print('%s: unrecognised' % target)56 if recursive and driver is None:57 try:58 mode = os.stat(target)[stat.ST_MODE]59 except:60 mode = 061 if stat.S_ISDIR(mode):62 subfilelist = os.listdir(target)63 for item in subfilelist:64 subtarget = os.path.join(target,item)65 ProcessTarget( subtarget, 1, report_failure, subfilelist )66 67# =============================================================================68# Mainline69# =============================================================================70recursive = 071report_failure = 072files = []73gdal.AllRegister()74argv = gdal.GeneralCmdLineProcessor( sys.argv )75if argv is None:76 sys.exit( 0 )77# Parse command line arguments.78i = 179while i < len(argv):80 arg = argv[i]81 if arg == '-r':82 recursive = 183 elif arg == '-f':84 report_failure = 185 else:86 files.append(arg)87 i = i + 188if len(files) == 0:89 Usage()90for file in files:...

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