How to use add_example method in pytest-bdd

Best Python code snippet using pytest-bdd_python

linphone-daemon.py

Source:linphone-daemon.py Github

copy

Full Screen

...47 self.proto = proto48 self.examples = []49 def exec_command(self, app, args):50 pass51 def add_example(self, example):52 self.examples.append(example)53 def help(self):54 body = \55"""{proto}56Description:57{description}58""".format(proto=self.proto, description=self.__doc__)59 idx = 060 for example in self.examples:61 idx += 162 body += \63"""64Example {idx}:65{example}66""".format(idx=idx, example=str(example))67 return body68class CallCommand(Command):69 """Place a call."""70 def __init__(self):71 Command.__init__(self, "call", "call <sip-address>")72 self.add_example(CommandExample(73 "call daemon-test@sip.linphone.org",74 "Status: Ok\n\nId: 1"75 ))76 self.add_example(CommandExample(77 "call daemon-test@sip.linphone.org",78 "Status: Error\nReason: Call creation failed."79 ))80 def exec_command(self, app, args):81 if len(args) >= 1:82 call = app.core.invite(args[0])83 if call is None:84 app.send_response(Response(Response.Error, "Call creation failed."))85 else:86 id = app.update_call_id(call)87 app.send_response(Response(Response.Ok, "Id: " + str(id)))88 else:89 app.send_response(Response(Response.Error, "Missing parameter."))90class CallPauseCommand(Command):91 """Pause a call (pause current if no id is specified)."""92 def __init__(self):93 Command.__init__(self, "call-pause", "call-pause [call-id]")94 self.add_example(CommandExample(95 "call-pause 1",96 "Status: Ok\n\nCall was paused"97 ))98 self.add_example(CommandExample(99 "call-pause 2",100 "Status: Error\nReason: No call with such id."101 ))102 self.add_example(CommandExample(103 "call-pause",104 "Status: Error\nReason: No current call available."105 ))106 def exec_command(self, app, args):107 current = False108 if len(args) >= 1:109 call = app.find_call(args[0])110 if call is None:111 app.send_response(Response(Response.Error, "No call with such id."))112 return113 else:114 current = True115 call = app.core.current_call116 if call is None:117 app.send_response(Response(Response.Error, "No current call available."))118 return119 if app.core.pause_call(call) == 0:120 msg = "Call was paused."121 if current:122 msg = "Current call was paused."123 app.send_response(Response(Response.Ok, msg))124 else:125 app.send_response(Response(Response.Error, "Error pausing call."))126class CallResumeCommand(Command):127 """Resume a call (resume current if no id is specified)."""128 def __init__(self):129 Command.__init__(self, "call-resume", "call-resume [call-id]")130 self.add_example(CommandExample(131 "call-resume 1",132 "Status: Ok\n\nCall was resumed"133 ))134 self.add_example(CommandExample(135 "call-resume 2",136 "Status: Error\nReason: No call with such id."137 ))138 self.add_example(CommandExample(139 "call-resume",140 "Status: Error\nReason: No current call available."141 ))142 def exec_command(self, app, args):143 current = False144 if len(args) >= 1:145 call = app.find_call(args[0])146 if call is None:147 app.send_response(Response(Response.Error, "No call with such id."))148 return149 else:150 current = True151 call = app.core.current_call152 if call is None:153 app.send_response(Response(Response.Error, "No current call available."))154 return155 if app.core.resume_call(call) == 0:156 msg = "Call was resumed."157 if current:158 msg = "Current call was resumed."159 app.send_response(Response(Response.Ok, msg))160 else:161 app.send_response(Response(Response.Error, "Error resuming call."))162class CallStatusCommand(Command):163 """Return status of the specified call or of the current call if no id is given."""164 def __init__(self):165 Command.__init__(self, "call-status", "call-status [call-id]")166 self.add_example(CommandExample(167 "call-status 1",168 "Status: Ok\n\nState: LinphoneCallStreamsRunning\nFrom: <sip:daemon-test@sip.linphone.org>\nDirection: out\nDuration: 6"169 ))170 self.add_example(CommandExample(171 "call-status 2",172 "Status: Error\nReason: No call with such id."173 ))174 self.add_example(CommandExample(175 "call-status",176 "Status: Error\nReason: No current call available."177 ))178 def exec_command(self, app, args):179 if len(args) >= 1:180 call = app.find_call(args[0])181 if call is None:182 app.send_response(Response(Response.Error, "No call with such id."))183 return184 else:185 call = app.core.current_call186 if call is None:187 app.send_response(Response(Response.Error, "No current call available."))188 return189 state = call.state190 body = "State: {state}".format(state=linphone.CallState.string(state))191 if state == linphone.CallState.CallOutgoingInit \192 or state == linphone.CallState.CallOutgoingProgress \193 or state == linphone.CallState.CallOutgoingRinging \194 or state == linphone.CallState.CallPaused \195 or state == linphone.CallState.CallStreamsRunning \196 or state == linphone.CallState.CallConnected \197 or state == linphone.CallState.CallIncomingReceived:198 body += "\nFrom: {address}".format(address=call.remote_address.as_string())199 if state == linphone.CallState.CallStreamsRunning \200 or state == linphone.CallState.CallConnected:201 direction_str = 'in'202 if call.dir == linphone.CallDir.CallOutgoing:203 direction_str = 'out'204 body += "\nDirection: {direction}\nDuration: {duration}".format(direction=direction_str, duration=call.duration)205 app.send_response(Response(Response.Ok, body))206class HelpCommand(Command):207 """Show <command> help notice, if command is unspecified or inexistent show all commands."""208 def __init__(self):209 Command.__init__(self, "help", "help <command>")210 def exec_command(self, app, args):211 body = ''212 if args:213 command = [item for item in app.commands if item.name == args[0]]214 if command:215 body = command[0].help()216 else:217 app.send_response(Response(Response.Error, "Unknown command '{command}'.".format(command=args[0])))218 return219 else:220 for command in app.commands:221 body += command.proto + '\n'222 app.send_response(Response(Response.Ok, body))223class QuitCommand(Command):224 """Quit the application."""225 def __init__(self):226 Command.__init__(self, "quit", "quit")227 def exec_command(self, app, args):228 app.quit()229 app.send_response(Response(Response.Ok))230class RegisterCommand(Command):231 """Register the daemon to a SIP proxy. If one of the parameters <password>, <userid> and <realm> is not needed, send the string "NULL"."""232 def __init__(self):233 Command.__init__(self, "register", "register <identity> <proxy-address> [password] [userid] [realm] [contact-parameters]")234 self.add_example(CommandExample(235 "register sip:daemon-test@sip.linphone.org sip.linphone.org password bob linphone.org",236 "Status: Ok\n\nId: 1"237 ))238 def exec_command(self, app, args):239 if len(args) >= 2:240 password = None241 userid = None242 realm = None243 contact_parameters = None244 identity = args[0]245 proxy = args[1]246 if len(args) > 2 and args[2] != "NULL":247 password = args[2]248 if len(args) > 3 and args[3] != "NULL":249 userid = args[3]250 if len(args) > 4 and args[4] != "NULL":251 realm = args[4]252 if len(args) > 5 and args[5] != "NULL":253 contact_parameters = args[5]254 proxy_cfg = app.core.create_proxy_config()255 if password is not None:256 addr = linphone.Address.new(identity)257 if addr is not None:258 info = linphone.AuthInfo.new(addr.username, userid, password, None, realm, None)259 app.core.add_auth_info(info)260 print(info)261 proxy_cfg.identity = identity262 proxy_cfg.server_addr = proxy263 proxy_cfg.register_enabled = True264 proxy_cfg.contact_parameters = contact_parameters265 app.core.add_proxy_config(proxy_cfg)266 id = app.update_proxy_id(proxy_cfg)267 app.send_response(Response(Response.Ok, "Id: " + str(id)))268 else:269 app.send_response(Response(Response.Error, "Missing/Incorrect parameter(s)."))270class RegisterStatusCommand(Command):271 """Return status of a registration or of all registrations."""272 def __init__(self):273 Command.__init__(self, "register-status", "register-status <register_id|ALL>")274 self.add_example(CommandExample(275 "register-status 1",276 "Status: Ok\n\nId: 1\nState: LinphoneRegistrationOk"277 ))278 self.add_example(CommandExample(279 "register-status ALL",280 "Status: Ok\n\nId: 1\nState: LinphoneRegistrationOk\n\nId: 2\nState: LinphoneRegistrationFailed"281 ))282 self.add_example(CommandExample(283 "register-status 3",284 "Status: Error\nReason: No register with such id."285 ))286 def exec_command(self, app, args):287 if len(args) == 0:288 app.send_response(Response(Response.Error, "Missing parameter."))289 else:290 id = args[0]291 if id == "ALL":292 response = RegisterStatusResponse()293 for id in app.proxy_ids_map:294 response.append(id, app.proxy_ids_map[id])295 app.send_response(response)296 else:297 proxy_cfg = app.find_proxy(id)298 if proxy_cfg is None:299 app.send_response(Response(Response.Error, "No register with such id."))300 else:301 app.send_response(RegisterStatusResponse().append(id, proxy_cfg))302class TerminateCommand(Command):303 """Terminate the specified call or the current call if no id is given."""304 def __init__(self):305 Command.__init__(self, "terminate", "terminate [call id]")306 self.add_example(CommandExample(307 "terminate 2",308 "Status: Error\nReason: No call with such id."309 ))310 self.add_example(CommandExample(311 "terminate 1",312 "Status: Ok\n"313 ))314 self.add_example(CommandExample(315 "terminate",316 "Status: Ok\n"317 ))318 self.add_example(CommandExample(319 "terminate",320 "Status: Error\nReason: No active call."321 ))322 def exec_command(self, app, args):323 if len(args) >= 1:324 call = app.find_call(args[0])325 if call is None:326 app.send_response(Response(Response.Error, "No call with such id."))327 return328 else:329 call = app.core.current_call330 if call is None:331 app.send_response(Response(Response.Error, "No active call."))332 return...

