How to use _call_function method in PyHamcrest

Best Python code snippet using PyHamcrest_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...173 f"Set{name}", _pack_value(typename, value)))174 return value175 def _set(self, value):176 if not implicit_write:177 self._call_function(f"Set{name}", _pack_value(typename, value))178 else:179 self._call_function_implicit(f"Set{name}", _pack_value(typename, value))180 if readonly:181 return property(_get)182 elif writeonly:183 return property(_set)184 else:185 return property(_get, _set)186# Finally we can define the object hierarchy. Each element of the object187# hierarchy has a `_call_function` method which handles adding the188# block/tile/toplevel arguments to the list of function parameters.189class RFdcThreshold:190 def __init__(self, parent, index):191 self._parent = parent192 self._index = index193 self._call_function = parent._call_function194 self._call_function_implicit = parent._call_function_implicit195 setattr(RFdcThreshold, '_settings',196 _create_c_property('ThresholdSettings', 'XRFdc_Threshold_Settings',197 False, False, True, True198 ))199 def SetClrMode(self, clr_mode):200 self._parent._call_function_implicit("SetThresholdClrMode", self._index+1, clr_mode)201 def StickyClear(self):202 self._parent._call_function_implicit("ThresholdStickyClear", self._index+1)203 @property204 def Settings(self):205 raw_settings = self._settings206 return {207 'ThresholdMode' : raw_settings['ThresholdMode' ][self._index],208 'ThresholdAvgVal' : raw_settings['ThresholdAvgVal' ][self._index],209 'ThresholdUnderVal': raw_settings['ThresholdUnderVal'][self._index],210 'ThresholdOverVal' : raw_settings['ThresholdOverVal' ][self._index]211 }212 @Settings.setter213 def Settings(self, settings):214 kpack = lambda x, i : [x,0] if i==0 else [0,x]215 self._settings = {216 'UpdateThreshold' : self._index+1,217 'ThresholdMode' : kpack(settings['ThresholdMode' ], self._index),218 'ThresholdAvgVal' : kpack(settings['ThresholdAvgVal' ], self._index),219 'ThresholdUnderVal': kpack(settings['ThresholdUnderVal'], self._index),220 'ThresholdOverVal' : kpack(settings['ThresholdOverVal' ], self._index)221 }222class RFdcBlock:223 def __init__(self, parent, index):224 self._parent = parent225 self._index = index226 def _call_function(self, name, *args):227 return self._parent._call_function(name, self._index, *args)228 229 def ResetNCOPhase(self):230 self._call_function("ResetNCOPhase")231 def UpdateEvent(self, Event):232 self._call_function("UpdateEvent", Event)233 234 def ResetInternalFIFOWidth(self):235 self._call_function("ResetInternalFIFOWidth")236 237 def GetConnectedIData(self):238 self._call_function("GetConnectedIData")239 240 def GetConnectedQData(self):241 self._call_function("GetConnectedQData")242class RFdcDacBlock(RFdcBlock):243 def __init__(self, *args, **kwargs):244 super().__init__(*args, **kwargs)245 def _call_function_implicit(self, name, *args):246 return self._parent._call_function_implicit(name, self._index, *args)247 248 def SetDACVOP(self, uACurrent):249 self._call_function_implicit("SetDACVOP", uACurrent)250class RFdcAdcBlock(RFdcBlock):251 def __init__(self, *args, **kwargs):252 super().__init__(*args, **kwargs)253 self.thresholds = [RFdcThreshold(self, i) for i in range(2)]254 def _call_function_implicit(self, name, *args):255 return self._parent._call_function_implicit(name, self._index, *args)256 257 def DisableCoefficientsOverride(self, CalibrationBlock):258 self._call_function_implicit("DisableCoefficientsOverride", CalibrationBlock)259 260 def ResetInternalFIFOWidthObs(self):261 self._call_function("ResetInternalFIFOWidthObs")262 263 def SetCalCoefficients(self, CalibrationBlock, *CoeffPtr):264 self._call_function_implicit("SetCalCoefficients", CalibrationBlock, *CoeffPtr)265 266 def GetCalCoefficients(self, CalibrationBlock, *CoeffPtr):267 self._call_function_implicit("GetCalCoefficients", CalibrationBlock, *CoeffPtr)268class RFdcTile:269 def __init__(self, parent, index):270 self._index = index271 self._parent = parent272 def _call_function(self, name, *args):273 return self._parent._call_function(name, self._type, self._index, *args)274 def _call_function_implicit(self, name, *args):275 return self._parent._call_function(name, self._index, *args)276 def StartUp(self):277 self._call_function("StartUp")278 def ShutDown(self):279 self._call_function("Shutdown")280 def Reset(self):281 self._call_function("Reset")282 283 def SetupFIFO(self, Enable):284 self._call_function("SetupFIFO", Enable)285 def DumpRegs(self):286 self._call_function("DumpRegs")287 def DynamicPLLConfig(self, source, ref_clk_freq, samp_rate):288 self._call_function("DynamicPLLConfig", source, ref_clk_freq, samp_rate)289class RFdcDacTile(RFdcTile):290 def __init__(self, *args):291 super().__init__(*args)292 self._type = _lib.XRFDC_DAC_TILE293 self.blocks = [RFdcDacBlock(self, i) for i in range(4)]294class RFdcAdcTile(RFdcTile):295 def __init__(self, *args):296 super().__init__(*args)297 self._type = _lib.XRFDC_ADC_TILE298 self.blocks = [RFdcAdcBlock(self, i) for i in range(4)]299 300 def SetupFIFOObs(self, Enable):301 self._call_function("SetupFIFOObs", Enable)302 303 def SetupFIFOBoth(self, Enable):304 self._call_function("SetupFIFOBoth", Enable)305 306 def GetFIFOStatusObs(self, *EnablePtr):307 self._call_function("GetFIFOStatusObs", *EnablePtr)308class RFdc(pynq.DefaultIP):309 bindto = ["xilinx.com:ip:usp_rf_data_converter:2.4", 310 "xilinx.com:ip:usp_rf_data_converter:2.3"]311 def __init__(self, description):312 super().__init__(description)313 if 'parameters' in description:314 from .config import populate_config315 self._config = _ffi.new('XRFdc_Config*')316 populate_config(self._config, description['parameters'])317 pass318 else:319 warnings.warn("Please use an hwh file with the RFSoC driver"320 " the driver cannot be loaded")321 raise pynq.UnsupportedConfiguration()322 self._instance = _ffi.new("XRFdc*")323 self._config.BaseAddr = self.mmio.array.ctypes.data324 _lib.XRFdc_CfgInitialize(self._instance, self._config)325 self.adc_tiles = [RFdcAdcTile(self, i) for i in range(4)]326 self.dac_tiles = [RFdcDacTile(self, i) for i in range(4)]327 def _call_function(self, name, *args):328 _safe_wrapper(f"XRFdc_{name}", self._instance, *args)329# Finally we can add our data-driven properties to each class in the hierarchy330for (name, typename, readonly) in _block_props:331 setattr(RFdcBlock, name, _create_c_property(name, typename, readonly))332for (name, typename, readonly, writeonly, implicit_read, implicit_write) in _adc_props:333 setattr(RFdcAdcBlock, name, _create_c_property(name, typename, readonly, writeonly,334 implicit_read, implicit_write))335for (name, typename, readonly, writeonly, implicit_read, implicit_write) in _dac_props:336 setattr(RFdcDacBlock, name, _create_c_property(name, typename, readonly, writeonly,337 implicit_read, implicit_write))338for (name, typename, readonly) in _tile_props:339 setattr(RFdcTile, name, _create_c_property(name, typename, readonly))340for (name, typename, readonly) in _rfdc_props:341 setattr(RFdc, name, _create_c_property(name, typename, readonly))...

