Best Python code snippet using tempest_python
track_ui_test.py
Source:track_ui_test.py
...45 **kwargs)46 async def test_segments_changed(self):47 with self._trackItem():48 with self.project.apply_mutations('test'):49 seg = self.track.create_segment(MT(3, 4), MD(2, 4))50 await self.processQtEvents()51 self.renderWidget()52 with self.project.apply_mutations('test'):53 self.track.remove_segment(seg)54 await self.processQtEvents()55 self.renderWidget()56 async def test_events_changed(self):57 with self.project.apply_mutations('test'):58 seg = self.track.create_segment(MT(0, 4), MD(4, 4))59 seg.segment.add_event(MEVT(MT(0, 4), NOTE_ON(0, 60, 100)))60 seg.segment.add_event(MEVT(MT(1, 4), NOTE_OFF(0, 60)))61 with self._trackItem():62 with self.project.apply_mutations('test'):63 seg.segment.add_event(MEVT(MT(1, 4), NOTE_ON(0, 61, 100)))64 seg.segment.add_event(MEVT(MT(2, 4), NOTE_OFF(0, 61)))65 await self.processQtEvents()66 self.renderWidget()67 with self.project.apply_mutations('test'):68 while len(seg.segment.events) > 0:69 seg.segment.remove_event(seg.segment.events[0])70 await self.processQtEvents()71 self.renderWidget()72 async def test_events_edited(self):73 with self.project.apply_mutations('test'):74 seg = self.track.create_segment(MT(0, 4), MD(4, 4))75 seg.segment.add_event(MEVT(MT(0, 4), NOTE_ON(0, 60, 100)))76 seg.segment.add_event(MEVT(MT(1, 4), NOTE_OFF(0, 60)))77 with self._trackItem() as ti:78 editor = ti.findChild(track_ui.SegmentEditor, 'segment-editor[%016x]' % seg.id)79 assert editor is not None80 grid = editor.findChild(pianoroll.PianoRollGrid, 'grid')81 assert grid is not None82 with grid.collect_mutations():83 grid.addEvent(MEVT(MT(1, 4), NOTE_ON(0, 61, 100)))84 grid.addEvent(MEVT(MT(2, 4), NOTE_OFF(0, 61)))85 await self.processQtEvents()86 self.renderWidget()87 self.assertEqual(len(seg.segment.events), 4)88 async def test_scroll(self):89 with self.project.apply_mutations('test'):90 self.track.create_segment(MT(0, 4), MD(2, 4))91 with self._trackItem() as ti:92 yoff = ti.yOffset()93 await self.scrollWheel(-1)94 self.assertGreater(ti.yOffset(), yoff)95 await self.scrollWheel(1)96 self.assertEqual(ti.yOffset(), yoff)97 async def test_playback_pos(self):98 with self.project.apply_mutations('test'):99 self.track.create_segment(MT(0, 4), MD(2, 4))100 self.track.create_segment(MT(3, 4), MD(2, 4))101 self.track.create_segment(MT(5, 4), MD(2, 4))102 with self._trackItem() as ti:103 t = MT(0, 1)104 while t < MT(8, 4):105 ti.setPlaybackPosition(t)106 await self.processQtEvents()107 t += MD(1, 32)108 async def test_change_row_height(self):109 with self.project.apply_mutations('test'):110 self.track.create_segment(MT(0, 4), MD(4, 4))111 with self._trackItem() as ti:112 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(2, 4)), ti.height() // 2))113 menu = await self.openContextMenu()114 incr_button = menu.findChild(QtWidgets.QAbstractButton, 'incr-row-height')115 assert incr_button is not None116 decr_button = menu.findChild(QtWidgets.QAbstractButton, 'decr-row-height')117 assert decr_button is not None118 h = ti.gridYSize()119 incr_button.click()120 self.assertGreater(ti.gridYSize(), h)121 decr_button.click()122 self.assertEqual(ti.gridYSize(), h)123 async def test_move_segment(self):124 with self.project.apply_mutations('test'):125 seg = self.track.create_segment(MT(0, 4), MD(4, 4))126 with self._trackItem() as ti:127 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(1, 4)), ti.height() // 2))128 await self.pressMouseButton(Qt.LeftButton)129 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(3, 4)), ti.height() // 2))130 await self.releaseMouseButton(Qt.LeftButton)131 self.assertEqual(seg.time, MT(2, 4))132 async def test_resize_segment(self):133 with self.project.apply_mutations('test'):134 seg = self.track.create_segment(MT(0, 4), MD(4, 4))135 with self._trackItem() as ti:136 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(4, 4)), ti.height() // 2))137 await self.pressMouseButton(Qt.LeftButton)138 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(5, 4)), ti.height() // 2))139 await self.releaseMouseButton(Qt.LeftButton)140 self.assertEqual(seg.time, MT(0, 4))141 self.assertEqual(seg.segment.duration, MD(5, 4))142 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(0, 4)), ti.height() // 2))143 await self.pressMouseButton(Qt.LeftButton)144 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(2, 4)), ti.height() // 2))145 await self.releaseMouseButton(Qt.LeftButton)146 self.assertEqual(seg.time, MT(2, 4))147 self.assertEqual(seg.segment.duration, MD(3, 4))148 async def test_add_segment(self):149 assert len(self.track.segments) == 0150 with self._trackItem() as ti:151 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(2, 4)), ti.height() // 2))152 menu = await self.openContextMenu()153 await self.triggerMenuAction(menu, 'add-segment')154 self.assertEqual(len(self.track.segments), 1)155 self.assertEqual(self.track.segments[0].time, MT(2, 4))156 async def test_delete_segment(self):157 with self.project.apply_mutations('test'):158 self.track.create_segment(MT(0, 4), MD(4, 4))159 with self._trackItem() as ti:160 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(2, 4)), ti.height() // 2))161 menu = await self.openContextMenu()162 await self.triggerMenuAction(menu, 'delete-segment')163 self.assertEqual(len(self.track.segments), 0)164 async def test_split_segment(self):165 with self.project.apply_mutations('test'):166 self.track.create_segment(MT(0, 4), MD(4, 4))167 with self._trackItem() as ti:168 ti.setPlaybackPosition(MT(3, 4))169 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(3, 4)), ti.height() // 2))170 menu = await self.openContextMenu()171 await self.triggerMenuAction(menu, 'split-segment')172 self.assertEqual(len(self.track.segments), 2)173 self.assertEqual(self.track.segments[0].time, MT(0, 4))174 self.assertEqual(self.track.segments[0].segment.duration, MD(3, 4))175 self.assertEqual(self.track.segments[1].time, MT(3, 4))176 self.assertEqual(self.track.segments[1].segment.duration, MD(1, 4))177 async def test_select_segments(self):178 with self.project.apply_mutations('test'):179 ref1 = self.track.create_segment(MT(0, 4), MD(4, 4))180 ref2 = self.track.create_segment(MT(6, 4), MD(4, 4))181 ref3 = self.track.create_segment(MT(12, 4), MD(4, 4))182 ref4 = self.track.create_segment(MT(18, 4), MD(4, 4))183 with self._trackItem() as ti:184 selected = lambda: {segment.segmentRef().id for segment in ti.selection()}185 self.assertEqual(selected(), set())186 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(2, 4)), ti.height() // 2))187 await self.clickMouseButton(Qt.LeftButton)188 self.assertEqual(selected(), {ref1.id})189 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(8, 4)), ti.height() // 2))190 await self.clickMouseButton(Qt.LeftButton)191 self.assertEqual(selected(), {ref2.id})192 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(14, 4)), ti.height() // 2))193 await self.pressKey(Qt.Key_Control)194 await self.clickMouseButton(Qt.LeftButton)195 await self.releaseKey(Qt.Key_Control)196 self.assertEqual(selected(), {ref2.id, ref3.id})197 await self.pressKey(Qt.Key_Control)198 await self.clickMouseButton(Qt.LeftButton)199 await self.releaseKey(Qt.Key_Control)200 self.assertEqual(selected(), {ref2.id})201 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(11, 4)), ti.height() // 2))202 await self.clickMouseButton(Qt.LeftButton)203 self.assertEqual(selected(), set())204 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(8, 4)), ti.height() // 2))205 await self.clickMouseButton(Qt.LeftButton)206 await self.moveMouse(QtCore.QPoint(ti.timeToX(MT(20, 4)), ti.height() // 2))207 await self.pressKey(Qt.Key_Shift)208 await self.clickMouseButton(Qt.LeftButton)209 await self.releaseKey(Qt.Key_Shift)210 self.assertEqual(selected(), {ref2.id, ref3.id, ref4.id})211 async def test_select_all_segment(self):212 with self.project.apply_mutations('test'):213 ref1 = self.track.create_segment(MT(0, 4), MD(4, 4))214 ref2 = self.track.create_segment(MT(6, 4), MD(4, 4))215 with self._trackItem() as ti:216 menu = await self.openContextMenu()217 await self.triggerMenuAction(menu, 'select-all')218 self.assertEqual(219 {segment.segmentRef().id for segment in ti.selection()},220 {ref1.id, ref2.id})221 async def test_clear_selection_segment(self):222 with self.project.apply_mutations('test'):223 self.track.create_segment(MT(0, 4), MD(4, 4))224 self.track.create_segment(MT(6, 4), MD(4, 4))225 with self._trackItem() as ti:226 ti.addToSelection(ti.segments[0])227 menu = await self.openContextMenu()228 await self.triggerMenuAction(menu, 'clear-selection')...
segmentation.py
Source:segmentation.py
...85 create_segment : a function of two arguments (sequence, sequence range) that returns a line segment that approximates the sequence data in the specified range86 compute_error: a function of two argments (sequence, segment) that returns the error from fitting the specified line segment to the sequence data87 max_error: the maximum allowable line segment fitting error88 """89 segments = [create_segment(sequence,seq_range) for seq_range in zip(range(len(sequence))[:-1],range(len(sequence))[1:])]90 mergesegments = [create_segment(sequence,(seg1[0],seg2[2])) for seg1,seg2 in zip(segments[:-1],segments[1:])]91 mergecosts = [compute_error(sequence, segment) for segment in mergesegments]92 while min(mergecosts) < max_error:93 idx = mergecosts.index(min(mergecosts))94 segments[idx] = mergesegments[idx]95 del segments[idx+1]96 if idx > 0: 97 mergesegments[idx-1] = create_segment(sequence,(segments[idx-1][0],segments[idx][2])) # å 为å äºä¸ä¸ªåå§çç¹æ以æ´æ°åè¾¹çmergesegemnts98 mergecosts[idx-1] = compute_error(sequence,mergesegments[idx-1])99 if idx+1 < len(mergecosts):100 mergesegments[idx+1] = create_segment(sequence,(segments[idx][0],segments[idx+1][2])) # å 为å äºä¸ä¸ªåå§çç¹æ以æ´æ°åè¾¹çmergesegemnts101 mergecosts[idx+1] = compute_error(sequence,mergesegments[idx])102 del mergesegments[idx] # å 为mergesegmentsæ¯è·¨ä¸ä¸ªç¹mergeçæ以åºè¯¥å é¤è¿ä¸ªæ²¡æè·¨ç¹çmergeç¹103 del mergecosts[idx] # å é¤å¯¹åºçcostç¹ï¼ç»§ç»æ¾ä¸ä¸ä¸ªæå°costçmergeç¹104 return segments105 106 def _topdownsegment(sequence, create_segment, compute_error, max_error, seq_range=None):107 """108 Return a list of line segments that approximate the sequence.109 The list is computed using the bottom-up technique.110 Parameters111 ----------112 sequence : sequence to segment113 create_segment : a function of two arguments (sequence, sequence range) that returns a line segment that approximates the sequence data in the specified range114 compute_error: a function of two argments (sequence, segment) that returns the error from fitting the specified line segment to the sequence data115 max_error: the maximum allowable line segment fitting error116 """117 if not seq_range:118 seq_range = (0,len(sequence)-1)119 bestlefterror,bestleftsegment = float('inf'), None120 bestrighterror,bestrightsegment = float('inf'), None121 bestidx = None122 for idx in range(seq_range[0]+1,seq_range[1]):123 segment_left = create_segment(sequence,(seq_range[0],idx))124 error_left = compute_error(sequence,segment_left)125 segment_right = create_segment(sequence,(idx,seq_range[1]))126 error_right = compute_error(sequence, segment_right)127 if error_left + error_right < bestlefterror + bestrighterror:128 bestlefterror, bestrighterror = error_left, error_right129 bestleftsegment, bestrightsegment = segment_left, segment_right130 bestidx = idx131 if bestlefterror <= max_error:132 leftsegs = [bestleftsegment]133 else:134 leftsegs = _topdownsegment(sequence, create_segment, compute_error, max_error, (seq_range[0],bestidx))135 if bestrighterror <= max_error:136 rightsegs = [bestrightsegment]137 else:138 rightsegs = _topdownsegment(sequence, create_segment, compute_error, max_error, (bestidx,seq_range[1]))139 return leftsegs + rightsegs...
segment.py
Source:segment.py
...13 if not seq_range:14 seq_range = (0,len(sequence)-1)15 start = seq_range[0]16 end = start17 result_segment = create_segment(sequence,(seq_range[0],seq_range[1]))18 while end < seq_range[1]:19 end += 120 test_segment = create_segment(sequence,(start,end))21 error = compute_error(sequence,test_segment)22 if error <= max_error:23 result_segment = test_segment24 else:25 break26 if end == seq_range[1]:27 return [result_segment]28 else:29 return [result_segment] + slidingwindowsegment(sequence, create_segment, compute_error, max_error, (end-1,seq_range[1]))30 31def bottomupsegment(sequence, create_segment, compute_error, max_error):32 """33 Return a list of line segments that approximate the sequence.34 35 The list is computed using the bottom-up technique.36 37 Parameters38 ----------39 sequence : sequence to segment40 create_segment : a function of two arguments (sequence, sequence range) that returns a line segment that approximates the sequence data in the specified range41 compute_error: a function of two argments (sequence, segment) that returns the error from fitting the specified line segment to the sequence data42 max_error: the maximum allowable line segment fitting error43 44 """45 segments = [create_segment(sequence,seq_range) for seq_range in zip(range(len(sequence))[:-1],range(len(sequence))[1:])]46 mergesegments = [create_segment(sequence,(seg1[0],seg2[2])) for seg1,seg2 in zip(segments[:-1],segments[1:])]47 mergecosts = [compute_error(sequence,segment) for segment in mergesegments]48 while min(mergecosts) < max_error:49 idx = mergecosts.index(min(mergecosts))50 new_seg = create_segment(sequence, (segments[idx][0], segments[idx + 1][2]))51 segments[idx] = new_seg52 del segments[idx + 1]53 if idx > 0:54 merge_seg = create_segment(sequence, (segments[idx - 1][0], segments[idx][2]))55 mergecosts[idx - 1] = compute_error(sequence, merge_seg)56 if idx + 1 < len(mergecosts):57 merge_seg = create_segment(sequence, (segments[idx][0], segments[idx + 1][2]))58 mergecosts[idx] = compute_error(sequence, merge_seg)59 del mergecosts[idx]60 return segments61 62def topdownsegment(sequence, create_segment, compute_error, max_error, seq_range=None):63 """64 Return a list of line segments that approximate the sequence.65 66 The list is computed using the bottom-up technique.67 68 Parameters69 ----------70 sequence : sequence to segment71 create_segment : a function of two arguments (sequence, sequence range) that returns a line segment that approximates the sequence data in the specified range72 compute_error: a function of two argments (sequence, segment) that returns the error from fitting the specified line segment to the sequence data73 max_error: the maximum allowable line segment fitting error74 75 """76 if not seq_range:77 seq_range = (0,len(sequence)-1)78 bestlefterror,bestleftsegment = float('inf'), None79 bestrighterror,bestrightsegment = float('inf'), None80 bestidx = None81 for idx in range(seq_range[0]+1,seq_range[1]):82 segment_left = create_segment(sequence,(seq_range[0],idx))83 error_left = compute_error(sequence,segment_left)84 segment_right = create_segment(sequence,(idx,seq_range[1]))85 error_right = compute_error(sequence, segment_right)86 if error_left + error_right < bestlefterror + bestrighterror:87 bestlefterror, bestrighterror = error_left, error_right88 bestleftsegment, bestrightsegment = segment_left, segment_right89 bestidx = idx90 91 if bestlefterror <= max_error:92 leftsegs = [bestleftsegment]93 else:94 leftsegs = topdownsegment(sequence, create_segment, compute_error, max_error, (seq_range[0],bestidx))95 96 if bestrighterror <= max_error:97 rightsegs = [bestrightsegment]98 else:99 rightsegs = topdownsegment(sequence, create_segment, compute_error, max_error, (bestidx,seq_range[1]))100 101 return leftsegs + rightsegs102def m_swab(sequence, create_segment, compute_error, max_error, buffer_size=80):103 """104 Described in Van Laerhoven, Kristof, and Bernt Schiele.105 "An Empirical Study of Time Series Approximation Algorithms for Wearable Accelerometers." (2009).106 Return a list of line segments that approximate the sequence.107 The list is computed using the bottom-up technique.108 Parameters109 ----------110 sequence : sequence to segment111 create_segment : a function of two arguments (sequence, sequence range) that returns a line segment that approximates the sequence data in the specified range112 compute_error: a function of two argments (sequence, segment) that returns the error from fitting the specified line segment to the sequence data113 max_error: the maximum allowable line segment fitting error114 """115 segs = []116 win_left = 0117 win_right = buffer_size-1118 seq_range = (0, len(sequence)-1)119 while True: #while new data:120 swabbuf = sequence[win_left:win_right]121 # Bottom-Up segmentation of buffer122 T = bottomupsegment(swabbuf, create_segment, compute_error, max_error)123 # add left-most segment from BU:124 segs.append(T[0])125 n = len(segs)126 # merge last segments if slope is equal127 if n > 2:128 last_slope = (segs[-1][3] - segs[-1][1]) // (segs[-1][2] - segs[-1][0])129 b_last_slope = (segs[-2][3] - segs[-2][1]) // (segs[-2][2] - segs[-2][0])130 if last_slope == b_last_slope:131 # merge segments132 new_segs = segs[:-2]133 merged = create_segment(sequence, (segs[-2][0], segs[-1][2]))134 new_segs.append(merged)135 segs = new_segs136 n -= 1137 # shift left of buffer window:138 win_left += segs[-1][0]139 # shift right of buffer window:140 if win_right < seq_range[1]:141 i = win_right + 1142 # get sign of the slope143 s = np.sign(sequence[i] - sequence[i-1])144 while np.sign(sequence[i] - sequence[i-1]) == s:145 i += 1146 if i >= seq_range[1]:147 i -= 1...
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!!