Full Screen

Full Screen

generic_bindings_generator.py

Source:generic_bindings_generator.py Github

copy

Full Screen

...30 la_backend_eigen = 'Dune::Stuff::LA::ChooseBackend::eigen_sparse'31 la_backend_istl = 'Dune::Stuff::LA::ChooseBackend::istl_sparse'32 space_backend_pdelab = 'Dune::GDT::ChooseSpaceBackend::pdelab'33 space_backend_fem = 'Dune::GDT::ChooseSpaceBackend::fem'34 def add_example(GridType, space_backend, la_backend, name):35 # build all types needed for the discretization36 dimRange = '1'37 polOrder = '1'38 grid_layer = 'Dune::Stuff::Grid::ChooseLayer::leaf'39 MatrixType = 'Dune::Stuff::LA::'40 VectorType = 'Dune::Stuff::LA::'41 if 'eigen_sparse' in la_backend:42 MatrixType += 'EigenRowMajorSparseMatrix'43 VectorType += 'EigenDenseVector'44 elif 'istl_sparse' in la_backend:45 MatrixType += 'IstlRowMajorSparseMatrix'46 VectorType += 'IstlDenseVector'47 MatrixType += '< ' + RangeFieldType + ' >'48 VectorType += '< ' + RangeFieldType + ' >'49 OperatorType = 'Dune::Pymor::Operators::LinearAffinelyDecomposedContainerBased< ' + MatrixType + ', ' + VectorType + ' >'50 ProductType = OperatorType51 FunctionalType = 'Dune::Pymor::Functionals::LinearAffinelyDecomposedVectorBased< ' + VectorType + ' >'52 DiscretizationName = 'Dune::HDD::LinearElliptic::Discretizations::CG'53 DiscretizationType = (DiscretizationName + '< '54 + GridType + ', ' + grid_layer + ', '55 + RangeFieldType + ', '56 + dimRange + ', ' + polOrder + ', '57 + space_backend + ', ' + la_backend + '>')58 inject_StationaryDiscretizationImplementation(module, exceptions, interfaces, CONFIG_H,59 DiscretizationName,60 Traits={'VectorType': VectorType,61 'OperatorType': OperatorType,62 'FunctionalType': FunctionalType,63 'ProductType': ProductType},64 template_parameters=[GridType, grid_layer, RangeFieldType,65 dimRange, polOrder, space_backend, la_backend])66 # then create the example67 Example = module.add_class('PbGenericLinearellipticExample', template_parameters=[GridType, space_backend, la_backend], custom_name=name)68 Example.add_method('logger_options',69 retval('Dune::Stuff::Common::Configuration'),70 [], is_static=True, throw=exceptions)71 Example.add_method('grid_options',72 retval('std::vector< std::string >'),73 [], is_static=True, throw=exceptions)74 Example.add_method('grid_options',75 retval('Dune::Stuff::Common::Configuration'),76 [param('const std::string&', 'type')], is_static=True, throw=exceptions)77 Example.add_method('boundary_options',78 retval('std::vector< std::string >'),79 [], is_static=True, throw=exceptions)80 Example.add_method('boundary_options',81 retval('Dune::Stuff::Common::Configuration'),82 [param('const std::string&', 'type')], is_static=True, throw=exceptions)83 Example.add_method('problem_options',84 retval('std::vector< std::string >'),85 [], is_static=True, throw=exceptions)86 Example.add_method('problem_options',87 retval('Dune::Stuff::Common::Configuration'),88 [param('const std::string&', 'type')], is_static=True, throw=exceptions)89 Example.add_method('solver_options',90 retval('std::vector< std::string >'),91 [], is_static=True, throw=exceptions)92 Example.add_method('solver_options',93 retval('Dune::Stuff::Common::Configuration'),94 [param('const std::string&', 'type')], is_static=True, throw=exceptions)95 Example.add_constructor([param('const Dune::Stuff::Common::Configuration&', 'logger_cfg'),96 param('const Dune::Stuff::Common::Configuration&', 'grid_cfg'),97 param('const Dune::Stuff::Common::Configuration&', 'boundary_cfg'),98 param('const Dune::Stuff::Common::Configuration&', 'problem_cfg')],99 throw=exceptions)100 Example.add_method('pb_discretization_and_return_ptr',101 retval(DiscretizationType + ' *', caller_owns_return=True),102 [], is_const=True, throw=exceptions,103 custom_name='discretization')104 Example.add_method('project',105 retval(VectorType),106 [param('const std::string', 'expression')], is_const=True, throw=exceptions)107 Example.add_method('visualize_grid',108 None,109 [param('const std::string&', 'filename_prefix')],110 is_const=True, throw=exceptions)111 Example.add_method('visualize_problem',112 None,113 [param('const std::string&', 'filename_prefix')],114 is_const=True, throw=exceptions)115 Example.add_method('visualize_problem',116 None,117 [param('const std::string&', 'filename_prefix'),118 param('const Dune::Pymor::Parameter&', 'mu')],119 is_const=True, throw=exceptions)120 if space_backend == space_backend_fem:121 Example.add_method('visualize_darcy_velocity',122 None,123 [param('const {}&'.format(VectorType), 'cg_vector'),124 param('const std::string&', 'filename'),125 param('const std::string&', 'name')],126 is_const=True, throw=exceptions)127 Example.add_method('visualize_darcy_velocity',128 None,129 [param('const {}&'.format(VectorType), 'cg_vector'),130 param('const std::string&', 'filename'),131 param('const std::string&', 'name'),132 param('const Dune::Pymor::Parameter&', 'mu')],133 is_const=True, throw=exceptions)134 if HAVE_DUNE_PDELAB and HAVE_DUNE_ISTL:135 add_example(YaspGrid1d, space_backend_pdelab, la_backend_istl, 'GenericLinearellipticExample_1dYaspGrid_pdelab_istl')136 add_example(YaspGrid2d, space_backend_pdelab, la_backend_istl, 'GenericLinearellipticExample_2dYaspGrid_pdelab_istl')137 add_example(YaspGrid3d, space_backend_pdelab, la_backend_istl, 'GenericLinearellipticExample_3dYaspGrid_pdelab_istl')138 if HAVE_ALUGRID:139 add_example(AluGridConform2d, space_backend_pdelab, la_backend_istl,140 'GenericLinearellipticExample_2dAluConformGrid_pdelab_istl')141 add_example(AluGridConform3d, space_backend_pdelab, la_backend_istl,142 'GenericLinearellipticExample_3dAluConformGrid_pdelab_istl')143 if HAVE_DUNE_SPGRID:144 add_example(SPGrid1d, space_backend_pdelab, la_backend_istl,145 'GenericLinearellipticExample_1dSpGrid_pdelab_istl')146 add_example(SPGrid2d, space_backend_pdelab, la_backend_istl,147 'GenericLinearellipticExample_2dSpGrid_pdelab_istl')148 add_example(SPGrid3d, space_backend_pdelab, la_backend_istl,149 'GenericLinearellipticExample_3dSpGrid_pdelab_istl')150 if HAVE_DUNE_PDELAB and HAVE_EIGEN:151 add_example(YaspGrid1d, space_backend_pdelab, la_backend_eigen, 'GenericLinearellipticExample_1dYaspGrid_pdelab_eigen')152 add_example(YaspGrid2d, space_backend_pdelab, la_backend_eigen, 'GenericLinearellipticExample_2dYaspGrid_pdelab_eigen')153 add_example(YaspGrid3d, space_backend_pdelab, la_backend_eigen, 'GenericLinearellipticExample_3dYaspGrid_pdelab_eigen')154 if HAVE_ALUGRID:155 add_example(AluGridConform2d, space_backend_pdelab, la_backend_eigen,156 'GenericLinearellipticExample_2dAluConformGrid_pdelab_eigen')157 add_example(AluGridConform3d, space_backend_pdelab, la_backend_eigen,158 'GenericLinearellipticExample_3dAluConformGrid_pdelab_eigen')159 if HAVE_DUNE_SPGRID:160 add_example(SPGrid1d, space_backend_pdelab, la_backend_eigen,161 'GenericLinearellipticExample_1dSpGrid_pdelab_eigen')162 add_example(SPGrid2d, space_backend_pdelab, la_backend_eigen,163 'GenericLinearellipticExample_2dSpGrid_pdelab_eigen')164 add_example(SPGrid3d, space_backend_pdelab, la_backend_eigen,165 'GenericLinearellipticExample_3dSpGrid_pdelab_eigen')166 if HAVE_DUNE_FEM and HAVE_DUNE_ISTL:167 add_example(YaspGrid1d, space_backend_fem, la_backend_istl, 'GenericLinearellipticExample_1dYaspGrid_fem_istl')168 add_example(YaspGrid2d, space_backend_fem, la_backend_istl, 'GenericLinearellipticExample_2dYaspGrid_fem_istl')169 add_example(YaspGrid3d, space_backend_fem, la_backend_istl, 'GenericLinearellipticExample_3dYaspGrid_fem_istl')170 if HAVE_ALUGRID:171 add_example(AluGridConform2d, space_backend_fem, la_backend_istl,172 'GenericLinearellipticExample_2dAluConformGrid_fem_istl')173 add_example(AluGridConform3d, space_backend_fem, la_backend_istl,174 'GenericLinearellipticExample_3dAluConformGrid_fem_istl')175 if HAVE_DUNE_SPGRID:176 add_example(SPGrid1d, space_backend_fem, la_backend_istl,177 'GenericLinearellipticExample_1dSpGrid_fem_istl')178 add_example(SPGrid2d, space_backend_fem, la_backend_istl,179 'GenericLinearellipticExample_2dSpGrid_fem_istl')180 add_example(SPGrid3d, space_backend_fem, la_backend_istl,181 'GenericLinearellipticExample_3dSpGrid_fem_istl')182 if HAVE_DUNE_FEM and HAVE_EIGEN:183 add_example(YaspGrid1d, space_backend_fem, la_backend_eigen, 'GenericLinearellipticExample_1dYaspGrid_fem_eigen')184 add_example(YaspGrid2d, space_backend_fem, la_backend_eigen, 'GenericLinearellipticExample_2dYaspGrid_fem_eigen')185 add_example(YaspGrid3d, space_backend_fem, la_backend_eigen, 'GenericLinearellipticExample_3dYaspGrid_fem_eigen')186 if HAVE_ALUGRID:187 add_example(AluGridConform2d, space_backend_fem, la_backend_eigen,188 'GenericLinearellipticExample_2dAluConformGrid_fem_eigen')189 add_example(AluGridConform3d, space_backend_fem, la_backend_eigen,190 'GenericLinearellipticExample_3dAluConformGrid_fem_eigen')191 if HAVE_DUNE_SPGRID:192 add_example(SPGrid1d, space_backend_fem, la_backend_eigen,193 'GenericLinearellipticExample_1dSpGrid_fem_eigen')194 add_example(SPGrid2d, space_backend_fem, la_backend_eigen,195 'GenericLinearellipticExample_2dSpGrid_fem_eigen')196 add_example(SPGrid3d, space_backend_fem, la_backend_eigen,197 'GenericLinearellipticExample_3dSpGrid_fem_eigen')198if __name__ == '__main__':199 # prepare the module200 module, pybindgen_filename, config_h_filename = prepare_python_bindings(sys.argv[1:])201 # add all of libdunepymor202 module, exceptions, interfaces, CONFIG_H = inject_lib_dune_pymor(module, config_h_filename)203 # add example user code (see above)204 inject_Example(module, exceptions, interfaces, CONFIG_H)205 # and finally write the pybindgen .cc file...

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 pytest-bdd 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