How to use format_exception_info method in Testify

Best Python code snippet using Testify_python

vdrnfofs.py

Source:vdrnfofs.py Github

copy

Full Screen

...38from vdrnfofs.vdr import *39from vdrnfofs.filesystemnodes import *40from vdrnfofs.nodecache import *41fuse.fuse_python_api = (0, 2)42def format_exception_info(level = 6):43 error_type, error_value, trbk = sys.exc_info()44 tb_list = traceback.format_tb(trbk, level)45 return 'Error: %s \nDescription: %s \nTraceback: %s' % (error_type.__name__, error_value, '\n'.join(tb_list))46def get_node(video, path):47 virtual_path, virtual_file_extension = os.path.splitext(path)48 if virtual_file_extension in ['.mpg', '.nfo']:49 p = virtual_path.rfind('_')50 if p > 0:51 video_path = '/'.join((video, virtual_path[1:p], virtual_path[p+1:]))52 if not os.path.isdir(video_path):53 return None54 elif virtual_file_extension == '.mpg':55 return MpgNode(video_path)56 elif virtual_file_extension == '.nfo':57 return NfoNode(video_path)58 else:59 dir = video + path60 if os.path.isdir(dir):61 return DirNode(dir)62 return None63class VdrNfoFsFile:64 def __init__(self, path, flags, *mode):65 self.path = path66 self.node = get_node(VdrNfoFsFile.video_root, path)67 self.keep_cache = True68 self.direct_io = False69 def read(self, size, offset):70 try:71 if not self.node:72 return -errno.ENOENT73 return self.node.read(offset, size)74 except:75 logging.error('VdrFuseFs: Unexpected error for read(%s): %s, %s' % (self.path, format_exception_info()))76 def release(self, flags):77 self.node.release()78# def write(self, buf, offset):79# return 080# def _fflush(self):81# if 'w' in self.file.mode or 'a' in self.file.mode:82# self.file.flush()83# def fsync(self, isfsyncfile):84# def flush(self):85# def fgetattr(self):86# return 087# def ftruncate(self, len):88# def lock(self, cmd, owner, **kw):89class VdrNfoFs(fuse.Fuse):90 def __init__(self, *args, **kw):91 fuse.Fuse.__init__(self, *args, **kw)92 self.video = ''93 self.log = ''94 self.loglevel = 'info'95 self.cache = NodeCache()96 def getattr(self, path):97 try:98 node = self.cache.get(path, lambda x: get_node(self.video, x))99 if node:100 return node.get_stat()101 return -errno.ENOENT102 except:103 logging.error('VdrFuseFs: Unexpected error for getattr(%s): %s' % (path, format_exception_info()))104 def readdir(self, path, offset):105 try:106 yield fuse.Direntry('.')107 yield fuse.Direntry('..')108 node = self.cache.get(path, lambda x: get_node(self.video, x))109 if node:110 for item in node.content():111 yield fuse.Direntry(item.file_system_name())112 except:113 logging.error('VdrFuseFs: Unexpected error for readdir(%s): %s' % (path, format_exception_info()))114 def main(self, *a, **kw):115 if self.log and self.log != None:116 logging.basicConfig(filename=self.log, level=getattr(logging, self.loglevel.upper()))117 else:118 logging.basicConfig(level=self.loglevel.upper())119 logging.info('Starting vdrnfofs')120 VdrNfoFsFile.video_root = self.video121 self.file_class = VdrNfoFsFile122 return fuse.Fuse.main(self, *a, **kw)123def main():124 usage = "\nVDR-NFO-FS - access VDR recordings as mpg and nfo files\n"125 usage += fuse.Fuse.fusage126 version = "%prog " + fuse.__version__127 fs = VdrNfoFs(version=version, usage=usage, dash_s_do='setsingle')...

Full Screen

Full Screen

test_result_test.py

Source:test_result_test.py Github

copy

Full Screen

...33 tb.configure_mock(**{'tb_frame.f_globals': f_globals})34 tb.tb_next = None35 tb = root_tb.tb_next36 test_result.end_in_failure((AssertionError, 'wat', tb))37 formatted = test_result.format_exception_info()38 assert_equal(formatted, 'Traceback: AssertionError\n')39 # It should format three frames of the stack, starting with the third frame.40 mock_format_exception.assert_called_with(AssertionError, 'wat', tb.tb_next.tb_next, 3)41 @mock.patch('traceback.format_exception', wraps=fake_format_exception)42 def test_format_exception_info_assertion(self, mock_format_exception):43 value, tb = self._append_exc_info(AssertionError)44 formatted = self.test_result.format_exception_info()45 mock_format_exception.assert_called_with(AssertionError, value, tb, 1)46 assert_equal(formatted, 'Traceback: AssertionError\n')47 @mock.patch('traceback.format_exception', wraps=fake_format_exception)48 def test_format_exception_info_error(self, mock_format_exception):49 value, tb = self._append_exc_info(ValueError)50 formatted = self.test_result.format_exception_info()51 mock_format_exception.assert_called_with(ValueError, value, tb, None)52 assert_equal(formatted, 'Traceback: ValueError\n')53 @mock.patch('traceback.format_exception', wraps=fake_format_exception)54 def test_format_exception_info_multiple(self, mock_format_exception):55 class Error1(Exception):56 pass57 class Error2(Exception):58 pass59 value1, tb1 = self._append_exc_info(Error1)60 value2, tb2 = self._append_exc_info(Error2)61 formatted = self.test_result.format_exception_info()62 mock_format_exception.assert_has_calls([63 mock.call(Error1, value1, tb1, None),64 mock.call(Error2, value2, tb2, None),65 ])66 assert_equal(67 formatted,68 (69 'Traceback: Error1\n'70 '\n'71 'During handling of the above exception, another exception occurred:\n'72 '\n'73 'Traceback: Error2\n'74 )75 )...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

...61 return HttpResponse(status=204, mimetype='application/javascript')62 63 return render_to_response('landing/message.js', {'filters': filters}, mimetype='application/javascript')64 except WrongWebsite:65 exc = format_exception_info()66 logging.info('wrong website: %s;%s;' % (exc[0], exc[1]), exc_info=sys.exc_info() )67 return bare_404(request)68 except:69 exc = format_exception_info()70 logging.error('Error in get_messages: %s;%s;' % (exc[0], exc[1]), exc_info=sys.exc_info() )71 return HttpResponseServerError() 72def bare_404(request):73 return HttpResponseNotFound('Not found')74def filter_fired(request):75 try:76 #retrieve required request parameters77 token = request.GET.get('t', None) 78 uid = request.GET.get('u', False) 79 80 request.redis = get_redis()81 82 #store the view83 store_page_view(location, client_identifier, token, new_visit, view_date, filters)84 85 if len(filters) == 0:86 return HttpResponse(status=204, mimetype='application/javascript')87 88 return render_to_response('landing/message.js', {'filters': filters}, mimetype='application/javascript')89 except WrongWebsite:90 exc = format_exception_info()91 logging.info('wrong website: %s;%s;' % (exc[0], exc[1]), exc_info=sys.exc_info() )92 return bare_404(request)93 except:94 exc = format_exception_info()95 logging.error('Error in get_messages: %s;%s;' % (exc[0], exc[1]), exc_info=sys.exc_info() )...

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