Best Python code snippet using SeleniumBase
test_search.py
Source:test_search.py
...126 ],127 )128 def test_search_objects(self):129 # Run a particular search and return a list of results130 def do_search(search_function, keywords):131 return list(search_function(SearchView.Term(keywords)))132 view = SearchView()133 # basic tests for antiquarian134 a1 = Antiquarian.objects.create(name="findme", re_code="1")135 a2 = Antiquarian.objects.create(name="foo", re_code="2")136 self.assertEqual(do_search(view.antiquarian_search, "findme"), [a1])137 self.assertEqual(do_search(view.antiquarian_search, "FinDMe"), [a1])138 self.assertEqual(do_search(view.antiquarian_search, "foo"), [a2])139 self.assertEqual(do_search(view.antiquarian_search, "fOo"), [a2])140 self.assertEqual(do_search(view.antiquarian_search, "F"), [a1, a2])141 # topics142 t1 = Topic.objects.create(name="topic", order=1)143 t2 = Topic.objects.create(name="pictures", order=2)144 self.assertEqual(do_search(view.topic_search, "topic"), [t1])145 self.assertEqual(do_search(view.topic_search, "TOPIc"), [t1])146 self.assertEqual(do_search(view.topic_search, "picture"), [t2])147 self.assertEqual(do_search(view.topic_search, "PiCTureS"), [t2])148 self.assertEqual(do_search(view.topic_search, "PIC"), [t1, t2])149 # works150 w1 = Work.objects.create(name="work")151 w2 = Work.objects.create(name="nothing")152 self.assertEqual(do_search(view.work_search, "work"), [w1])153 self.assertEqual(do_search(view.work_search, "WORK"), [w1])154 self.assertEqual(do_search(view.work_search, "nothing"), [w2])155 self.assertEqual(do_search(view.work_search, "NothInG"), [w2])156 self.assertEqual(do_search(view.work_search, "O"), [w2, w1])157 cw = CitingWork.objects.create(title="citing_work")158 # fragments159 f1 = Fragment.objects.create()160 f1.original_texts.create(161 content="findme with your search powers",162 reference="louisa may alcott",163 citing_work=cw,164 )165 f2 = Fragment.objects.create()166 f2.original_texts.create(167 content="not$me",168 reference="daisy ma<>,./?;'#:@~[]{}-=_+!\"£$%^&*()\\|y cooper",169 citing_work=cw,170 )171 self.assertEqual(do_search(view.fragment_search, "findme yovr"), [f1])172 self.assertEqual(do_search(view.fragment_search, "findme not"), [])173 self.assertEqual(174 do_search(view.fragment_search, 'findme "with yovr" powers'), [f1]175 )176 self.assertEqual(177 do_search(view.fragment_search, 'findme "with yovr powers"'), []178 )179 self.assertEqual(do_search(view.fragment_search, "FINDME"), [f1])180 self.assertEqual(do_search(view.fragment_search, "notme"), [f2])181 self.assertEqual(do_search(view.fragment_search, "No!TMe"), [f2])182 self.assertEqual(do_search(view.fragment_search, "Me"), [f1, f2])183 self.assertEqual(do_search(view.fragment_search, "may"), [f1, f2])184 self.assertEqual(185 do_search(view.fragment_search, "m!£$%^&*()_+-=|\\{[}]:;@'~#<,>.?/ay"),186 [f1, f2],187 )188 self.assertEqual(do_search(view.fragment_search, "mav"), [])189 self.assertEqual(do_search(view.fragment_search, 'alcott "louisa may"'), [f1])190 self.assertEqual(do_search(view.fragment_search, 'may "louisa alcott"'), [])191 f3 = Fragment.objects.create()192 f3.original_texts.create(content="de uita Uaticani", citing_work=cw)193 f4 = Fragment.objects.create()194 f4.original_texts.create(content="vita brevIS", citing_work=cw)195 self.assertEqual(do_search(view.fragment_search, "vita"), [f3, f4])196 self.assertEqual(do_search(view.fragment_search, "bREUIs"), [f4])197 t1 = Testimonium.objects.create()198 t1.original_texts.create(content="findme", citing_work=cw)199 t2 = Testimonium.objects.create()200 t2.original_texts.create(content="notme", citing_work=cw)201 self.assertEqual(do_search(view.testimonium_search, "findme"), [t1])202 self.assertEqual(do_search(view.testimonium_search, "FINDME"), [t1])203 self.assertEqual(do_search(view.testimonium_search, "notme"), [t2])204 self.assertEqual(do_search(view.testimonium_search, "NoTMe"), [t2])205 self.assertEqual(do_search(view.testimonium_search, "Me"), [t1, t2])206 # fragments with apparatus criticus207 data = {"content": "content", "citing_work": cw}208 f1 = Fragment.objects.create()209 o1 = f1.original_texts.create(**data)210 o1.apparatus_criticus_items.create(content="stuff")211 t1 = Testimonium.objects.create()212 o2 = t1.original_texts.create(**data)213 o2.apparatus_criticus_items.create(content="nonsense")214 f2 = AnonymousFragment.objects.create()215 o3 = f2.original_texts.create(**data)216 o3.apparatus_criticus_items.create(content="rubbish")217 self.assertEqual(do_search(view.apparatus_criticus_search, "TuF"), [f1])218 self.assertEqual(do_search(view.apparatus_criticus_search, "TVF"), [f1])219 self.assertEqual(do_search(view.apparatus_criticus_search, "bBi"), [f2])220 self.assertEqual(do_search(view.apparatus_criticus_search, "nseN"), [t1])221 self.assertEqual(do_search(view.apparatus_criticus_search, "s"), [f1, f2, t1])222 self.assertEqual(do_search(view.apparatus_criticus_search, "content"), [])223 # bibliography224 parent = TextObjectField.objects.create(content="foo")225 data = {"authors": "Aab, W", "title": "The Roman Age", "parent": parent}226 b1 = BibliographyItem.objects.create(**data)227 data = {"authors": "Beeb, Z", "title": "The Roman Era", "parent": parent}228 b2 = BibliographyItem.objects.create(**data)229 self.assertEqual(do_search(view.bibliography_search, "aab"), [b1])230 self.assertEqual(do_search(view.bibliography_search, "EE"), [b2])231 self.assertEqual(do_search(view.bibliography_search, "romAN"), [b1, b2])232 # anonymous fragments vs. apposita233 data = {"content": "raddish", "citing_work": cw}234 f1 = Fragment.objects.create()235 af1 = AnonymousFragment.objects.create()236 o1 = af1.original_texts.create(**data)237 af2 = AnonymousFragment.objects.create()238 o2 = af2.original_texts.create(**data)239 # Create appositum link for one of the anonymous fragments240 AppositumFragmentLink.objects.create(anonymous_fragment=af1, linked_to=f1)241 self.assertEqual(242 do_search(view.anonymous_fragment_search, "raddish"), [af1, af2]243 )244 self.assertEqual(do_search(view.appositum_search, "raddish"), [af1])245 # citing authors246 ca1 = CitingAuthor.objects.create(name="Alice")247 ca2 = CitingAuthor.objects.create(name="Felicity")248 self.assertEqual(do_search(view.citing_author_search, "al"), [ca1])249 self.assertEqual(do_search(view.citing_author_search, "fe"), [ca2])250 self.assertEqual(do_search(view.citing_author_search, "lic"), [ca1, ca2])251 # citing works252 cw1 = CitingWork.objects.create(title="Opus", edition="Book one", author=ca1)253 cw2 = CitingWork.objects.create(title="Book", edition="Sixth", author=ca2)254 self.assertEqual(do_search(view.citing_work_search, "opu"), [cw1])255 self.assertEqual(do_search(view.citing_work_search, "xth"), [cw2])256 self.assertCountEqual(do_search(view.citing_work_search, "ook"), [cw1, cw2])257 def test_search_snippets(self):258 raw_content = (259 "Lorem ipsum dolor sit amet, <span class='test consectatur'>"260 "consectetur</span> adipiscing <strong>elit</strong>, sed do "261 "eiusmod tempor incididunt ut labore et dolore magna aliqua"262 )263 search_term = "consectetur"264 expected_snippet = (265 'Lorem ipsum dolor sit amet <span class="search-snippet">'266 "consectetur</span> adipiscing elit sed do eiusmod ..."267 )268 view = SearchView()269 cw = CitingWork.objects.create(title="citing_work")270 # fragments...
keyIndexSearchingSoritng.py
Source:keyIndexSearchingSoritng.py
...32 for i in a:33 if i > max_value:34 max_value = i35 return max_value36 def do_search(self, val):37 size_k = len(self.k)38 if self.min >= 0:39 if val < size_k and val >= 0 and self.k[val] > 0:40 return "true"41 else:42 return "false"43 else:44 temp = val + (self.min * (-1))45 if temp < size_k and temp >= 0 and self.k[temp] > 0:46 return "true"47 else:48 return "false"49 def do_sort(self):50 global a51 sorted_arr = [0] * len(a)52 if self.min >= 0:53 idx = 054 for i in range(len(self.k)):55 if self.k[i] > 0:56 counter = self.k[i]57 while counter != 0:58 sorted_arr[idx] = i59 counter = counter - 160 idx += 161 return sorted_arr62 else:63 idx = 064 for i in range(len(self.k)):65 if self.k[i] > 0:66 counter = self.k[i]67 while counter != 0:68 sorted_arr[idx] = i + self.min69 counter = counter - 170 idx += 171 return sorted_arr72 # print(a)73# ============================================ Tester Code ===========================================================74# ============================================= Input-1 ==============================================================75accuracy_flag = True76a = [0, -1, -2, -3, -4, -5]77obj_1 = KeyIndex(a)78print("For input-1 :")79print(obj_1.do_search(100)) # Output should be false80if obj_1.do_search(100) != "false":81 accuracy_flag = False82print(obj_1.do_search(-5)) # Output should be true83if obj_1.do_search(-5) != "true":84 accuracy_flag = False85print(obj_1.do_sort()) # Output should be [-5, -4, -3, -2, -1, 0]86if obj_1.do_sort() != [-5, -4, -3, -2, -1, 0]:87 accuracy_flag = False88print()89# =========================================== Input-2 ================================================================90a = [4, -2, 3, -4, 7, 4]91obj_2 = KeyIndex(a)92print("For input-2 :")93print(obj_2.do_search(70)) # Output should be false94if obj_2.do_search(70) != "false":95 accuracy_flag = False96print(obj_2.do_search(4)) # Output should be true97if obj_2.do_search(4) != "true":98 accuracy_flag = False99print(obj_2.do_sort()) # Output should be [-4, -2, 3, 4, 4, 7]100if obj_2.do_sort() != [-4, -2, 3, 4, 4, 7]:101 accuracy_flag = False102print()103# ========================================== Input-3 =================================================================104a = [4, 2, 3, 4, 7, 4]105obj_3 = KeyIndex(a)106print("For input-3 :")107print(obj_3.do_search(99)) # Output should be false108if obj_3.do_search(99) != "false":109 accuracy_flag = False110print(obj_3.do_search(3)) # Output should be true111if obj_3.do_search(3) != "true":112 accuracy_flag = False113print(obj_3.do_sort()) # Output should be [2, 3, 4, 4, 4, 7]114if obj_3.do_sort() != [2, 3, 4, 4, 4, 7]:115 accuracy_flag = False116print()117# ====================================== Accuracy =====================================================================118if accuracy_flag:119 print("TESTING: \n All the methods in the KeyIndex class is working properly")120else:...
test_xv.py
Source:test_xv.py
...5logic = XvSearchLogic()6class TestXvSearchLogic(unittest.TestCase):7 """Test TestXvSearchLogic"""8 def test_search(self):9 logic.do_search('pov jav bj')10 logic.do_search('pov jav bj')11 logic.do_search('pov jav ass')12 logic.do_search('pov jav ass')13 logic.do_search('pov jav bj')14 logic.do_search('pov jav bj')15 logic.do_search('pov jav bj')16 self.assertEqual(logic.get_top3_keywords()[0], 'pov jav bj')17 self.assertEqual(logic.get_top3_keywords()[1], 'pov jav ass')18 logic.do_search('jav bj', 1)19 logic.do_search('jav bj', 2)20 logic.do_search('jav bj', 3)21 logic.do_search('jav ass')22 logic.do_search('jav ass')23 self.assertEqual(logic.get_top3_keywords()[0], 'pov jav bj')24 def test_cache(self):25 logic.do_search('jav bj')26 cache = logic.get_cache('jav bj-0')27 self.assertFalse(cache is False)28 def test_get_video(self):29 vid = '28605129'30 data = logic.get_video(vid)31 src1 = data['src']32 data = logic.get_video(vid)33 src2 = data['src']34 self.assertEqual(src1, src2)35 def test_star(self):36 vid = '28605129'37 data = logic.get_video(vid)38 star1 = data['star']39 logic.star(vid)...
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!!