Best Python code snippet using tempest_python
test_circular_linked_list.py
Source:test_circular_linked_list.py
...12 if mode == 0:13 self.list = CircularLinkedList()14 elif mode == 1:15 self.list = ConcurrentCircularLinkedList()16 self._assert_empty()17 18 @parameterized.expand(_test_params)19 def test_add_first(self, name, mode):20 self._setUp(mode)21 self.list.add_first("Node1")22 self._assert_list_size(1)23 self.assertEquals("Node1", self.list.head.data)24 self.assertEquals("Node1", self.list.tail.data)25 26 # It's a circular list so it should point to itself27 self.assertEquals("Node1", self.list.head.next.data)28 self.assertEquals("Node1", self.list.tail.next.data)29 # Add a second node first30 self.list.add_first("Node0")31 self._assert_list_size(2)32 self.assertEquals("Node0", self.list.head.data)33 self.assertEquals("Node1", self.list.head.next.data)34 self.assertEquals("Node0", self.list.head.next.next.data)35 36 self.assertEquals("Node1", self.list.tail.data)37 self.assertEquals("Node0", self.list.tail.next.data)38 self.assertEquals("Node1", self.list.tail.next.next.data)39 @parameterized.expand(_test_params)40 def test_add(self, name, mode):41 self._setUp(mode)42 self.list.add("Node0")43 self._assert_list_size(1)44 self.assertEquals("Node0", self.list.head.data)45 self.assertEquals("Node0", self.list.tail.data)46 self.assertEquals("Node0", self.list.head.next.data)47 self.assertEquals("Node0", self.list.tail.next.data)48 # Add a second node49 self.list.add("Node1")50 self._assert_list_size(2)51 self.assertEquals("Node0", self.list.head.data)52 self.assertEquals("Node1", self.list.tail.data)53 self.assertEquals("Node1", self.list.head.next.data)54 self.assertEquals("Node0", self.list.tail.next.data)55 self.assertEquals("Node0", self.list.head.next.next.data)56 self.assertEquals("Node1", self.list.tail.next.next.data)57 @parameterized.expand(_test_params)58 def test_add_first_unique(self, name, mode):59 self._setUp(mode)60 self.list.add_first("Node1")61 self._assert_list_size(1)62 self.assertTrue("Node1" in self.list.indexes)63 self.list.add_first("Node1")64 self._assert_list_size(1)65 self.assertEquals(1, len(self.list.indexes))66 self.list.remove("Node1")67 self._assert_empty()68 self.assertFalse("Node1" in self.list.indexes)69 self.assertEquals(0, len(self.list.indexes))70 self.list.add_first("Node1")71 self._assert_list_size(1)72 self.assertTrue("Node1" in self.list.indexes)73 self.assertEquals(1, len(self.list.indexes))74 @parameterized.expand(_test_params)75 def test_add_unique(self, name, mode):76 self._setUp(mode)77 self.list.add("Node1")78 self._assert_list_size(1)79 self.assertTrue("Node1" in self.list.indexes)80 self.list.add("Node1")81 self._assert_list_size(1)82 self.assertEquals(1, len(self.list.indexes))83 self.list.remove_index(0)84 self._assert_empty()85 self.assertFalse("Node1" in self.list.indexes)86 self.assertEquals(0, len(self.list.indexes))87 self.list.add("Node1")88 self._assert_list_size(1)89 self.assertTrue("Node1" in self.list.indexes)90 self.assertEquals(1, len(self.list.indexes))91 @parameterized.expand(_test_params)92 def test_peek_add(self, name, mode):93 self._setUp(mode)94 self.list.add("Node1")95 self._assert_list_size(1)96 first = self.list.peek()97 self.assertEquals("Node1", first)98 self._assert_list_size(1)99 self.list.add("Node2")100 first = self.list.peek()101 self.assertEquals("Node1", first)102 self._assert_list_size(2)103 @parameterized.expand(_test_params)104 def test_peek_add_first(self, name, mode):105 self._setUp(mode)106 self.list.add_first("Node1")107 self._assert_list_size(1)108 first = self.list.peek()109 self.assertEquals("Node1", first)110 self._assert_list_size(1)111 self.list.add_first("Node0")112 first = self.list.peek()113 self.assertEquals("Node0", first)114 self._assert_list_size(2)115 @parameterized.expand(_test_params)116 def test_poll_add(self, name, mode):117 self._setUp(mode)118 self.list.add("Node1")119 first = self.list.poll()120 self.assertEquals("Node1", first)121 self._assert_empty()122 self.list.add("Node2")123 self.list.add("Node3")124 self._assert_list_size(2)125 first = self.list.poll()126 self.assertEquals("Node2", first)127 self._assert_list_size(1)128 first = self.list.poll()129 self.assertEquals("Node3", first)130 self._assert_empty()131 @parameterized.expand(_test_params)132 def test_poll_add_first(self, name, mode):133 self._setUp(mode)134 self.list.add_first("Node0")135 first = self.list.poll()136 self.assertEquals("Node0", first)137 self._assert_empty()138 self.list.add_first("Node1")139 self.list.add_first("Node2")140 self._assert_list_size(2)141 first = self.list.poll()142 self.assertEquals("Node2", first)143 self._assert_list_size(1)144 first = self.list.poll()145 self.assertEquals("Node1", first)146 self._assert_empty()147 @parameterized.expand(_test_params)148 def test_peek_add(self, name, mode):149 self._setUp(mode)150 self.list.add("Node1")151 self.list.add("Node2")152 self._assert_list_size(2)153 first = self.list.peek()154 self.assertEquals("Node1", first)155 self._assert_list_size(2)156 first2 = self.list.peek()157 self.assertEquals(first, first2)158 self._assert_list_size(2)159 @parameterized.expand(_test_params)160 def test_peek_add_first(self, name, mode):161 self._setUp(mode)162 self.list.add_first("Node1")163 self.list.add_first("Node2")164 self._assert_list_size(2)165 first = self.list.peek()166 self.assertEquals("Node2", first)167 self._assert_list_size(2)168 first2 = self.list.peek()169 self.assertEquals(first, first2)170 self._assert_list_size(2)171 @parameterized.expand(_test_params)172 def test_poll_empty_list(self, name, mode):173 self._setUp(mode)174 first = self.list.poll()175 self.assertIsNone(first)176 self.list.add("Node1")177 self.list.poll()178 first = self.list.poll()179 self._assert_empty()180 self.assertIsNone(first)181 self.list.add("Node2")182 self.list.poll()183 first = self.list.poll()184 self._assert_empty()185 self.assertIsNone(first)186 @parameterized.expand(_test_params)187 def test_peek_empty_list(self, name, mode):188 self._setUp(mode)189 first = self.list.peek()190 self.assertIsNone(first)191 @parameterized.expand(_test_params)192 def test_get_empty(self, name, mode):193 self._setUp(mode)194 with self.assertRaises(Exception) as ex:195 node = self.list.get(0)196 @parameterized.expand(_test_params)197 def test_get_negative_number(self, name, mode):198 self._setUp(mode)199 with self.assertRaises(Exception) as ex:200 node = self.list.get(-1)201 @parameterized.expand(_test_params)202 def test_get_index_out_of_bounds(self, name, mode):203 self._setUp(mode)204 self.list.add_first("Node1")205 self.list.add("Node2")206 with self.assertRaises(Exception) as ex:207 self.list.get(2)208 @parameterized.expand(_test_params)209 def test_get(self, name, mode):210 self._setUp(mode)211 self.list.add("Node1")212 self.list.add("Node2")213 node = self.list.get(1)214 self.assertEquals("Node2", node)215 self._assert_list_size(2)216 @parameterized.expand(_test_params)217 def test_index_of_empty(self, name, mode):218 self._setUp(mode)219 idx = self.list.index_of("SomeNode")220 self.assertEquals(-1, idx)221 @parameterized.expand(_test_params)222 def test_index_not_found(self, name, mode):223 self._setUp(mode)224 self.list.add("Node1")225 self.list.add("Node2")226 idx = self.list.index_of("SomeNode")227 self.assertEquals(-1, idx)228 @parameterized.expand(_test_params)229 def test_index_found(self, name, mode):230 self._setUp(mode)231 self.list.add("Node1")232 self.list.add("Node2")233 idx = self.list.index_of("Node2")234 self.assertEquals(1, idx)235 @parameterized.expand(_test_params)236 def test_list_size(self, name, mode):237 self._setUp(mode)238 self.assertEquals(0, self.list.list_size())239 self.list.add("Node1")240 self.assertEquals(1, self.list.list_size())241 self.list.add_first("Node2")242 self.assertEquals(2, self.list.list_size())243 self.list.get(1)244 self.assertEquals(2, self.list.list_size())245 self.list.poll()246 self.assertEquals(1, self.list.list_size())247 @parameterized.expand(_test_params)248 def test_remove_index_empty_list(self, name, mode):249 self._setUp(mode)250 with self.assertRaises(Exception) as ex:251 self.list.remove_index(0)252 @parameterized.expand(_test_params)253 def test_remove_index_negative(self, name, mode):254 self._setUp(mode)255 with self.assertRaises(Exception) as ex:256 self.list.remove_index(-1)257 @parameterized.expand(_test_params)258 def test_remove_index_out_of_bounds(self, name, mode):259 self._setUp(mode)260 self.list.add("Node1")261 self.list.add("Node2")262 with self.assertRaises(Exception) as ex:263 self.list.remove_index(2)264 @parameterized.expand(_test_params)265 def test_remove_index(self, name, mode):266 self._setUp(mode)267 self.list.add("Node1")268 self.list.add("Node2")269 self._assert_list_size(2)270 node = self.list.remove_index(1)271 self._assert_list_size(1)272 self.assertEquals("Node2", node)273 274 self.assertEquals("Node1", self.list.head.data)275 self.assertEquals("Node1", self.list.tail.data)276 self.assertEquals("Node1", self.list.head.next.data)277 self.assertEquals("Node1", self.list.tail.next.data)278 self.list.remove_index(0)279 self._assert_empty()280 self.assertIsNone(self.list.head)281 self.assertIsNone(self.list.tail)282 self.list.add("Node1")283 self.list.add("Node2")284 self.list.add("Node3")285 self._assert_list_size(3)286 self.list.remove_index(1)287 self._assert_list_size(2)288 self.assertEquals("Node1", self.list.head.data)289 self.assertEquals("Node3", self.list.tail.data)290 self.assertEquals("Node3", self.list.head.next.data)291 self.assertEquals("Node1", self.list.tail.next.data)292 293 @parameterized.expand(_test_params)294 def test_remove_index_head(self, name, mode):295 self._setUp(mode)296 self.list.add("Node1")297 self.list.add("Node2")298 self.list.add("Node3")299 self.list.remove_index(0)300 self._assert_list_size(2)301 self.assertEquals("Node2", self.list.head.data)302 self.assertEquals("Node2", self.list.tail.next.data)303 self.assertEquals("Node3", self.list.head.next.data)304 @parameterized.expand(_test_params)305 def test_remove_index_tail(self, name, mode):306 self._setUp(mode)307 self.list.add("Node1")308 self.list.add("Node2")309 self.list.add("Node3")310 self._assert_list_size(3)311 312 self.list.remove_index(2)313 self._assert_list_size(2)314 self.assertEquals("Node1", self.list.head.data)315 self.assertEquals("Node2", self.list.tail.data)316 self.assertEquals("Node1", self.list.tail.next.data)317 self.list.remove_index(0)318 self.list.remove_index(0)319 self._assert_empty()320 self.assertIsNone(self.list.head)321 self.assertIsNone(self.list.tail)322 @parameterized.expand(_test_params)323 def test_empty_list(self, name, mode):324 self._setUp(mode)325 self.list.add("Node1")326 self._assert_list_size(1)327 self.list.clear()328 self._assert_empty()329 self.assertIsNone(self.list.head)330 self.assertIsNone(self.list.tail)331 @parameterized.expand(_test_params)332 def test_remove_empty(self, name, mode):333 self._setUp(mode)334 node = self.list.remove("Node1")335 self.assertIsNone(node)336 self._assert_empty()337 @parameterized.expand(_test_params)338 def test_remove(self, name, mode):339 self._setUp(mode)340 self.list.add("Node1")341 self._assert_list_size(1)342 node = self.list.remove("Node1")343 self._assert_empty()344 self.assertEquals("Node1", node)345 self.list.add("Node1")346 self.list.add("Node2")347 self.list.add("Node3")348 self._assert_list_size(3)349 node = self.list.remove("Node2")350 self._assert_list_size(2)351 self.assertEquals("Node2", node)352 @parameterized.expand(_test_params)353 def test_slice_empty(self, name, mode):354 self._setUp(mode)355 slice = self.list.slice(10)356 self.assertIsNone(slice)357 @parameterized.expand(_test_params)358 def test_slice_size_bigger_length(self, name, mode):359 self._setUp(mode)360 self.list.add("Node1")361 self.list.add("Node2")362 self.list.add("Node3")363 self._assert_list_size(3)364 slice = self.list.slice(10)365 self.assertEquals(3, len(slice))366 self.assertTrue("Node1" in slice)367 self.assertTrue("Node2" in slice)368 self.assertTrue("Node3" in slice)369 @parameterized.expand(_test_params)370 def test_slice_rotation(self, name, mode):371 self._setUp(mode)372 self.list.add("Node1")373 self.list.add("Node2")374 self.list.add("Node3")375 self.list.add("Node4")376 self.list.add("Node5")377 slice = self.list.slice(3)378 self.assertEquals(3, len(slice))379 self.assertTrue("Node1" in slice)380 self.assertTrue("Node2" in slice)381 self.assertTrue("Node3" in slice)382 slice = self.list.slice(3)383 self.assertEquals(3, len(slice))384 self.assertTrue("Node4" in slice)385 self.assertTrue("Node5" in slice)386 self.assertTrue("Node1" in slice)387 @parameterized.expand(_test_params)388 def test_slice_rotation_with_remove(self, name, mode):389 self._setUp(mode)390 self.list.add("Node1")391 self.list.add("Node2")392 self.list.add("Node3")393 self.list.add("Node4")394 self.list.add("Node5")395 slice = self.list.slice(3)396 self.assertEquals(3, len(slice))397 self.assertTrue("Node1" in slice)398 self.assertTrue("Node2" in slice)399 self.assertTrue("Node3" in slice)400 self.list.remove("Node4")401 402 slice = self.list.slice(3)403 self.assertEquals(3, len(slice))404 print(slice)405 self.assertTrue("Node5" in slice)406 self.assertTrue("Node1" in slice)407 self.assertTrue("Node2" in slice)408 @parameterized.expand(_test_params)409 def test_slice_rotation_with_add(self, name, mode):410 self._setUp(mode)411 self.list.add("Node1")412 self.list.add("Node2")413 self.list.add("Node3")414 slice = self.list.slice(10)415 self.assertEquals(3, len(slice))416 self.assertTrue("Node1" in slice)417 self.assertTrue("Node2" in slice)418 self.assertTrue("Node3" in slice)419 self.list.add("Node4")420 slice = self.list.slice(10)421 self.assertEqual(4, len(slice))422 self.assertTrue("Node4" in slice)423 @parameterized.expand(_test_params)424 def test_contains_empty(self, name, mode):425 self._setUp(mode)426 self.assertFalse(self.list.contains("Node1"))427 428 @parameterized.expand(_test_params)429 def test_contains(self, name, mode):430 self._setUp(mode)431 self.list.add("Node1")432 self.assertTrue(self.list.contains("Node1"))433 self.assertFalse(self.list.contains("SomeOtherNode"))434 435 def _assert_empty(self):436 self._assert_list_size(0)437 438 def _assert_list_size(self, expected):...
test_toxini.py
Source:test_toxini.py
...49 collector = self._collect(tmpdir)50 assert {"aaa", "zzz"} == collector.requires.test51 assert [["tick"], ["tock"]] == collector.ext.tox.commands52 assert collector.ext.tox.env.ONE == "1"53 def _assert_empty(self, collector):54 assert "tox" not in collector.ext55 assert not collector.requires56 def test_collect_alt(self, tmpdir):57 tmpdir.join("tox.ini").write(TOXINI_ALT)58 collector = self._collect(tmpdir)59 self._assert_empty(collector)60 def test_collect_noconfig(self, tmpdir):61 tmpdir.join("tox.ini").write(TOXINI_NOCONFIG)62 collector = self._collect(tmpdir)63 self._assert_empty(collector)64 def test_collect_bad(self, tmpdir):65 tmpdir.join("tox.ini").write(TOXINI_BAD)66 collector = self._collect(tmpdir)67 self._assert_empty(collector)68 def test_collect_bad_alt(self, tmpdir):69 tmpdir.join("tox.ini").write(TOXINI_BAD_ALT)70 collector = self._collect(tmpdir)71 self._assert_empty(collector)72 def test_collect_conf_error(self, monkeypatch, tmpdir):73 monkeypatch.setattr(toxini, "parseconfig", self._raiser(ConfigError))74 tmpdir.join("tox.ini").write(TOXINI)75 collector = self._collect(tmpdir)...
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!!