Best Python code snippet using Airtest
test_widget_label.py
Source:test_widget_label.py
...43 'dolore eu fugiat nulla pariatur.', 'Excepteur sint occaecat cupidatat',44 'non proident, sunt in culpa qui', 'officia deserunt mollit anim id',45 'est laborum.']46 for i in range(len(label)):47 self.assertEqual(label[i].get_title(), label_text[i])48 # Split label49 label = menu.add.label('This label should split.\nIn two lines')50 self.assertEqual(label[0].get_title(), 'This label should split.')51 self.assertEqual(label[1].get_title(), 'In two lines')52 # Split label, but also with maxchar enabled53 label = menu.add.label(54 'This label should split, this line is really long so it should split.\nThe second line', max_char=40)55 self.assertEqual(label[0].get_title(), 'This label should split, this line is')56 self.assertEqual(label[1].get_title(), 'really long so it should split.')57 self.assertEqual(label[2].get_title(), 'The second line')58 # Split label with -1 maxchar59 label = menu.add.label(60 'This label should split, this line is really long so it should split.\nThe second line', max_char=-1)61 self.assertEqual(label[0].get_title(), 'This label should split, this line is really')62 self.assertEqual(label[1].get_title(), 'long so it should split.')63 self.assertEqual(label[2].get_title(), 'The second line')64 # Split label with -1 double \n65 label = menu.add.label('a\n\nb\n\nc', max_char=-1)66 self.assertEqual(label[0].get_title(), 'a')67 self.assertEqual(label[1].get_title(), '')68 self.assertEqual(label[2].get_title(), 'b')69 self.assertEqual(label[3].get_title(), '')70 self.assertEqual(label[4].get_title(), 'c')71 # Add underline72 label = menu.add.label('nice')73 self.assertEqual(label._decorator._total_decor(), 0)74 label.add_underline((0, 0, 0), 1, 1, force_render=True)75 self.assertEqual(label._decorator._total_decor(), 1)76 # Test generator77 gen_index = [-1]78 def generator() -> str:79 """80 Label generator.81 """82 s = ('a', 'b', 'c')83 gen_index[0] = (gen_index[0] + 1) % len(s)84 return s[gen_index[0]]85 self.assertNotIn(label, menu._update_widgets)86 label.set_title_generator(generator)87 self.assertIn(label, menu._update_widgets)88 self.assertEqual(label.get_title(), 'nice')89 label._render()90 self.assertEqual(label.get_title(), 'nice')91 label.render()92 self.assertEqual(label.get_title(), 'nice')93 label.update([])94 self.assertEqual(label.get_title(), 'a')95 label.update([])96 self.assertEqual(label.get_title(), 'b')97 label.update([])98 self.assertEqual(label.get_title(), 'c')99 label.update([])100 self.assertEqual(label.get_title(), 'a')101 # Update title with generator, it should raise a warning102 label.set_title('this should be overridden')103 label.set_title('this should be overridden 2')104 label.update([])105 self.assertEqual(label.get_title(), 'b')106 # Remove generator, it also should remove the widget from update107 label.set_title_generator(None)108 self.assertNotIn(label, menu._update_widgets)109 label.update([])110 self.assertEqual(label.get_title(), 'b')111 self.assertIsNone(label._title_generator)112 # Label set to empty113 label_e = menu.add.label('new')114 self.assertRaises(ValueError, lambda: label_e.set_value(''))115 label_e.set_title('')116 label_e.draw(surface)117 # Test underline118 label_u = menu.add.label('underlined', underline=True)119 self.assertIsNotNone(label_u._last_underline[1])120 def test_clock(self) -> None:121 """122 Test clock.123 """124 menu = MenuUtils.generic_menu()125 clock = menu.add.clock()126 self.assertNotEqual(clock.get_title(), '')127 # Check title format128 self.assertRaises(AssertionError, lambda: menu.add.clock(title_format='bad'))129 self.assertIsInstance(clock, Label)130 def test_empty_title(self) -> None:131 """132 Test empty title.133 """134 menu = MenuUtils.generic_menu()135 label = menu.add.label('')136 p = label._padding137 self.assertEqual(label.get_width(), p[1] + p[3])138 self.assertEqual(label.get_height(), p[0] + p[2] + 41 if PYGAME_V2 else 42)139 def test_value(self) -> None:140 """...
js.service.ts
Source:js.service.ts
...25}26ghost = factory_movie('Ghost in the shell');27matrix = factory_movie('Matrix');28 29alert(ghost.get_title());30alert(matrix.get_title());31 32ghost.set_title('ê³µê°ê¸°ëë');33 34alert(ghost.get_title());35alert(matrix.get_title());36`;37 paragraph1 =38 `ì ììì²ë¼ titleì´ë¼ë ì¸ë¶í¨ìì parameterì 39 ì¸ë¶í¨ìë¡ë ì ê·¼í ì ìì¼ë¯ë¡ privateë³ìì ì±ì§ì ëë¤.40 íì§ë§ ì¸ë¶í¨ìê° ë§ë£ë ì´íìë ë´ë¶í¨ìë titleì ì ê·¼í ì ìì¼ë¯ë¡ get setí¨ì를41 ë´ë¶í¨ìë¡ ì ì íë¤.`;42 code3 =43 `44var arr = []45for(var i = 0; i < 5; i++){46 arr[i] = function(){47 return i;48 }49}50for(var index in arr) {51 console.log(arr[index]());52}53`;54 code4 = `55var arr = []56for(var i = 0; i < 5; i++){57 arr[i] = function(id) {58 return function(){59 return id;60 }61 }(i);62}63for(var index in arr) {64 console.log(arr[index]());65}66`;67 paragraph2 =68 `69ì«ì 5ë§ 5ë² ì¶ë ¥ëë¤. 70`71 paragraph3 =72 `73ìëí ëë¡ 0ë¶í° 4 ê¹ì§ ììëë¡ ì¶ë ¥ëë¤ 74`75 code5 =76 `77var person = {78 'name' : 'egoing',79 'introduce' : function(){80 return 'My name is '+this.name;81 }82}`;83 code6 =84 `85function Person(name){86 this.name = name;87 this.introduce = function(){88 return 'My name is '+this.name; 89 } 90}91var p1 = new Person('egoing');92 93var p2 = new Person('leezche');`;94 paragraph4 = `ê°ì¥ ë¨ìí ê°ì²´ ìì± ë°©ë²ì¼ë¡ ë¨ìí ë§í¼ ë¹í¨ì¨ì ì´ë¤.`;95 paragraph5 = `ì¬ê¸°ì function Personì ìì±ìì´ë¤. jsììë class를 ë°ë¡96ì ì íì§ ìê³ ë¤ìê³¼ ê°ì´ ìì±ìë§ì¼ë¡ ê°ì²´ë¥¼ íííë©° ì´ë°ìì¼ë¡ ê°ì²´ë¥¼ ìì±íë ê²ì´ 97ì²ì ììë³´ë¤ í¨ì¬ í¨ì¨ ì ì´ë¤.`;98 p6 = `thisë í´ë¹ methodê° ììëì´ ìë ê°ì²´ë¥¼ ì미íë¤.`;99 code7=100 `101function func(){102 if(window === this){103 document.write("window === this");104 }105}106func();107`;108 code8=109 `110var o = {111 func : function(){112 if(o === this){113 document.write("o === this");114 }115 }116}117o.func();`;118 code9 =119 `120var funcThis = null; 121 122function Func(){123 funcThis = this;124}125var o1 = Func();126if(funcThis === window){127 document.write('window <br />');128}129 130var o2 = new Func();131if(funcThis === o2){132 document.write('o2 <br />');133}`;134 code10 =135 `136var o = {}137var p = {}138function func(){139 switch(this){140 case o:141 document.write('o<br />');142 break;143 case p:144 document.write('p<br />');145 break;146 case window:147 document.write('window<br />');148 break; 149 }150}151func();152func.apply(o);153func.apply(p);`;154 section1 = {155 h4: "closure1.js",156 code:`157function outter(){158 var title = 'coding everybody'; 159 return function(){ 160 alert(title);161 }162}163inner = outter();164inner();`,165 p:""166 };167 section2 = {168 h4:"closure2.js",169 code : `170function factory_movie(title){171 return {172 get_title : function (){173 return title;174 },175 set_title : function(_title){176 title = _title177 }178 }179}180ghost = factory_movie('Ghost in the shell');181matrix = factory_movie('Matrix');182 183alert(ghost.get_title());184alert(matrix.get_title());185 186ghost.set_title('ê³µê°ê¸°ëë');187 188alert(ghost.get_title());189alert(matrix.get_title());`,190 p:`ì ììì²ë¼ titleì´ë¼ë ì¸ë¶í¨ìì parameterì 191 ì¸ë¶í¨ìë¡ë ì ê·¼í ì ìì¼ë¯ë¡ privateë³ìì ì±ì§ì ëë¤.192 íì§ë§ ì¸ë¶í¨ìê° ë§ë£ë ì´íìë ë´ë¶í¨ìë titleì ì ê·¼í ì ìì¼ë¯ë¡ get setí¨ì를193 ë´ë¶í¨ìë¡ ì ì íë¤.`194 };195 section3 = {196 h4:"wrong.js",197 code:this.code3,198 p:this.paragraph2199 };200 section4 = {201 h4:"nice.js",202 code:this.code4,203 p:this.paragraph3...
booksdatasourcetests.py
Source:booksdatasourcetests.py
...35 self.assertTrue(len(authors) == 0)36 def test_unique_book(self):37 books = self.data_source_long.books('Sula')38 self.assertTrue(len(books) == 1)39 self.assertTrue(books[0].get_title() == 'Sula')40 def test_book_not_in_file(self):41 books = self.data_source_long.books('Cat')42 self.assertTrue(len(books) == 0)43 def test_books_none(self):44 books = self.data_source_short.books(None)45 self.assertTrue(len(books) == 3)46 self.assertTrue(books[0].get_title() == 'All Clear')47 self.assertTrue(books[1].get_title() == 'Jane Eyre')48 self.assertTrue(books[2].get_title() == 'The Tenant of Wildfell Hall')49 def test_year_sorting(self):50 books = self.data_source_short.books('All', 'year')51 self.assertTrue(len(books) == 2)52 self.assertTrue(books[0].get_title() == 'The Tenant of Wildfell Hall')53 self.assertTrue(books[1].get_title() == 'All Clear')54 def test_title_sorting_explicit(self):55 books = self.data_source_short.books('All', 'title')56 self.assertTrue(len(books) == 2)57 self.assertTrue(books[0].get_title() == 'All Clear')58 self.assertTrue(books[1].get_title() == 'The Tenant of Wildfell Hall')59 def test_title_sorting_default(self):60 books = self.data_source_short.books('All')61 self.assertTrue(len(books) == 2)62 self.assertTrue(books[0].get_title() == 'All Clear')63 self.assertTrue(books[1].get_title() == 'The Tenant of Wildfell Hall')64 def test_books_between_none(self):65 books = self.data_source_short.books_between_years()66 self.assertTrue(len(books) == 3)67 self.assertTrue(books[0].get_title() == 'Jane Eyre')68 self.assertTrue(books[1].get_title() == 'The Tenant of Wildfell Hall')69 self.assertTrue(books[2].get_title() == 'All Clear')70 def test_books_between_tiebreaker(self):71 books = self.data_source_long.books_between_years(1995,1996)72 self.assertTrue(len(books) == 2)73 self.assertTrue(books[0].get_title() == 'Neverwhere')74 self.assertTrue(books[1].get_title() == 'Thief of Time')75 def test_books_between_no_end(self):76 books = self.data_source_long.books_between_years(2020, None)77 self.assertTrue(len(books) == 2)78 self.assertTrue(books[0].get_title() == 'Boys and Sex')79 self.assertTrue(books[1].get_title() == 'The Invisible Life of Addie LaRue')80 def test_books_between_no_start(self):81 books = self.data_source_long.books_between_years(None,1770)82 self.assertTrue(len(books) == 1)83 self.assertTrue(books[0].get_title() == 'The Life and Opinions of Tristram Shandy, Gentleman')84if __name__ == '__main__':...
3 private variable.js
Source:3 private variable.js
...5 }6}7ghost = factory_movie('Ghost in the shell');8matrix = factory_movie('Matrix');9alert(ghost.get_title());10alert(matrix.get_title());11ghost.set_title('ê³µê°ê¸°ëë');12alert(ghost.get_title());13alert(matrix.get_title());14// 1. í´ë¡ì ë ê°ì²´ì ë©ìëììë ì¬ì©í ì ìë¤. ìì ìì ë í¨ìì 리í´ê°ì¼ë¡ ê°ì²´ë¥¼ ë°ííê³ ìë¤. ì´ ê°ì²´ë ë©ìë get_titleê³¼ set_titleì ê°ì§ê³ ìë¤. ì´ ë©ìëë¤ì ì¸ë¶í¨ìì¸ factory_movieì ì¸ìê°ì¼ë¡ ì ë¬ë ì§ìë³ì titleì ì¬ì©íê³ ìë¤.15// 2. ëì¼í ì¸ë¶í¨ì ììì ë§ë¤ì´ì§ ë´ë¶í¨ìë ë©ìëë ì¸ë¶í¨ìì ì§ìë³ì를 ê³µì íë¤. 13íìì ì¤íë set_titleì ì¸ë¶í¨ì factory_movieì ì§ìë³ì titleì ê°ì 'ê³µê°ê¸°ëë'ë¡ ë³ê²½íë¤. 15íìì ghost.get_title();ì ê°ì´ 'ê³µê°ê¸°ëë'ì¸ ê²ì set_titleì get_title í¨ìê° titleì ê°ì ê³µì íê³ ìë¤ë ì미ë¤.16// 3. ê·¸ë°ë° ëê°ì ì¸ë¶í¨ì factory_movie를 ê³µì íê³ ìë ghostì matrixì get_titleì ê²°ê³¼ë ìë¡ ê°ê° ë¤ë¥´ë¤. ê·¸ê²ì ì¸ë¶í¨ìê° ì¤íë ëë§ë¤ ìë¡ì´ ì§ìë³ì를 í¬í¨íë í´ë¡ì ê° ìì±ë기 ë문ì ghostì matrixë ìë¡ ìì í ë
립ë ê°ì²´ê° ëë¤.17// 4. factory_movieì ì§ìë³ì titleì 2íìì ì ìë ê°ì²´ì ë©ìëììë§ ì ê·¼ í ì ìë ê°ì´ë¤. ì´ ë§ì titleì ê°ì ì½ê³ ìì í ì ìë ê²ì factory_movie ë©ìë를 íµí´ì ë§ë¤ì´ì§ ê°ì²´ ë¿ì´ë¼ë ì미ë¤. JavaScriptë 기본ì ì¼ë¡ Privateí ìì±ì ì§ìíì§ ìëë°, í´ë¡ì ì ì´ë¬í í¹ì±ì ì´ì©í´ì Privateí ìì±ì ì¬ì©í ì ìê²ëë¤.18// ì°¸ê³ Private ìì±ì ê°ì²´ì ì¸ë¶ììë ì ê·¼ í ì ìë ì¸ë¶ì ê°ì¶°ì§ ìì±ì´ë ë©ìë를 ì미íë¤. ì´ë¥¼ íµí´ì ê°ì²´ì ë´ë¶ììë§ ì¬ì©í´ì¼ íë ê°ì´ ë
¸ì¶ë¨ì¼ë¡ì ì길 ì ìë ì¤ë¥ë¥¼ ì¤ì¼ ì ìë¤. ìë°ì ê°ì ì¸ì´ììë ì´ë¬í í¹ì±ì ì¸ì´ ë¬¸ë² ì°¨ììì ì§ìíê³ ìë¤....
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!!