How to use assert_description method in PyHamcrest

Best Python code snippet using PyHamcrest_python

a2dp.py

Source:a2dp.py Github

copy

Full Screen

1# Copyright 2022 Google LLC2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# https://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""A2DP proxy module."""15import time16from typing import Optional17from grpc import RpcError18from mmi2grpc._audio import AudioSignal19from mmi2grpc._helpers import assert_description20from mmi2grpc._proxy import ProfileProxy21from pandora.a2dp_grpc import A2DP22from pandora.a2dp_pb2 import Sink, Source, PlaybackAudioRequest23from pandora.host_grpc import Host24from pandora.host_pb2 import Connection25AUDIO_SIGNAL_AMPLITUDE = 0.826AUDIO_SIGNAL_SAMPLING_RATE = 4410027class A2DPProxy(ProfileProxy):28 """A2DP proxy.29 Implements A2DP and AVDTP PTS MMIs.30 """31 connection: Optional[Connection] = None32 sink: Optional[Sink] = None33 source: Optional[Source] = None34 def __init__(self, channel):35 super().__init__()36 self.host = Host(channel)37 self.a2dp = A2DP(channel)38 def convert_frame(data):39 return PlaybackAudioRequest(data=data, source=self.source)40 self.audio = AudioSignal(41 lambda frames: self.a2dp.PlaybackAudio(map(convert_frame, frames)),42 AUDIO_SIGNAL_AMPLITUDE,43 AUDIO_SIGNAL_SAMPLING_RATE44 )45 @assert_description46 def TSC_AVDTP_mmi_iut_accept_connect(47 self, test: str, pts_addr: bytes, **kwargs):48 """49 If necessary, take action to accept the AVDTP Signaling Channel50 Connection initiated by the tester.51 Description: Make sure the IUT52 (Implementation Under Test) is in a state to accept incoming Bluetooth53 connections. Some devices may need to be on a specific screen, like a54 Bluetooth settings screen, in order to pair with PTS. If the IUT is55 still having problems pairing with PTS, try running a test case where56 the IUT connects to PTS to establish pairing.57 """58 if "SRC" in test:59 self.connection = self.host.WaitConnection(60 address=pts_addr).connection61 try:62 if "INT" in test:63 self.source = self.a2dp.OpenSource(64 connection=self.connection).source65 else:66 self.source = self.a2dp.WaitSource(67 connection=self.connection).source68 except RpcError:69 pass70 else:71 self.connection = self.host.WaitConnection(72 address=pts_addr).connection73 try:74 self.sink = self.a2dp.WaitSink(75 connection=self.connection).sink76 except RpcError:77 pass78 return "OK"79 @assert_description80 def TSC_AVDTP_mmi_iut_initiate_discover(self, **kwargs):81 """82 Send a discover command to PTS.83 Action: If the IUT (Implementation84 Under Test) is already connected to PTS, attempting to send or receive85 streaming media should trigger this action. If the IUT is not connected86 to PTS, attempting to connect may trigger this action.87 """88 return "OK"89 @assert_description90 def TSC_AVDTP_mmi_iut_initiate_start(self, test: str, **kwargs):91 """92 Send a start command to PTS.93 Action: If the IUT (Implementation Under94 Test) is already connected to PTS, attempting to send or receive95 streaming media should trigger this action. If the IUT is not connected96 to PTS, attempting to connect may trigger this action.97 """98 if "SRC" in test:99 self.a2dp.Start(source=self.source)100 else:101 self.a2dp.Start(sink=self.sink)102 return "OK"103 @assert_description104 def TSC_AVDTP_mmi_iut_initiate_suspend(self, test: str, **kwargs):105 """106 Suspend the streaming channel.107 """108 if "SRC" in test:109 self.a2dp.Suspend(source=self.source)110 else:111 assert False112 return "OK"113 @assert_description114 def TSC_AVDTP_mmi_iut_initiate_close_stream(self, test: str, **kwargs):115 """116 Close the streaming channel.117 Action: Disconnect the streaming channel,118 or close the Bluetooth connection to the PTS.119 """120 if "SRC" in test:121 self.a2dp.Close(source=self.source)122 self.source = None123 else:124 self.a2dp.Close(sink=self.sink)125 self.sink = None126 return "OK"127 @assert_description128 def TSC_AVDTP_mmi_iut_initiate_out_of_range(129 self, pts_addr: bytes, **kwargs):130 """131 Move the IUT out of range to create a link loss scenario.132 Action: This133 can be also be done by placing the IUT or PTS in an RF shielded box.134 """135 if self.connection is None:136 self.connection = self.host.GetConnection(137 address=pts_addr).connection138 self.host.Disconnect(connection=self.connection)139 self.connection = None140 self.sink = None141 self.source = None142 return "OK"143 @assert_description144 def TSC_AVDTP_mmi_iut_begin_streaming(self, test: str, **kwargs):145 """146 Begin streaming media ...147 Note: If the IUT has suspended the stream148 please restart the stream to begin streaming media.149 """150 if test == "AVDTP/SRC/ACP/SIG/SMG/BI-29-C":151 time.sleep(2) # TODO: Remove, AVRCP SegFault152 if test in ("A2DP/SRC/CC/BV-09-I",153 "A2DP/SRC/SET/BV-04-I",154 "AVDTP/SRC/ACP/SIG/SMG/BV-18-C",155 "AVDTP/SRC/ACP/SIG/SMG/BV-20-C",156 "AVDTP/SRC/ACP/SIG/SMG/BV-22-C"):157 time.sleep(1) # TODO: Remove, AVRCP SegFault158 if test == "A2DP/SRC/SUS/BV-01-I":159 # Stream is not suspended when we receive the interaction160 time.sleep(1)161 self.a2dp.Start(source=self.source)162 self.audio.start()163 return "OK"164 @assert_description165 def TSC_AVDTP_mmi_iut_initiate_media(self, **kwargs):166 """167 Take action if necessary to start streaming media to the tester.168 """169 self.audio.start()170 return "OK"171 @assert_description172 def TSC_AVDTP_mmi_iut_initiate_stream_media(self, **kwargs):173 """174 Stream media to PTS. If the IUT is a SNK, wait for PTS to start175 streaming media.176 Action: If the IUT (Implementation Under Test) is177 already connected to PTS, attempting to send or receive streaming media178 should trigger this action. If the IUT is not connected to PTS,179 attempting to connect may trigger this action.180 """181 self.audio.start()182 return "OK"183 @assert_description184 def TSC_AVDTP_mmi_user_verify_media_playback(self, **kwargs):185 """186 Is the test system properly playing back the media being sent by the187 IUT?188 """189 result = self.audio.verify()190 assert result191 return "Yes" if result else "No"192 @assert_description193 def TSC_AVDTP_mmi_iut_initiate_get_capabilities(self, **kwargs):194 """195 Send a get capabilities command to PTS.196 Action: If the IUT197 (Implementation Under Test) is already connected to PTS, attempting to198 send or receive streaming media should trigger this action. If the IUT199 is not connected to PTS, attempting to connect may trigger this action.200 """201 # This will be done as part as the a2dp.OpenSource or a2dp.WaitSource202 return "OK"203 @assert_description204 def TSC_AVDTP_mmi_iut_accept_discover(self, **kwargs):205 """206 If necessary, take action to accept the AVDTP Discover operation207 initiated by the tester.208 """209 return "OK"210 @assert_description211 def TSC_AVDTP_mmi_iut_initiate_set_configuration(self, **kwargs):212 """213 Send a set configuration command to PTS.214 Action: If the IUT215 (Implementation Under Test) is already connected to PTS, attempting to216 send or receive streaming media should trigger this action. If the IUT217 is not connected to PTS, attempting to connect may trigger this action.218 """219 return "OK"220 @assert_description221 def TSC_AVDTP_mmi_iut_accept_close_stream(self, **kwargs):222 """223 If necessary, take action to accept the AVDTP Close operation initiated224 by the tester.225 """226 return "OK"227 @assert_description228 def TSC_AVDTP_mmi_iut_accept_abort(self, **kwargs):229 """230 If necessary, take action to accept the AVDTP Abort operation initiated231 by the tester..232 """233 return "OK"234 @assert_description235 def TSC_AVDTP_mmi_iut_accept_get_all_capabilities(self, **kwargs):236 """237 If necessary, take action to accept the AVDTP Get All Capabilities238 operation initiated by the tester.239 """240 return "OK"241 @assert_description242 def TSC_AVDTP_mmi_iut_accept_get_capabilities(self, **kwargs):243 """244 If necessary, take action to accept the AVDTP Get Capabilities operation245 initiated by the tester.246 """247 return "OK"248 @assert_description249 def TSC_AVDTP_mmi_iut_accept_set_configuration(self, **kwargs):250 """251 If necessary, take action to accept the AVDTP Set Configuration252 operation initiated by the tester.253 """254 return "OK"255 @assert_description256 def TSC_AVDTP_mmi_iut_accept_get_configuration(self, **kwargs):257 """258 Take action to accept the AVDTP Get Configuration command from the259 tester.260 """261 return "OK"262 @assert_description263 def TSC_AVDTP_mmi_iut_accept_open_stream(self, **kwargs):264 """265 If necessary, take action to accept the AVDTP Open operation initiated266 by the tester.267 """268 return "OK"269 @assert_description270 def TSC_AVDTP_mmi_iut_accept_start(self, **kwargs):271 """272 If necessary, take action to accept the AVDTP Start operation initiated273 by the tester.274 """275 return "OK"276 @assert_description277 def TSC_AVDTP_mmi_iut_accept_suspend(self, **kwargs):278 """279 If necessary, take action to accept the AVDTP Suspend operation280 initiated by the tester.281 """282 return "OK"283 @assert_description284 def TSC_AVDTP_mmi_iut_accept_reconfigure(self, **kwargs):285 """286 If necessary, take action to accept the AVDTP Reconfigure operation287 initiated by the tester.288 """289 return "OK"290 @assert_description291 def TSC_AVDTP_mmi_iut_accept_media_transports(self, **kwargs):292 """293 Take action to accept transport channels for the recently configured294 media stream.295 """296 return "OK"297 @assert_description298 def TSC_AVDTP_mmi_iut_confirm_streaming(self, **kwargs):299 """300 Is the IUT (Implementation Under Test) receiving streaming media from301 PTS?302 Action: Press 'Yes' if the IUT is receiving streaming data from303 the PTS (in some cases the sound may not be clear, this is normal).304 """305 # TODO: verify306 return "OK"307 @assert_description308 def TSC_AVDTP_mmi_iut_initiate_open_stream(self, **kwargs):309 """310 Open a streaming media channel.311 Action: If the IUT (Implementation312 Under Test) is already connected to PTS, attempting to send or receive313 streaming media should trigger this action. If the IUT is not connected314 to PTS, attempting to connect may trigger this action.315 """316 return "OK"317 @assert_description318 def TSC_AVDTP_mmi_iut_accept_reconnect(self, pts_addr: bytes, **kwargs):319 """320 Press OK when the IUT (Implementation Under Test) is ready to allow the321 PTS to reconnect the AVDTP signaling channel.322 Action: Press OK when the323 IUT is ready to accept Bluetooth connections again.324 """325 return "OK"326 @assert_description327 def TSC_AVDTP_mmi_iut_initiate_get_all_capabilities(self, **kwargs):328 """329 Send a GET ALL CAPABILITIES command to PTS.330 Action: If the IUT331 (Implementation Under Test) is already connected to PTS, attempting to332 send or receive streaming media should trigger this action. If the IUT333 is not connected to PTS, attempting to connect may trigger this action.334 """335 return "OK"336 @assert_description337 def TSC_AVDTP_mmi_tester_verifying_suspend(self, **kwargs):338 """339 Please wait while the tester verifies the IUT does not send media during340 suspend ...341 """342 return "Yes"343 @assert_description344 def TSC_A2DP_mmi_user_confirm_optional_data_attribute(self, **kwargs):345 """346 Tester found the optional SDP attribute named 'Supported Features'.347 Press 'Yes' if the data displayed below is correct.348 Value: 0x0001349 """350 # TODO: Extract and verify attribute name and value from description351 return "OK"352 @assert_description353 def TSC_A2DP_mmi_user_confirm_optional_string_attribute(self, **kwargs):354 """355 Tester found the optional SDP attribute named 'Service Name'. Press356 'Yes' if the string displayed below is correct.357 Value: Advanced Audio358 Source359 """360 # TODO: Extract and verify attribute name and value from description361 return "OK"362 @assert_description363 def TSC_A2DP_mmi_user_confirm_no_optional_attribute_support(self, **kwargs):364 """365 Tester could not find the optional SDP attribute named 'Provider Name'.366 Is this correct?367 """368 # TODO: Extract and verify attribute name from description369 return "OK"370 @assert_description371 def TSC_AVDTPEX_mmi_iut_accept_delayreport(self, **kwargs):372 """373 Take action if necessary to accept the Delay Reportl command from the374 tester.375 """376 return "OK"377 @assert_description378 def TSC_AVDTPEX_mmi_iut_initiate_media_transport_connect(self, **kwargs):379 """380 Take action to initiate an AVDTP media transport.381 """382 return "OK"383 @assert_description384 def TSC_AVDTPEX_mmi_user_confirm_SIG_SMG_BV_28_C(self, **kwargs):385 """386 Were all the service capabilities reported to the upper tester valid?387 """388 # TODO: verify389 return "Yes"390 @assert_description391 def TSC_AVDTPEX_mmi_iut_reject_invalid_command(self, **kwargs):392 """393 Take action to reject the invalid command sent by the tester.394 """395 return "OK"396 @assert_description397 def TSC_AVDTPEX_mmi_iut_reject_open(self, **kwargs):398 """399 Take action to reject the invalid OPEN command sent by the tester.400 """401 return "OK"402 @assert_description403 def TSC_AVDTPEX_mmi_iut_reject_start(self, **kwargs):404 """405 Take action to reject the invalid START command sent by the tester.406 """407 return "OK"408 @assert_description409 def TSC_AVDTPEX_mmi_iut_reject_suspend(self, **kwargs):410 """411 Take action to reject the invalid SUSPEND command sent by the tester.412 """413 return "OK"414 @assert_description415 def TSC_AVDTPEX_mmi_iut_reject_reconfigure(self, **kwargs):416 """417 Take action to reject the invalid or incompatible RECONFIGURE command418 sent by the tester.419 """420 return "OK"421 @assert_description422 def TSC_AVDTPEX_mmi_iut_reject_get_all_capabilities(self, **kwargs):423 """424 Take action to reject the invalid GET ALL CAPABILITIES command with the425 error code BAD_LENGTH.426 """427 return "OK"428 @assert_description429 def TSC_AVDTPEX_mmi_iut_reject_get_capabilities(self, **kwargs):430 """431 Take action to reject the invalid GET CAPABILITIES command with the432 error code BAD_LENGTH.433 """434 return "OK"435 @assert_description436 def TSC_AVDTPEX_mmi_iut_reject_set_configuration(self, **kwargs):437 """438 Take action to reject the SET CONFIGURATION sent by the tester. The IUT439 is expected to respond with SEP_IN_USE because the SEP requested was440 previously configured.441 """442 return "OK"443 def TSC_AVDTPEX_mmi_iut_reject_get_configuration(self, **kwargs):444 """445 Take action to reject the GET CONFIGURATION sent by the tester. The IUT446 is expected to respond with BAD_ACP_SEID because the SEID requested was447 not previously configured.448 """449 return "OK"450 @assert_description451 def TSC_AVDTPEX_mmi_iut_reject_close(self, **kwargs):452 """453 Take action to reject the invalid CLOSE command sent by the tester.454 """455 return "OK"456 @assert_description457 def TSC_AVDTPEX_mmi_user_confirm_SIG_SMG_BV_18_C(self, **kwargs):458 """459 Did the IUT receive media with the following information?460 - V = RTP_Ver461 - P = 0 (no padding bits)462 - X = 0 (no extension)463 - CC = 0 (no464 contributing source)465 - M = 0466 """467 # TODO: verify...

Full Screen

Full Screen

_helpers.py

Source:_helpers.py Github

copy

Full Screen

...17import functools18import textwrap19import unittest20DOCSTRING_WIDTH = 80 - 8 # 80 cols - 8 indentation spaces21def assert_description(f):22 """Decorator which verifies the description of a PTS MMI implementation.23 Asserts that the docstring of a function implementing a PTS MMI is the same24 as the corresponding official MMI description.25 Args:26 f: function implementing a PTS MMI.27 Raises:28 AssertionError: the docstring of the function does not match the MMI29 description.30 """31 @functools.wraps(f)32 def wrapper(*args, **kwargs):33 description = textwrap.fill(34 kwargs['description'], DOCSTRING_WIDTH, replace_whitespace=False)35 docstring = textwrap.dedent(f.__doc__ or '')...

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