Full Screen

Full Screen

test_module.py

Source:test_module.py Github

copy

Full Screen

...342 {"testfunc": lambda a, b, c, *args, **kwargs: (a, b, c, args, kwargs)},343 clear=True,344 ):345 self.assertEqual(346 module._call_function(347 "testfunc", func_args=[{"a": 1}, {"b": 2}, {"c": 3}]348 ),349 (1, 2, 3, (), {}),350 )351 self.assertEqual(352 module._call_function(353 "testfunc", func_args=[{"c": 3}, {"a": 1}, {"b": 2}]354 ),355 (1, 2, 3, (), {}),356 )357 self.assertEqual(358 module._call_function("testfunc", func_kwargs={"a": 1, "b": 2, "c": 3}),359 (1, 2, 3, (), {}),360 )361 self.assertEqual(362 module._call_function("testfunc", func_kwargs={"c": 3, "a": 1, "b": 2}),363 (1, 2, 3, (), {}),364 )365 self.assertEqual(366 module._call_function("testfunc", func_kwargs={"b": 2, "a": 1, "c": 3}),367 (1, 2, 3, (), {}),368 )369 self.assertEqual(370 module._call_function("testfunc", func_kwargs={"a": 1, "c": 3, "b": 2}),371 (1, 2, 3, (), {}),372 )373 with patch.dict(374 module.__salt__,375 {"testfunc": lambda c, a, b, *args, **kwargs: (a, b, c, args, kwargs)},376 clear=True,377 ):378 self.assertEqual(379 module._call_function(380 "testfunc", func_args=[{"a": 1}, {"b": 2}, {"c": 3}]381 ),382 (1, 2, 3, (), {}),383 )384 self.assertEqual(385 module._call_function(386 "testfunc", func_args=[{"c": 3}, {"a": 1}, {"b": 2}]387 ),388 (1, 2, 3, (), {}),389 )390 self.assertEqual(391 module._call_function("testfunc", func_kwargs={"a": 1, "b": 2, "c": 3}),392 (1, 2, 3, (), {}),393 )394 self.assertEqual(395 module._call_function("testfunc", func_kwargs={"c": 3, "a": 1, "b": 2}),396 (1, 2, 3, (), {}),397 )398 self.assertEqual(399 module._call_function("testfunc", func_kwargs={"b": 2, "a": 1, "c": 3}),400 (1, 2, 3, (), {}),401 )402 self.assertEqual(403 module._call_function("testfunc", func_kwargs={"a": 1, "c": 3, "b": 2}),404 (1, 2, 3, (), {}),405 )406 def test_call_function_ordered_args(self):407 """408 Test _call_function routine when params are not named. Their position should matter.409 :return:410 """411 with patch.dict(412 module.__salt__,413 {"testfunc": lambda a, b, c, *args, **kwargs: (a, b, c, args, kwargs)},414 clear=True,415 ):416 self.assertEqual(417 module._call_function("testfunc", func_args=[1, 2, 3]),418 (1, 2, 3, (), {}),419 )420 self.assertEqual(421 module._call_function("testfunc", func_args=[3, 1, 2]),422 (3, 1, 2, (), {}),423 )424 def test_call_function_ordered_and_named_args(self):425 """426 Test _call_function routine when params are not named. Their position should matter.427 :return:428 """429 with patch.dict(430 module.__salt__,431 {"testfunc": lambda a, b, c, *args, **kwargs: (a, b, c, args, kwargs)},432 clear=True,433 ):434 self.assertEqual(435 module._call_function(436 "testfunc", func_args=[1], func_kwargs={"b": 2, "c": 3}437 ),438 (1, 2, 3, (), {}),439 )440 self.assertEqual(441 module._call_function(442 "testfunc", func_args=[1, 2], func_kwargs={"c": 3}443 ),444 (1, 2, 3, (), {}),...

Full Screen

Full Screen

docker_controller.py

Source:docker_controller.py Github

copy

Full Screen

...22 '''23 @staticmethod24 def docker_controller_open_sftp(**kwargs):25 func = open_sftp26 return _call_function(func, **kwargs)27 '''28 @staticmethod29 def docker_controller_client_info(**kwargs):30 func = client_info31 return _call_function(func, **kwargs)32 @staticmethod33 def docker_controller_list_containers(**kwargs):34 func = list_containers35 return _call_function(func, **kwargs)36 @staticmethod37 def docker_controller_containers_id(**kwargs):38 func = containers_id39 return _call_function(func, **kwargs)40 @staticmethod41 def docker_controller_containers_images(**kwargs):42 func = containers_images43 return _call_function(func, **kwargs)44 @staticmethod45 def docker_controller_list_images(**kwargs):46 func = list_images47 return _call_function(func, **kwargs)48 @staticmethod49 def docker_controller_containers_status(**kwargs):50 func = containers_status51 return _call_function(func, **kwargs)52 @staticmethod53 def docker_controller_kill_container(**kwargs):54 func = kill_container55 return _call_function(func, **kwargs)56 @staticmethod57 def docker_controller_container_stats(**kwargs):58 func = container_stats59 return _call_function(func, **kwargs)60 @staticmethod61 def docker_controller_remove_container(**kwargs):62 func = remove_container63 return _call_function(func, **kwargs)64 @staticmethod65 def docker_controller_rename_container(**kwargs):66 func = rename_container67 return _call_function(func, **kwargs)68 @staticmethod69 def docker_controller_containers_info(**kwargs):70 func = containers_info71 return _call_function(func, **kwargs)72 @staticmethod73 def docker_controller_images_info(**kwargs):74 func = images_info75 return _call_function(func, **kwargs)76 @staticmethod77 def docker_controller_inspect_image(**kwargs):78 func = inspect_image79 return _call_function(func, **kwargs)80 @staticmethod81 def docker_controller_commit(**kwargs):82 func = commit83 return _call_function(func, **kwargs)84 @staticmethod85 def docker_controller_save_image(**kwargs):86 func = save_image87 return _call_function(func, **kwargs)88 @staticmethod89 def docker_controller_remove_image(**kwargs):90 func = remove_image91 return _call_function(func, **kwargs)92 @staticmethod93 def docker_controller_export_container(**kwargs):94 func = export_container95 return _call_function(func, **kwargs)96 @staticmethod97 def docker_controller_create_image(**kwargs):98 func = create_image99 return _call_function(func, **kwargs)100 @staticmethod101 def docker_controller_pull_image(**kwargs):102 func = pull_image103 return _call_function(func, **kwargs)104 @staticmethod105 def docker_controller_create_container(**kwargs):106 func = create_container107 return _call_function(func, **kwargs)108 @staticmethod109 def docker_controller_change_status(**kwargs):110 func = change_status111 return _call_function(func, **kwargs)112 @staticmethod113 def docker_controller_inspect_container(**kwargs):114 func = inspect_container115 return _call_function(func, **kwargs)116 @staticmethod117 def docker_controller_list_networks(**kwargs):118 func = list_networks119 return _call_function(func, **kwargs)120 @staticmethod121 def docker_controller_inspect_network(**kwargs):122 func = inspect_network123 return _call_function(func, **kwargs)124 @staticmethod125 def docker_controller_create_network(**kwargs):126 func = create_network127 return _call_function(func, **kwargs)128 @staticmethod129 def docker_controller_connect_container(**kwargs):130 func = connect_container131 return _call_function(func, **kwargs)132 @staticmethod133 def docker_controller_disconnect_container(**kwargs):134 func = disconnect_container135 return _call_function(func, **kwargs)136 @staticmethod137 def docker_controller_remove_network(**kwargs):138 func = remove_network139 return _call_function(func, **kwargs)140 @staticmethod141 def docker_controller_create_volume(**kwargs):142 func = create_volume143 return _call_function(func, **kwargs)144 @staticmethod145 def docker_controller_list_volumes(**kwargs):146 func = list_volumes147 return _call_function(func, **kwargs)148 @staticmethod149 def docker_controller_inspect_volume(**kwargs):150 func = inspect_volume151 return _call_function(func, **kwargs)152 @staticmethod153 def docker_controller_remove_volume(**kwargs):154 func = remove_volume155 return _call_function(func, **kwargs)156# =====================================private functions======================#157def _call_function(func, **kwargs):158 body = kwargs['body']159 params = signature(func).parameters160 relevent_kwargs = {}161 for param in params:162 if params[param].default == Parameter.empty:163 try:164 relevent_kwargs[param] = body[param]165 except KeyError:166 raise KeyError('missing argument' + param + 'in call to ' + func.__name__)167 else:168 relevent_kwargs[param] = body.get(param, params[param].default)169 return func(**relevent_kwargs)170#===============================private functions end=======================================171#========================docker client===========================...

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