Best Python code snippet using autotest_python
interval_actions.py
Source:interval_actions.py
...150 setattr(self.target, self.attrib,151 self.start_p + self.delta * t152 )153154 def __reversed__(self):155 return Lerp(self.attrib, self.end_p, self.start_p, self.duration)156 157class RotateBy( IntervalAction ):158 """Rotates a `CocosNode` object clockwise a number of degrees159 by modiying it's rotation attribute.160161 Example::162163 # rotates the sprite 180 degrees in 2 seconds164 action = RotateBy( 180, 2 )165 sprite.do( action )166 """167 def init(self, angle, duration ):168 """Init method.169170 :Parameters:171 `angle` : float172 Degrees that the sprite will be rotated.173 Positive degrees rotates the sprite clockwise.174 `duration` : float175 Duration time in seconds176 """177 self.angle = angle #: Quantity of degrees to rotate178 self.duration = duration #: Duration in seconds179180 def start( self ):181 self.start_angle = self.target.rotation182 183 def update(self, t):184 self.target.rotation = (self.start_angle + self.angle * t ) % 360185 186 def __reversed__(self):187 return RotateBy(-self.angle, self.duration)188189Rotate = RotateBy190191192class RotateTo( IntervalAction ):193 """Rotates a `CocosNode` object to a certain angle by modifying it's194 rotation attribute.195 The direction will be decided by the shortest angle.196197 Example::198199 # rotates the sprite to angle 180 in 2 seconds200 action = RotateTo( 180, 2 )201 sprite.do( action )202 """203 def init(self, angle, duration ):204 """Init method.205206 :Parameters:207 `angle` : float208 Destination angle in degrees.209 `duration` : float210 Duration time in seconds211 """212 self.angle = angle%360 #: Destination angle in degrees213 self.duration = duration #: Duration in seconds214215 def start( self ):216 ea = self.angle217 sa = self.start_angle = (self.target.rotation%360)218 self.angle = ((ea%360) - (sa%360))219 if self.angle > 180: 220 self.angle = -360+self.angle221 if self.angle < -180: 222 self.angle = 360+self.angle223 224 def update(self, t):225 self.target.rotation = (self.start_angle + self.angle * t ) % 360226227 def __reversed__(self):228 return RotateTo(-self.angle, self.duration)229 230class Speed( IntervalAction ):231 """232 Changes the speed of an action, making it take longer (speed>1)233 or less (speed<1)234235 Example::236237 # rotates the sprite 180 degrees in 1 secondclockwise238 action = Speed( Rotate( 180, 2 ), 2 )239 sprite.do( action )240 """241 def init(self, other, speed ):242 """Init method.243244 :Parameters:245 `other` : IntervalAction246 The action that will be affected247 `speed` : float248 The speed change. 1 is no change.249 2 means twice as fast, takes half the time250 0.5 means half as fast, takes double the time251 """252 self.other = other253 self.speed = speed254 self.duration = other.duration/speed255256 def start(self):257 self.other.target = self.target258 self.other.start()259260 def update(self, t):261 self.other.update( t )262263 def __reversed__(self):264 return Speed( Reverse( self.other ), self.speed )265266class Accelerate( IntervalAction ):267 """268 Changes the acceleration of an action269270 Example::271272 # rotates the sprite 180 degrees in 2 seconds clockwise273 # it starts slow and ends fast274 action = Accelerate( Rotate( 180, 2 ), 4 )275 sprite.do( action )276 """277 def init(self, other, rate = 2):278 """Init method.279280 :Parameters:281 `other` : IntervalAction282 The action that will be affected283 `rate` : float284 The acceleration rate. 1 is linear.285 the new t is t**rate286 """287 self.other = other288 self.rate = rate289 self.duration = other.duration290291 def start(self):292 self.other.target = self.target293 self.other.start()294295 def update(self, t):296 self.other.update( t**self.rate )297298 def __reversed__(self):299 return Accelerate(Reverse(self.other), 1.0/self.rate)300301class AccelDeccel( IntervalAction ):302 """303 Makes an action change the travel speed but retain near normal304 speed at the beginning and ending.305306 Example::307308 # rotates the sprite 180 degrees in 2 seconds clockwise309 # it starts slow, gets fast and ends slow310 action = AccelDeccel( RotateBy( 180, 2 ) )311 sprite.do( action )312 """313 def init(self, other):314 """Init method.315316 :Parameters:317 `other` : IntervalAction318 The action that will be affected319 """320 self.other = other321 self.duration = other.duration322323 def start(self):324 self.other.target = self.target325 self.other.start()326327 def update(self, t):328 if t != 1.0:329 ft = (t - 0.5) * 12330 t = 1./( 1. + math.exp(-ft) )331 self.other.update( t )332333 def __reversed__(self):334 return AccelDeccel( Reverse(self.other) )335336337338class MoveTo( IntervalAction ):339 """Moves a `CocosNode` object to the position x,y. x and y are absolute coordinates340 by modifying it's position attribute.341342 Example::343344 # Move the sprite to coords x=50, y=10 in 8 seconds345346 action = MoveTo( (50,10), 8 )347 sprite.do( action )348 """349 def init(self, dst_coords, duration=5):350 """Init method.351352 :Parameters:353 `dst_coords` : (x,y)354 Coordinates where the sprite will be placed at the end of the action355 `duration` : float356 Duration time in seconds357 """358359 self.end_position = Point2( *dst_coords )360 self.duration = duration361362 def start( self ):363 self.start_position = self.target.position364 self.delta = self.end_position-self.start_position365366367 def update(self,t):368 self.target.position = self.start_position + self.delta * t369370class MoveBy( MoveTo ):371 """Moves a `CocosNode` object x,y pixels by modifying it's 372 position attribute.373 x and y are relative to the position of the object.374 Duration is is seconds.375376 Example::377378 # Move the sprite 50 pixels to the left in 8 seconds379 action = MoveBy( (-50,0), 8 )380 sprite.do( action )381 """382 def init(self, delta, duration=5):383 """Init method.384385 :Parameters:386 `delta` : (x,y)387 Delta coordinates388 `duration` : float389 Duration time in seconds390 """391 self.delta = Point2( *delta )392 self.duration = duration393394 def start( self ):395 self.start_position = self.target.position396 self.end_position = self.start_position + self.delta397398 def __reversed__(self):399 return MoveBy(-self.delta, self.duration)400401class FadeOut( IntervalAction ):402 """Fades out a `CocosNode` object by modifying it's opacity attribute.403404 Example::405406 action = FadeOut( 2 )407 sprite.do( action )408 """409 def init( self, duration ):410 """Init method.411412 :Parameters:413 `duration` : float414 Seconds that it will take to fade415 """416 self.duration = duration417418 def update( self, t ):419 self.target.opacity = 255 * (1-t)420421 def __reversed__(self):422 return FadeIn( self.duration )423424class FadeTo( IntervalAction ):425 """Fades a `CocosNode` object to a specific alpha value by modifying it's opacity attribute.426427 Example::428429 action = FadeTo( 128, 2 )430 sprite.do( action )431 """432 def init( self, alpha, duration ):433 """Init method.434435 :Parameters:436 `alpha` : float437 0-255 value of opacity438 `duration` : float439 Seconds that it will take to fade440 """441 self.alpha = alpha442 self.duration = duration443444 def start(self):445 self.start_alpha = self.target.opacity446447 def update( self, t ):448 self.target.opacity = self.start_alpha + (449 self.alpha - self.start_alpha450 ) * t451452453class FadeIn( FadeOut):454 """Fades in a `CocosNode` object by modifying it's opacity attribute.455456 Example::457458 action = FadeIn( 2 )459 sprite.do( action )460 """461 def update( self, t ):462 self.target.opacity = 255 * t463464 def __reversed__(self):465 return FadeOut( self.duration )466467class ScaleTo(IntervalAction):468 """Scales a `CocosNode` object to a zoom factor by modifying it's scale attribute.469470 Example::471472 # scales the sprite to 5x in 2 seconds473 action = ScaleTo( 5, 2 )474 sprite.do( action )475 """476 def init(self, scale, duration=5 ):477 """Init method.478479 :Parameters:480 `scale` : float481 scale factor482 `duration` : float483 Duration time in seconds484 """485 self.end_scale = scale486 self.duration = duration487488 def start( self ):489 self.start_scale = self.target.scale490 self.delta = self.end_scale-self.start_scale491492 def update(self, t):493 self.target.scale = self.start_scale + self.delta * t494495496class ScaleBy(ScaleTo):497 """Scales a `CocosNode` object a zoom factor by modifying it's scale attribute.498499 Example::500501 # scales the sprite by 5x in 2 seconds502 action = ScaleBy( 5, 2 )503 sprite.do( action )504 """505506 def start( self ):507 self.start_scale = self.target.scale508 self.delta = self.start_scale*self.end_scale - self.start_scale509510 def __reversed__(self):511 return ScaleBy( 1.0/self.end_scale, self.duration )512513514class Blink( IntervalAction ):515 """Blinks a `CocosNode` object by modifying it's visible attribute516517 The action ends with the same visible state than at the start time.518519 Example::520521 # Blinks 10 times in 2 seconds522 action = Blink( 10, 2 )523 sprite.do( action )524 """525526527 def init(self, times, duration):528 """Init method.529530 :Parameters:531 `times` : integer532 Number of times to blink533 `duration` : float534 Duration time in seconds535 """536 self.times = times537 self.duration = duration538539 def start(self):540 self.end_invisible = not self.target.visible 541542 def update(self, t):543 slice = 1.0 / self.times544 m = t % slice545 self.target.visible = self.end_invisible ^ (m < slice / 2.0)546547 def __reversed__(self):548 return self549550551class Bezier( IntervalAction ):552 """Moves a `CocosNode` object through a bezier path by modifying it's position attribute.553554 Example::555556 action = Bezier( bezier_conf.path1, 5 ) # Moves the sprite using the557 sprite.do( action ) # bezier path 'bezier_conf.path1'558 # in 5 seconds559 """560 def init(self, bezier, duration=5, forward=True):561 """Init method562563 :Parameters:564 `bezier` : bezier_configuration instance565 A bezier configuration566 `duration` : float567 Duration time in seconds568 """569 self.duration = duration570 self.bezier = bezier571 self.forward = forward572573 def start( self ):574 self.start_position = self.target.position575576 def update(self,t):577 if self.forward:578 p = self.bezier.at( t )579 else:580 p = self.bezier.at( 1-t )581 self.target.position = ( self.start_position +Point2( *p ) )582583 def __reversed__(self):584 return Bezier(self.bezier, self.duration, not self.forward)585586class Jump(IntervalAction):587 """Moves a `CocosNode` object simulating a jump movement by modifying it's position attribute.588589 Example::590591 action = Jump(50,200, 5, 6) # Move the sprite 200 pixels to the right592 sprite.do( action ) # in 6 seconds, doing 5 jumps593 # of 50 pixels of height594 """595596 def init(self, y=150, x=120, jumps=1, duration=5):597 """Init method598599 :Parameters:600 `y` : integer601 Height of jumps602 `x` : integer603 horizontal movement relative to the startin position604 `jumps` : integer605 quantity of jumps606 `duration` : float607 Duration time in seconds608 """609610 import warnings611 warnings.warn('Deprecated "Jump" action. Consider using JumpBy instead', DeprecationWarning)612 613614 self.y = y615 self.x = x616 self.duration = duration617 self.jumps = jumps618619 def start( self ):620 self.start_position = self.target.position621622 def update(self, t):623 y = int( self.y * abs( math.sin( t * math.pi * self.jumps ) ) )624625 x = self.x * t626 self.target.position = self.start_position + Point2(x,y)627628 def __reversed__(self):629 return Jump(self.y, -self.x, self.jumps, self.duration)630631class JumpBy(IntervalAction):632 """Moves a `CocosNode` object simulating a jump movement by modifying it's position attribute.633634 Example::635636 # Move the sprite 200 pixels to the right and up637 action = JumpBy((100,100),200, 5, 6) 638 sprite.do( action ) # in 6 seconds, doing 5 jumps639 # of 200 pixels of height640 """641642 def init(self, position=(0,0), height=100, jumps=1, duration=5):643 """Init method644645 :Parameters:646 `position` : integer x integer tuple647 horizontal and vertical movement relative to the 648 starting position649 `height` : integer650 Height of jumps651 `jumps` : integer652 quantity of jumps653 `duration` : float654 Duration time in seconds655 """656 self.position = position657 self.height = height658 self.duration = duration659 self.jumps = jumps660661 def start( self ):662 self.start_position = self.target.position663 self.delta = Vector2(*self.position)664 665 def update(self, t):666 y = self.height * abs( math.sin( t * math.pi * self.jumps ) )667 y = int(y+self.delta[1] * t)668 x = self.delta[0] * t669 self.target.position = self.start_position + Point2(x,y)670 671 def __reversed__(self):672 return JumpBy( (-self.position[0],-self.position[1]), self.height, self.jumps, self.duration)673674class JumpTo(JumpBy):675 """Moves a `CocosNode` object to a position simulating a jump movement by modifying676 it's position attribute.677678 Example::679680 action = JumpTo(50,200, 5, 6) # Move the sprite 200 pixels to the right681 sprite.do( action ) # in 6 seconds, doing 5 jumps682 # of 50 pixels of height683 """684685686 def start( self ):687 self.start_position = self.target.position688 self.delta = Vector2(*self.position)-self.start_position689 690691class Delay(IntervalAction):692 """Delays the action a certain amount of seconds693694 Example::695696 action = Delay(2.5)697 sprite.do( action )698 """699 def init(self, delay):700 """Init method701702 :Parameters:703 `delay` : float704 Seconds of delay705 """706 self.duration = delay707708 def __reversed__(self):709 return self710 711712class RandomDelay(Delay):713 """Delays the actions between *min* and *max* seconds714715 Example::716717 action = RandomDelay(2.5, 4.5) # delays the action between 2.5 and 4.5 seconds718 sprite.do( action )719 """720 def init(self, low, hi):721 """Init method722
...
player.py
Source:player.py
...123 self.cached_next = None124 self.cached_next_file = None125 def move_queue_item(self, source_index, dest_index):126 if -1 < source_index < len(self.__queue) and -1 < dest_index < len(self.__queue):127 helper_q = list(self.__queue.__reversed__())128 helper_q.insert(dest_index, helper_q.pop(source_index))129 self.__queue = list(helper_q.__reversed__())130 if dest_index <= self.queue_position < source_index:131 self.queue_position += 1132 elif source_index < self.queue_position <= dest_index:133 self.queue_position -= 1134 elif source_index == self.queue_position:135 self.queue_position = dest_index136 self.__cache_next()137 def set_queue(self, queue):138 self.__queue = queue.__reversed__()139 self.queue_position = -1140 self.cached_next = Stream(self.__queue.__reversed__[self.queue_position+1].file, self.next_track) if \141 (len(self.__queue) and self.__queue[self.queue_position+1].file != self.cached_next_file) else None142 self.cached_next_file = \143 self.__queue[self.queue_position+1].file \144 if (self.queue_position+1 < len(self.__queue)145 and self.__queue[self.queue_position+1].file != self.cached_next_file) else None146 def __load(self, track):147 self.kill_stream()148 self.track = track149 logs.print_info(u"Åadowanie {}".format(self.track.title))150 self.__stream = Stream(self.track.file, self.next_track)151 def get_queue_position(self):152 return self.queue_position153 def set_queue_position(self, pos):154 if -1 < pos < len(self.__queue):155 self.queue_position = pos156 self.__load(list(self.__queue.__reversed__())[pos])157 self.__cache_next()158 def del_from_queue(self, pos):159 helper_q = list(self.__queue.__reversed__())160 del helper_q[pos]161 self.__queue = list(helper_q.__reversed__())162 if pos == self.queue_position:163 self.queue_position -= 1164 self.next_track()165 elif pos < self.queue_position:166 self.queue_position -= 1167 def add_to_queue(self, track):168 self.__queue.insert(0, track)169 if len(self.__queue) == 1:170 self.set_queue_position(0)171 self.__cache_next()172 def get_queue(self):173 return list(self.__queue.__reversed__())174 @staticmethod175 def set_volume(value):176 mixer.setvolume(value)177 @staticmethod178 def get_volume():179 return mixer.getvolume()180 def get_position(self):181 if self.__stream:182 return self.__stream.get_position()183 else:184 return 0185 def get_duration(self):186 if self.__stream:187 return self.__stream.get_duration()188 else:189 return 0190 def is_playing(self):191 return self.__stream and self.__stream.is_playing()192 def get_json_status(self):193 vol = self.get_volume()194 data = {"vol_left": vol[0],195 "vol_right": vol[0] if len(vol) == 1 else vol[1],196 "status": "playing" if self.is_playing() else "paused",197 "queue_position": self.get_queue_position(),198 "mode": self.mode,199 "queue_md5": self.get_queue_hash()}200 if self.track:201 data["file"] = self.track.file202 data["position"] = self.get_position()203 data["duration"] = self.get_duration()204 data["artist"] = self.track.artist.name205 data["album"] = self.track.album.name206 data["title"] = self.track.title207 return data208 def pause(self):209 if self.__stream:210 self.__stream.pause()211 def play(self):212 if self.__stream and self.gaps.is_unlocked():213 self.__stream.play()214 logs.print_info("Odtwarzanie {}".format(self.track.title))215 def stop(self):216 if self.__stream:217 self.__stream.pause()218 self.__stream.seek(0)219 logs.print_info(u"Zatrzymano {}".format(self.track.title))220 def kill_stream(self):221 if self.__stream:222 self.__stream.kill()223 logs.print_info(u"Zabito strumieÅ {}".format(self.__stream.get_file()))224 def seek(self, seconds):225 if self.__stream:226 self.__stream.seek(seconds)227 def next_track(self, is_call_internal=False):228 if is_call_internal and self.mode == Player.MODE_REPEAT_ONE:229 self.seek(0)230 self.play()231 return232 logs.print_info(u"Przechodzenie do kolejnego utworu")233 self.kill_stream()234 if self.queue_position+1 < len(self.__queue):235 self.queue_position += 1236 if not self.cached_next or self.cached_next_file != list(self.__queue.__reversed__())[self.queue_position].file:237 self.__load(list(self.__queue.__reversed__())[self.queue_position])238 self.play()239 else:240 self.__stream = self.cached_next241 self.cached_next = None242 self.cached_next_file = None243 self.track = list(self.__queue.__reversed__())[self.queue_position]244 self.play()245 elif is_call_internal and self.mode == Player.MODE_REPEAT:246 self.set_queue_position(0)247 self.play()248 else:249 self.track = None250 self.queue_position = len(self.__queue)251 return252 self.__cache_next()253 def __cache_next(self):254 next_position = self.queue_position + 1255 if self.mode == Player.MODE_REPEAT and self.queue_position + 1 == len(self.__queue):256 next_position = 0257 if not next_position < len(self.__queue) or self.mode == Player.MODE_REPEAT_ONE:258 if self.cached_next:259 logs.print_info(u"Usuwanie cache - {}".format(self.cached_next.get_file()))260 self.cached_next.kill()261 self.cached_next = None262 self.cached_next_file = None263 return264 are_equal = list(self.__queue.__reversed__())[next_position].file == self.cached_next_file265 if not are_equal:266 if self.cached_next:267 logs.print_info(u"Czyszczenie cache - {}".format(self.cached_next.get_file()))268 self.cached_next.kill()269 self.cached_next = Stream(list(self.__queue.__reversed__())[next_position].file, self.next_track, is_cache=True)270 self.cached_next_file = list(self.__queue.__reversed__())[next_position].file271 logs.print_info(u"Cachowanie {}".format(self.cached_next.get_file()))272 def prev_track(self):273 logs.print_info(u"Przechodzenie do poprzedniego utworu")274 if self.queue_position <= 0:275 self.seek(0)276 self.play()277 return278 else:279 self.queue_position -= 2280 self.next_track()281def get_musiclibrary():282 lib_files = music_library.get_file_list(config.library_path)283 global lib284 lib = music_library.parse_library(lib_files)...
LabelMe.py
Source:LabelMe.py
1import torch2import cv23import os4import numpy as np5various = torch.Tensor([0,0,0]).__reversed__()6building = torch.Tensor([128,0,0]).__reversed__()7car = torch.Tensor([128,0,128]).__reversed__()8door = torch.Tensor([128,128,0]).__reversed__()9pavement = torch.Tensor([128,128,128]).__reversed__()10road = torch.Tensor([128,64,0]).__reversed__()11sky = torch.Tensor([0,128,128]).__reversed__()12vegetation = torch.Tensor([0,128,0]).__reversed__()13window = torch.Tensor([0,0,128]).__reversed__()14path = '/home/quantum/Workspace/Storage/Other/Temp/dataset/YOLO_Data/data/images/facade/'15facade_labels_path = '/home/quantum/Workspace/Storage/Other/Temp/dataset/YOLO_Data/data/labels/facade/'16annotations_path = '/home/quantum/Workspace/Storage/Other/Temp/dataset/labelmefacade/labels/'17files = sorted(os.listdir(path))18label_files = sorted(os.listdir(annotations_path))19def write_box(f, rect, height, width):20 x, y, w, h = rect21 f.write("91 {} {} {} {}\n".format((x + w/2) / width, (y + h/2) / height, (w / width), (h / height)))22start = 023for i in range(start, len(files)):24 print(i, "Reading: ", files[i], label_files[i], end='')25 if files[i][-4:] != '.jpg':26 continue27 f = open(facade_labels_path + files[i][:-4] + '.txt', '+w')...
bad_reversed_sequence.py
Source:bad_reversed_sequence.py
...4from collections import deque5__revision__ = 06class GoodReversed(object):7 """ Implements __reversed__ """8 def __reversed__(self):9 return [1, 2, 3]10class SecondGoodReversed(object):11 """ Implements __len__ and __getitem__ """12 def __len__(self):13 return 314 def __getitem__(self, index):15 return index16class BadReversed(object):17 """ implements only len() """18 def __len__(self):19 return 320class SecondBadReversed(object):21 """ implements only __getitem__ """22 def __getitem__(self, index):23 return index24class ThirdBadReversed(dict):25 """ dict subclass """26def uninferable(seq):27 """ This can't be infered at this moment,28 make sure we don't have a false positive.29 """30 return reversed(seq)31def test(path):32 """ test function """33 seq = reversed() # No argument given34 seq = reversed(None) # [bad-reversed-sequence]35 seq = reversed([1, 2, 3])36 seq = reversed((1, 2, 3))37 seq = reversed(set()) # [bad-reversed-sequence]38 seq = reversed({'a': 1, 'b': 2}) # [bad-reversed-sequence]39 seq = reversed(iter([1, 2, 3])) # [bad-reversed-sequence]40 seq = reversed(GoodReversed())41 seq = reversed(SecondGoodReversed())42 seq = reversed(BadReversed()) # [bad-reversed-sequence]43 seq = reversed(SecondBadReversed()) # [bad-reversed-sequence]44 seq = reversed(range(100))45 seq = reversed(ThirdBadReversed()) # [bad-reversed-sequence]46 seq = reversed(lambda: None) # [bad-reversed-sequence]47 seq = reversed(deque([]))48 seq = reversed("123")49 seq = uninferable([1, 2, 3])50 seq = reversed(path.split("/"))51 return seq52def test_dict_ancestor_and_reversed():53 """Don't emit for subclasses of dict, with __reversed__ implemented."""54 from collections import OrderedDict55 class Child(dict):56 def __reversed__(self):57 return reversed(range(10))58 seq = reversed(OrderedDict())...
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!!