Best Python code snippet using slash
test_exception_handling.py
Source:test_exception_handling.py
...123 def setUp(self):124 super(DebuggingTest, self).setUp()125 self.forge.replace_with(debug, "launch_debugger", self.dummy_debugger)126 self.debugger_called = False127 def dummy_debugger(self, *args, **kwargs): # pylint: disable=unused-argument128 self.debugger_called = True129 def test_debugging_not_configured(self):130 self._raise_exception_in_context(ZeroDivisionError)131 self.assertFalse(self.debugger_called)132 def test_debugging_configured_no_skips(self):133 self.override_config("debug.debug_skips", False)134 self.override_config("debug.enabled", True)135 self._raise_exception_in_context(SkipTest)136 self.assertFalse(self.debugger_called)137 def test_debugging_skips(self):138 self.override_config("debug.debug_skips", True)139 self.override_config("debug.enabled", True)140 self._raise_exception_in_context(SkipTest)141 self.assertTrue(self.debugger_called)...
test.py
Source:test.py
1# -*- coding: utf-8 -*-2"""3Module developed for quick testing the OpenImageDebugger shared library4"""5import sys6import math7import time8import threading9import array10from oidscripts import oidwindow11from oidscripts import symbols12from oidscripts.debuggers.interfaces import BridgeInterface13def oidtest(script_path):14 """15 Entry point for the testing mode.16 """17 dummy_debugger = DummyDebugger()18 window = oidwindow.OpenImageDebuggerWindow(script_path, dummy_debugger)19 window.initialize_window()20 try:21 # Wait for window to initialize22 while not window.is_ready():23 time.sleep(0.1)24 window.set_available_symbols(dummy_debugger.get_available_symbols())25 for buffer in dummy_debugger.get_available_symbols():26 window.plot_variable(buffer)27 while window.is_ready():28 dummy_debugger.run_event_loop()29 time.sleep(0.1)30 except KeyboardInterrupt:31 window.terminate()32 exit(0)33 dummy_debugger.kill()34def _gen_color(pos, k, f_a, f_b):35 """36 Generates a color for the pixel at (pos[0], pos[1]) with coefficients k[0]37 and k[1], and colouring functions f_a and f_b that map R->[-1, 1].38 """39 p0 = float(pos[0])40 p1 = float(pos[1])41 return (f_a(p0 * f_b(p1/k[0])/k[1]) + 1.0) * 255.0 / 2.042def _gen_buffers(width, height):43 """44 Generate sample buffers45 """46 channels = [3, 1]47 types = [{'array': 'B', 'oid': symbols.OID_TYPES_UINT8},48 {'array': 'f', 'oid': symbols.OID_TYPES_FLOAT32}]49 tex1 = [0] * width * height * channels[0]50 tex2 = [0] * width * height * channels[1]51 c_x = width * 2.0 / 3.052 c_y = height * 0.553 scale = 3.0 / width54 for pos_y in range(0, height):55 for pos_x in range(0, width):56 # Buffer 1: Coloured set57 pixel_pos = [pos_x, pos_y]58 buffer_pos = pos_y * channels[0] * width + channels[0] * pos_x59 tex1[buffer_pos + 0] = _gen_color(60 pixel_pos, [20.0, 80.0], math.cos, math.cos)61 tex1[buffer_pos + 1] = _gen_color(62 pixel_pos, [50.0, 200.0], math.sin, math.cos)63 tex1[buffer_pos + 2] = _gen_color(64 pixel_pos, [30.0, 120.0], math.cos, math.cos)65 # Buffer 2: Mandelbrot set66 pixel_pos = complex((pos_x-c_x), (pos_y-c_y)) * scale67 buffer_pos = pos_y * channels[1] * width + channels[1] * pos_x68 mandel_z = complex(0, 0)69 for _ in range(0, 20):70 mandel_z = mandel_z * mandel_z + pixel_pos71 z_norm_squared = mandel_z.real * mandel_z.real +\72 mandel_z.imag * mandel_z.imag73 z_threshold = 5.074 for channel in range(0, channels[1]):75 tex2[buffer_pos + channel] = z_threshold - min(z_threshold,76 z_norm_squared)77 tex_arr1 = array.array(types[0]['array'], [int(val) for val in tex1])78 tex_arr2 = array.array(types[1]['array'], tex2)79 if sys.version_info[0] == 2:80 mem1 = buffer(tex_arr1)81 mem2 = buffer(tex_arr2)82 else:83 mem1 = memoryview(tex_arr1)84 mem2 = memoryview(tex_arr2)85 rowstride = width86 return {87 'sample_buffer_1': {88 'variable_name': 'sample_buffer_1',89 'display_name': 'uint8* sample_buffer_1',90 'pointer': mem1,91 'width': width,92 'height': height,93 'channels': channels[0],94 'type': types[0]['oid'],95 'row_stride': rowstride,96 'pixel_layout': 'rgba',97 'transpose_buffer': False98 },99 'sample_buffer_2': {100 'variable_name': 'sample_buffer_2',101 'display_name': 'float* sample_buffer_2',102 'pointer': mem2,103 'width': width,104 'height': height,105 'channels': channels[1],106 'type': types[1]['oid'],107 'row_stride': rowstride,108 'pixel_layout': 'rgba',109 'transpose_buffer': False110 }111 }112class DummyDebugger(BridgeInterface):113 """114 Very simple implementation of a debugger bridge for the sake of the test115 mode.116 """117 def __init__(self):118 width = 400119 height = 200120 self._buffers = _gen_buffers(width, height)121 self._buffer_names = [name for name in self._buffers]122 self._is_running = True123 self._incoming_request_queue = []124 def run_event_loop(self):125 if self._is_running:126 request_queue = self._incoming_request_queue127 self._incoming_request_queue = []128 while len(request_queue) > 0:129 latest_request = request_queue.pop(-1)130 latest_request()131 def kill(self):132 """133 Request consumer thread to finish its execution134 """135 self._is_running = False136 def get_casted_pointer(self, typename, debugger_object):137 """138 No need to cast anything in this example139 """140 return debugger_object141 def register_event_handlers(self, events):142 """143 No need to register events in this example144 """145 pass146 def get_available_symbols(self):147 """148 Return the names of the available sample buffers149 """150 return self._buffer_names151 def get_buffer_metadata(self, var_name):152 """153 Search in the list of available buffers and return the requested one154 """155 if var_name in self._buffers:156 return self._buffers[var_name]157 return None158 def get_backend_name(self): # type: () -> str159 return 'dummy'160 def queue_request(self, callable_request):...
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!!