How to use set_type method in autotest

Best Python code snippet using autotest_python

test_set_dropin.py

Source:test_set_dropin.py Github

copy

Full Screen

...15 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]16)17class TestSetDropIn(UnitTestMock): 18 def test_init_from_iter(self, set_type):19 s=set_type([1,2,3,1])20 self.assertEqual(len(s), 3)21 self.assertTrue(1 in s)22 self.assertTrue(2 in s)23 self.assertTrue(3 in s)24 def test_clear(self, set_type):25 s=set_type([1,2,3,1])26 s.clear()27 self.assertEqual(len(s), 0)28 s.add(5)29 s.update([3,4,5,6])30 self.assertEqual(s, set_type([3,4,5,6]))31 s.clear()32 self.assertEqual(len(s), 0)33 def test_str(self, set_type):34 s=set_type([1,2,3,1])35 ss = str(s)36 self.assertTrue("1" in ss)37 self.assertTrue("2" in ss)38 self.assertTrue("3" in ss)39 self.assertTrue(ss.startswith("{"))40 self.assertTrue(ss.endswith("}"))41 def test_remove_yes(self, set_type):42 s=set_type([1,2])43 s.remove(1)44 self.assertEqual(s,set_type([2]))45 s.remove(2)46 self.assertEqual(s,set_type([]))47 def test_remove_no(self, set_type):48 s=set_type([1,2])49 with pytest.raises(KeyError) as context:50 s.remove(3)51 self.assertEqual(3, context.value.args[0])52 def test_pop_one(self, set_type):53 s=set_type([1])54 el=s.pop()55 self.assertEqual(s,set_type([]))56 self.assertEqual(el,1)57 def test_pop_all(self, set_type):58 s=set_type([1,2,3])59 new_s={s.pop(), s.pop(), s.pop()}60 self.assertEqual(s,set_type([]))61 self.assertEqual(new_s,{1,2,3})62 def test_pop_empty(self, set_type):63 s=set_type([])64 with pytest.raises(KeyError) as context:65 s.pop()66 self.assertEqual("pop from empty set", context.value.args[0])67def test_pyobject_same_object_pop():68 a=float("3333.2")69 s=PyObjectSet([a])70 b=s.pop()71 assert a is b72@pytest.mark.parametrize(73 "set_type",74 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]75)76class TestIsDisjoint(UnitTestMock): 77 def test_aredisjoint_with_none(self, set_type):78 s=set_type([1,2,3,1])79 fun=pick_fun("aredisjoint", set_type)80 with pytest.raises(TypeError) as context:81 fun(None,s)82 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])83 with pytest.raises(TypeError) as context:84 fun(s,None)85 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])86 with pytest.raises(TypeError) as context:87 fun(None,None)88 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])89 def test_aredisjoint_with_empty(self, set_type):90 empty1=set_type()91 empty2=set_type()92 non_empty=set_type(range(3))93 aredisjoint=pick_fun("aredisjoint", set_type)94 self.assertEqual(aredisjoint(empty1, non_empty), True)95 self.assertEqual(aredisjoint(non_empty, empty2), True)96 self.assertEqual(aredisjoint(empty1, empty2), True)97 def test_aredisjoint_yes(self, set_type):98 a=set_type([1,2,3,1])99 b=set_type([4,55])100 fun=pick_fun("aredisjoint", set_type)101 self.assertEqual(fun(a,b), True)102 self.assertEqual(fun(b,a), True)103 def test_aredisjoint_no(self, set_type):104 a=set_type([1,2,3,333,1])105 b=set_type([4,55,4,5,6,7,333])106 fun=pick_fun("aredisjoint", set_type)107 self.assertEqual(fun(a,b), False)108 self.assertEqual(fun(b,a), False)109 def test_isdisjoint_yes_set(self, set_type):110 a=set_type([1,2,3,1])111 b=set_type([4,55])112 self.assertEqual(a.isdisjoint(b), True)113 self.assertEqual(b.isdisjoint(a), True)114 def test_isdisjoint_no_set(self, set_type):115 a=set_type([1,2,3,333,1])116 b=set_type([4,55,4,5,6,7,333])117 self.assertEqual(a.isdisjoint(b), False)118 self.assertEqual(b.isdisjoint(a), False)119 def test_isdisjoint_yes_iter(self, set_type):120 a=set_type([1,2,3,1])121 b=[4,55]122 self.assertEqual(a.isdisjoint(b), True)123 def test_isdisjoint_no_iter(self, set_type):124 a=set_type([1,2,3,333,1])125 b=[4,55,4,5,6,7,333]126 self.assertEqual(a.isdisjoint(b), False)127@pytest.mark.parametrize(128 "set_type",129 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]130)131class TestIsSubsetIsSuperset(UnitTestMock): 132 def test_with_none(self, set_type):133 s=set_type([1,2,3,1])134 fun=pick_fun("issubset", set_type)135 with pytest.raises(TypeError) as context:136 fun(None,s)137 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])138 with pytest.raises(TypeError) as context:139 fun(s,None)140 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])141 with pytest.raises(TypeError) as context:142 fun(None,None)143 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])144 def test_with_empty(self, set_type):145 a=set_type([1,2,3,1])146 b=set_type([])147 fun=pick_fun("issubset", set_type)148 self.assertEqual(fun(a,a), True)149 self.assertEqual(fun(a,b), True)150 self.assertEqual(fun(b,a), False)151 self.assertEqual(fun(b,b), True)152 def test_yes(self, set_type):153 a=set_type([1,2,3,1])154 b=set_type([1,3])155 fun=pick_fun("issubset", set_type)156 self.assertEqual(fun(a,b), True)157 self.assertEqual(fun(b,a), False)158 def test_no(self, set_type):159 a=set_type([1,2,3,1])160 b=set_type([4])161 fun=pick_fun("issubset", set_type)162 self.assertEqual(fun(a,b), False)163 self.assertEqual(fun(b,a), False)164 def test_issuperset_yes(self, set_type):165 a=set_type([1,2,3,1])166 b=set_type([1,3])167 self.assertEqual(a.issuperset(b), True)168 self.assertEqual(b.issuperset(a), False)169 def test_issuperset_no(self, set_type):170 a=set_type([1,2,3,1])171 b=set_type([4])172 self.assertEqual(a.issuperset(b), False)173 self.assertEqual(b.issuperset(a), False)174 def test_issuperset_yes_iter(self, set_type):175 a=set_type([1,2,3,1])176 b=[1,3]177 self.assertEqual(a.issuperset(b), True)178 def test_issuperset_no_iter(self, set_type):179 a=set_type([1,2,3,1])180 b=[4]181 self.assertEqual(a.issuperset(b), False)182 def test_issubset_yes_iter(self, set_type):183 a=set_type([1,2])184 b=[1,3,2]185 self.assertEqual(a.issubset(b), True)186 def test_issubset_no_iter(self, set_type):187 a=set_type([1,2])188 b=[1,1,3]189 self.assertEqual(a.issubset(b), False)190 def test_issubset_yes(self, set_type):191 a=set_type([1,2])192 b=set_type([1,3,2])193 self.assertEqual(a.issubset(b), True)194 self.assertEqual(b.issubset(a), False)195 def test_issubset_no(self, set_type):196 a=set_type([1,2])197 b=set_type([1,1,3])198 self.assertEqual(a.issubset(b), False)199 self.assertEqual(b.issubset(a), False)200 def test_compare_self(self, set_type):201 a=set_type([1,2])202 self.assertEqual(a<=a, True)203 self.assertEqual(a>=a, True)204 self.assertEqual(a<a, False)205 self.assertEqual(a>a, False)206 def test_compare_no_relation(self, set_type):207 a=set_type([1,2])208 b=set_type([1,3])209 self.assertEqual(a<=b, False)210 self.assertEqual(a>=b, False)211 self.assertEqual(a<b, False)212 self.assertEqual(a>b, False)213 def test_compare_real_subset(self, set_type):214 a=set_type([1,2,3])215 b=set_type([1,3])216 self.assertEqual(a<=b, False)217 self.assertEqual(a>=b, True)218 self.assertEqual(a<b, False)219 self.assertEqual(a>b, True)220 def test_compare_same(self, set_type):221 a=set_type([1,3])222 b=set_type([1,3])223 self.assertEqual(a<=b, True)224 self.assertEqual(a>=b, True)225 self.assertEqual(a<b, False)226 self.assertEqual(a>b, False)227 def test_compare_equal_yes(self, set_type):228 a=set_type([2,5,7,8,1,3])229 b=set_type([1,3,7,7,7,7,7,2,5,8,8,8,8,8,8])230 self.assertEqual(a==b, True)231 self.assertEqual(a==b, True)232 def test_compare_equal_yes(self, set_type):233 a=set_type([2,5,7,8,1,3])234 b=set_type([3,7,7,7,7,7,2,5,8,8,8,8,8,8])235 self.assertEqual(a==b, False)236 self.assertEqual(a==b, False)237@pytest.mark.parametrize(238 "set_type",239 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]240)241class TestCopy(UnitTestMock): 242 def test_with_none(self, set_type):243 s=set_type([1,2,3,1])244 copy=pick_fun("copy", set_type)245 self.assertTrue(copy(None) is None)246 def test_with_empty(self, set_type):247 a=set_type([])248 copy=pick_fun("copy", set_type)249 self.assertEqual(len(copy(a)), 0)250 def test_small(self, set_type):251 a=set_type([1,2,3,1])252 copy=pick_fun("copy", set_type)253 self.assertEqual(copy(a)==a, True)254 def test_large(self, set_type):255 a=set_type(range(33,10000,3))256 copy=pick_fun("copy", set_type)257 self.assertEqual(copy(a)==a, True)258 def test_large_method(self, set_type):259 a=set_type(range(33,10000,3))260 self.assertEqual(a.copy()==a, True)261@pytest.mark.parametrize(262 "set_type",263 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]264)265class TestUpdate(UnitTestMock): 266 def test_with_none(self, set_type):267 s=set_type([1,2,3,1])268 update=pick_fun("update", set_type) 269 with pytest.raises(TypeError) as context:270 update(None,s)271 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])272 with pytest.raises(TypeError) as context:273 update(s,None)274 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])275 with pytest.raises(TypeError) as context:276 update(None,None)277 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])278 def test_some_common(self, set_type):279 a=set_type([1,2,3,4])280 b=set_type([2,1,2,5])281 c=b.copy()282 update=pick_fun("update", set_type) 283 update(a,b)284 self.assertEqual(a, set_type([1,2,3,4,5]))285 self.assertEqual(b, c)286 def test_with_itself(self, set_type):287 a=set_type([1,2,3,1])288 b=a.copy()289 update=pick_fun("update", set_type) 290 update(a,a)291 self.assertEqual(a, b)292 def test_with_disjunct(self, set_type):293 a=set_type(range(50))294 b=set_type(range(50,100))295 update=pick_fun("update", set_type) 296 update(a,b)297 self.assertEqual(a, set_type(range(100)))298 def test_method_with_set(self, set_type):299 a=set_type(range(50))300 b=set_type(range(100))301 a.update(b)302 self.assertEqual(a, set_type(range(100)))303 def test_method_with_set(self, set_type):304 a=set_type(range(50))305 b=set_type(range(100))306 a.update(b)307 self.assertEqual(a, set_type(range(100)))308 def test_method_with_iterator(self, set_type):309 a=set_type(range(50))310 a.update(range(60))311 self.assertEqual(a, set_type(range(60)))312 def test_ior(self, set_type):313 a=set_type(range(50))314 a|=set_type(range(60))315 self.assertEqual(a, set_type(range(60)))316 def test_union(self, set_type):317 a=set_type(range(30))318 a_copy = a.copy()319 b=a.union(range(30,40), set_type(range(40,50)), range(50,60))320 self.assertEqual(b, set_type(range(60)))321 self.assertEqual(a, a_copy)322 def test_union_empty(self, set_type):323 a=set_type(range(30))324 a.union()325 self.assertEqual(a, set_type(range(30)))326 def test_or(self, set_type):327 a=set_type(range(30))328 b=set_type(range(30,40))329 c=set_type(range(40,50))330 d=a|b|c331 self.assertEqual(d, set_type(range(50)))332 self.assertEqual(a, set_type(range(30)))333 self.assertEqual(b, set_type(range(30,40)))334 self.assertEqual(c, set_type(range(40,50)))335@pytest.mark.parametrize(336 "set_type",337 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]338)339class TestSwap(UnitTestMock): 340 def test_with_none(self, set_type):341 s=set_type([1,2,3,1])342 swap=pick_fun("swap", set_type) 343 with pytest.raises(TypeError) as context:344 swap(None,s)345 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])346 with pytest.raises(TypeError) as context:347 swap(s,None)348 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])349 with pytest.raises(TypeError) as context:350 swap(None,None)351 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])352 def test_some_common(self, set_type):353 a=set_type([1,2,3,4])354 b=set_type([5,2,4])355 a_copy=a.copy()356 b_copy=b.copy()357 swap=pick_fun("swap", set_type) 358 swap(a,b)359 self.assertEqual(a, b_copy)360 self.assertEqual(b, a_copy)361 swap(a,b)362 self.assertEqual(a, a_copy)363 self.assertEqual(b, b_copy)364@pytest.mark.parametrize(365 "set_type",366 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]367)368class TestIntersect(UnitTestMock): 369 def test_with_none(self, set_type):370 s=set_type([1,2,3,1])371 intersect=pick_fun("intersect", set_type) 372 with pytest.raises(TypeError) as context:373 intersect(None,s)374 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])375 with pytest.raises(TypeError) as context:376 intersect(s,None)377 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])378 with pytest.raises(TypeError) as context:379 intersect(None,None)380 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])381 def test_small(self, set_type):382 a=set_type([1,2,3,4])383 b=set_type([5,2,4])384 a_copy=a.copy()385 b_copy=b.copy()386 intersect=pick_fun("intersect", set_type) 387 c=intersect(a,b)388 self.assertEqual(a, a_copy)389 self.assertEqual(b, b_copy)390 self.assertEqual(c, set_type([2,4]))391 c=intersect(b,a)392 self.assertEqual(a, a_copy)393 self.assertEqual(b, b_copy)394 self.assertEqual(c, set_type([2,4]))395 def test_disjunct(self, set_type):396 a=set_type([1,3,5,7,9])397 b=set_type([2,2,4,6,8,10])398 a_copy=a.copy()399 b_copy=b.copy()400 intersect=pick_fun("intersect", set_type) 401 c=intersect(a,b)402 self.assertEqual(a, a_copy)403 self.assertEqual(b, b_copy)404 self.assertEqual(c, set_type())405 c=intersect(b,a)406 self.assertEqual(a, a_copy)407 self.assertEqual(b, b_copy)408 self.assertEqual(c, set_type([]))409 def test_empty(self, set_type):410 a=set_type([])411 b=set_type([])412 c=set_type([2,2,4,6,8,10])413 intersect=pick_fun("intersect", set_type) 414 d=intersect(a,b)415 self.assertEqual(len(d), 0)416 d=intersect(c,b)417 self.assertEqual(len(d), 0)418 d=intersect(a,c)419 self.assertEqual(len(d), 0)420 def test_intersection_update(self, set_type):421 a=set_type([1,2,3,4,5,6,7,8])422 b=set_type([2,4,6,8,10,12])423 b_copy = b.copy()424 a.intersection_update(b)425 self.assertEqual(a, set_type([2,4,6,8]))426 self.assertEqual(b, b_copy)427 def test_intersection_update_iter(self, set_type):428 a=set_type([1,2,3,4,5,6,7,8])429 a.intersection_update([2,4,6,8,10,12])430 self.assertEqual(a, set_type([2,4,6,8]))431 def test_empty_update(self, set_type):432 a=set_type([1,2,3,4,5,6,7,8])433 b=set_type([])434 a.intersection_update(b)435 self.assertEqual(len(a), 0)436 def test_empty_update_iter(self, set_type):437 a=set_type([1,2,3,4,5,6,7,8])438 a.intersection_update([])439 self.assertEqual(a, set_type())440 def test_iadd(self, set_type):441 a=set_type([1,2,3,4,5,6,7,8])442 b=set_type([1,104,3])443 a&=b444 self.assertEqual(a, set_type([1,3]))445 def test_add(self, set_type):446 a=set_type([1,2,3,4,5,6,7,8])447 b=set_type([1,104,3])448 a_copy=a.copy()449 b_copy=b.copy()450 c=a&b451 self.assertEqual(c, set_type([1,3]))452 self.assertEqual(a, a_copy)453 self.assertEqual(b, b_copy)454 def test_intersection(self, set_type):455 a=set_type([1,2,3,4,5,6,7,8])456 a_copy=a.copy()457 c=a.intersection([1,2,3,4,5,6], set_type([1,2,3,4,5]), [1,2,3])458 self.assertEqual(c, set_type([1,2,3]))459 self.assertEqual(a, a_copy)460@pytest.mark.parametrize(461 "set_type",462 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]463)464class TestDifference(UnitTestMock): 465 def test_with_none(self, set_type):466 s=set_type([1,2,3,1])467 difference=pick_fun("difference", set_type) 468 with pytest.raises(TypeError) as context:469 difference(None,s)470 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])471 with pytest.raises(TypeError) as context:472 difference(s,None)473 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])474 with pytest.raises(TypeError) as context:475 difference(None,None)476 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])477 def test_small(self, set_type):478 a=set_type([1,2,3,4])479 b=set_type([5,2,4])480 a_copy=a.copy()481 b_copy=b.copy()482 difference=pick_fun("difference", set_type) 483 c=difference(a,b)484 self.assertEqual(a, a_copy)485 self.assertEqual(b, b_copy)486 self.assertEqual(c, set_type([1,3]))487 c=difference(b,a)488 self.assertEqual(a, a_copy)489 self.assertEqual(b, b_copy)490 self.assertEqual(c, set_type([5]))491 def test_disjunct(self, set_type):492 a=set_type([1,3,5,7,9])493 b=set_type([2,2,4,6,8,10])494 a_copy=a.copy()495 b_copy=b.copy()496 difference=pick_fun("difference", set_type) 497 c=difference(a,b)498 self.assertEqual(a, a_copy)499 self.assertEqual(b, b_copy)500 self.assertEqual(c, a)501 c=difference(b,a)502 self.assertEqual(a, a_copy)503 self.assertEqual(b, b_copy)504 self.assertEqual(c, b)505 def test_empty(self, set_type):506 a=set_type([])507 b=set_type([])508 c=set_type([2,2,4,6,8,10])509 difference=pick_fun("difference", set_type) 510 d=difference(a,b)511 self.assertEqual(len(d), 0)512 d=difference(c,b)513 self.assertEqual(c, d)514 d=difference(a,c)515 self.assertEqual(len(d), 0)516 def test_method_update(self, set_type):517 a=set_type([1,2,3,4])518 b=set_type([5,2,4])519 b_copy=b.copy()520 a.difference_update(b)521 self.assertEqual(b, b_copy)522 self.assertEqual(a, set_type([1,3]))523 def test_method_update2(self, set_type):524 a=set_type([1,2,3,4])525 b=set_type([5,2,4])526 a_copy=a.copy()527 b.difference_update(a)528 self.assertEqual(a, a_copy)529 self.assertEqual(b, set_type([5]))530 def test_method_update_from_iter(self, set_type):531 a=set_type([1,2,3,4])532 a.difference_update([5,2,4])533 self.assertEqual(a, set_type([1,3]))534 def test_method_update_from_iter2(self, set_type):535 a=set_type(range(1000))536 a.difference_update(range(0,1000,2))537 self.assertEqual(a, set_type(range(1,1000,2)))538 def test_method_update_from_iter3(self, set_type):539 a=set_type([1,2])540 a.difference_update([1]*10000)541 self.assertEqual(a, set_type([2]))542 def test_sub(self, set_type):543 a=set_type([0,222,3,444,5])544 b=set_type([222,3,4])545 a_copy=a.copy()546 b_copy=b.copy()547 c=a-b548 self.assertEqual(a, a_copy)549 self.assertEqual(b, b_copy)550 self.assertEqual(c, set_type([0,444,5]))551 c=b-a552 self.assertEqual(a, a_copy)553 self.assertEqual(b, b_copy)554 self.assertEqual(c, set_type([4]))555 def test_sub2(self, set_type):556 a=set_type([1,2,3,4])557 a_copy=a.copy()558 b=a-a-a-a559 self.assertEqual(a, a_copy)560 self.assertEqual(b, set_type())561 def test_isub(self, set_type):562 a=set_type([0,222,3,444,5])563 b=set_type([222,3,4])564 b_copy=b.copy()565 a-=b566 self.assertEqual(b, b_copy)567 self.assertEqual(a, set_type([0,444,5]))568 def test_isub2(self, set_type):569 a=set_type([1,2,3,4])570 a-=a571 self.assertEqual(a, set_type())572 def test_difference_method(self, set_type):573 a=set_type(range(10000))574 a_copy=a.copy()575 b=a.difference(range(5000), set_type(range(5000,10000,2)), range(1,9999,2))576 self.assertEqual(b, set_type([9999]))577 self.assertEqual(a, a_copy)578@pytest.mark.parametrize(579 "set_type",580 [Int64Set, Int32Set, Float64Set, Float32Set, PyObjectSet]581)582class TestSymmetricDifference(UnitTestMock): 583 def test_with_none(self, set_type):584 s=set_type([1,2,3,1])585 symmetric_difference=pick_fun("symmetric_difference", set_type) 586 with pytest.raises(TypeError) as context:587 symmetric_difference(None,s)588 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])589 with pytest.raises(TypeError) as context:590 symmetric_difference(s,None)591 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])592 with pytest.raises(TypeError) as context:593 symmetric_difference(None,None)594 self.assertTrue("'NoneType' object is not iterable" in context.value.args[0])595 def test_small(self, set_type):596 a=set_type([1,2,3,4])597 b=set_type([5,2,4])598 a_copy=a.copy()599 b_copy=b.copy()600 symmetric_difference=pick_fun("symmetric_difference", set_type) 601 c=symmetric_difference(a,b)602 self.assertEqual(a, a_copy)603 self.assertEqual(b, b_copy)604 self.assertEqual(c, set_type([1,3,5]))605 c=symmetric_difference(b,a)606 self.assertEqual(a, a_copy)607 self.assertEqual(b, b_copy)608 self.assertEqual(c, set_type([1,3,5]))609 def test_disjunct(self, set_type):610 a=set_type([1,3,5,7,9])611 b=set_type([2,2,4,6,8,10])612 a_copy=a.copy()613 b_copy=b.copy()614 symmetric_difference=pick_fun("symmetric_difference", set_type) 615 c=symmetric_difference(a,b)616 self.assertEqual(a, a_copy)617 self.assertEqual(b, b_copy)618 self.assertEqual(c, a|b)619 c=symmetric_difference(b,a)620 self.assertEqual(a, a_copy)621 self.assertEqual(b, b_copy)622 self.assertEqual(c, a|b)623 def test_empty(self, set_type):624 a=set_type([])625 b=set_type([])626 c=set_type([2,2,4,6,8,10])627 symmetric_difference=pick_fun("symmetric_difference", set_type) 628 d=symmetric_difference(a,b)629 self.assertEqual(len(d), 0)630 d=symmetric_difference(c,b)631 self.assertEqual(c, d)632 d=symmetric_difference(a,c)633 self.assertEqual(c, d)634 def test_method_update(self, set_type):635 a=set_type([1,2,3,4])636 b=set_type([5,2,4])637 b_copy=b.copy()638 a.symmetric_difference_update(b)639 self.assertEqual(b, b_copy)640 self.assertEqual(a, set_type([1,3,5]))641 def test_method_update2(self, set_type):642 a=set_type([1,2,3,4])643 b=set_type([5,2,4])644 a_copy=a.copy()645 b.symmetric_difference_update(a)646 self.assertEqual(a, a_copy)647 self.assertEqual(b, set_type([1,3,5]))648 def test_method_update_from_iter(self, set_type):649 a=set_type([1,2,3,4])650 a.symmetric_difference_update([5,2,4])651 self.assertEqual(a, set_type([1,3, 5]))652 def test_method_update_from_iter2(self, set_type):653 a=set_type(range(1000))654 a.symmetric_difference_update(range(0,1000,2))655 self.assertEqual(a, set_type(range(1,1000,2)))656 def test_method_update_from_iter3(self, set_type):657 a=set_type([1,2])658 a.symmetric_difference_update([1]*10000)659 self.assertEqual(a, set_type([2]))660 def test_method_update_from_iter4(self, set_type):661 a=set_type([1,2])662 a.symmetric_difference_update(a)663 self.assertEqual(len(a), 0)664 def test_xor(self, set_type):665 a=set_type([0,222,3,444,5])666 b=set_type([222,3,4])667 a_copy=a.copy()668 b_copy=b.copy()669 c=a^b670 self.assertEqual(a, a_copy)671 self.assertEqual(b, b_copy)672 self.assertEqual(c, set_type([0,444,5,4]))673 c=b^a674 self.assertEqual(a, a_copy)675 self.assertEqual(b, b_copy)676 self.assertEqual(c, set_type([0,444,5,4]))677 def test_xor2(self, set_type):678 a=set_type([1,2,3,4])679 a_copy=a.copy()680 b=a^a^a^a681 self.assertEqual(a, a_copy)682 self.assertEqual(len(b), 0)683 def test_xor3(self, set_type):684 a=set_type([1,2,3,4])685 a_copy=a.copy()686 b=a^a^a^a^a687 self.assertEqual(a, a_copy)688 self.assertEqual(b, a)689 def test_ixor(self, set_type):690 a=set_type([0,222,3,444,5])691 b=set_type([222,3,4])692 b_copy=b.copy()693 a^=b694 self.assertEqual(b, b_copy)695 self.assertEqual(a, set_type([0,444,5,4]))696 def test_ixor2(self, set_type):697 a=set_type([1,2,3,4])698 a^=a699 self.assertEqual(a, set_type())700 def test_symmetric_method(self, set_type):701 a=set_type(range(10))702 a_copy=a.copy()703 b=a.symmetric_difference(range(5,15), set_type(range(5,10)), range(1,16))704 self.assertEqual(b, set_type([0,15]))...

Full Screen

Full Screen

test_templatetags.py

Source:test_templatetags.py Github

copy

Full Screen

...79 c = self._get_context_for_rendering(cat, cats[0].slug, request)80 self.assertNotIn(self.t_tree_item.render(c), out)81 def test_get_empty_tree_with_nonexisting_int_pk(self):82 """ The cat tree returns no result display """83 set_type = create_set_type()84 request = self._reverse_listview({'set_type': set_type.slug, 'cat_id': 1})85 request.session = self.client.session86 out = Template(87 "{% load filersets_menutags %}"88 "{% fs_category_tree 99 %}"89 ).render(RequestContext(request, {'current_app': 'filersets'}))90 self.assertInHTML('<p>No categories available</p>', out)91 def test_get_tree_with_existing_variable_param(self):92 """ The cat tree is rendered starting with pk given as variable """93 create_controlled_categories()94 cats = Category.objects.all().order_by('pk')95 request = self._reverse_listview({'set_type': cats[0].slug, 'cat_id': 1})96 request.session = self.client.session97 pk_as_val = Category.objects.first().pk98 out = Template(99 "{% with pk_var=" + str(pk_as_val) + " %}"100 "{% load filersets_menutags %}"101 "{% fs_category_tree pk_var %}"102 "{% endwith %}"103 ).render(RequestContext(request, {'current_app': 'filersets'}))104 root_cat = Category.objects.get(pk=pk_as_val)105 lvl_compensate = root_cat.get_level_compensation()106 for cat in root_cat.get_descendants():107 c = self._get_context_for_rendering(cat, cats[0].slug, request, lvl_compensate)108 self.assertInHTML(self.t_tree_item.render(c), out)109 def test_get_empty_tree_with_nonexisting_variable_param(self):110 """ The cat tree return no result display """111 set_type = create_set_type()112 request = self._reverse_listview({'set_type': set_type.slug, 'cat_id': 1})113 request.session = self.client.session114 out = Template(115 "{% with pk_var=99 %}"116 "{% load filersets_menutags %}"117 "{% fs_category_tree pk_var %}"118 "{% endwith %}"119 ).render(RequestContext(request, {'current_app': 'filersets'}))120 self.assertInHTML('<p>No categories available</p>', out)121 def test_raises_exception_with_invalid_variable(self):122 """ The cat tree raises VariableDoesNotExist with invalid param """123 set_type = create_set_type()124 request = self._reverse_listview({'set_type': set_type.slug, 'cat_id': 1})125 request.session = self.client.session126 with self.assertRaises(ValueError):127 Template(128 "{% with pk_var='foobar' %}"129 "{% load filersets_menutags %}"130 "{% fs_category_tree pk_var %}"131 "{% endwith %}"132 ).render(RequestContext(request, {'current_app': 'filersets'}))133 def test_active_item_from_id_view(self):134 """ The active item is highlighted in the menu tree """135 set_type = create_set_type()136 request = self._reverse_listview({'set_type': set_type.slug, 'cat_id': set_type.get_root_category().pk})137 request.session = self.client.session138 out = Template(139 "{% load filersets_menutags %}"140 "{% fs_category_tree %}"141 ).render(RequestContext(request, {'current_app': 'filersets'}))142 out = out.replace("\n", "")143 m = re.search(r'(?i)<a([^>]+class="(.+?)")>(.+?)</a>', out, re.M | re.U)144 self.assertTrue('active' in m.group(2))145 def test_active_item_from_slug_view(self):146 """ The active item is highlighted in the menu tree """147 set_type = create_set_type()148 request = self._reverse_listview({'set_type': set_type.slug, 'cat_slug': set_type.get_root_category().slug_composed})149 request.session = self.client.session150 out = Template(151 "{% load filersets_menutags %}"152 "{% fs_category_tree %}"153 ).render(RequestContext(request, {'current_app': 'filersets'}))154 out = out.replace("\n", "")155 m = re.search(r'(?i)<a([^>]+class="(.+?)")>(.+?)</a>', out, re.M | re.U)156 self.assertTrue('active' in m.group(2))157 def test_only_one_active_cat_when_switching_categories(self):158 """ Only the current item is active when switching categories """159 set_type = create_set_type()160 cat1 = set_type.get_root_category().add_child(name='Category 01', is_active=True, parent=None)161 cat2 = set_type.get_root_category().add_child(name='Category 02', is_active=True, parent=None)162 # Write session entries as if we came from cat1 category list page.163 request = self._reverse_listview({'set_type': set_type.slug, 'cat_id': cat1.pk})164 cat1_fullpath = request.get_full_path()165 # Hit cat2 category list page to check the active class on the tree.166 request = self._reverse_listview({'set_type': set_type.slug, 'cat_id': cat2.pk})167 request.session = self.client.session168 request.session['has_back_base'] = True169 request.session['back_base_url'] = cat1_fullpath170 request.session['fs_referrer'] = '{}:list_view'.format(set_type.slug)171 request.session.save()172 out = Template(173 "{% load filersets_menutags %}"...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1# Copyright (c) OpenMMLab. All rights reserved.2import copy3import warnings4import mmcv5import numpy as np6import torch7from mmdet.datasets import replace_ImageToTensor8from mmocr.utils import is_2dlist, is_type_list9def update_pipeline(cfg, idx=None):10 if idx is None:11 if cfg.pipeline is not None:12 cfg.pipeline = replace_ImageToTensor(cfg.pipeline)13 else:14 cfg.pipeline[idx] = replace_ImageToTensor(cfg.pipeline[idx])15def replace_image_to_tensor(cfg, set_types=None):16 """Replace 'ImageToTensor' to 'DefaultFormatBundle'."""17 assert set_types is None or isinstance(set_types, list)18 if set_types is None:19 set_types = ['val', 'test']20 cfg = copy.deepcopy(cfg)21 for set_type in set_types:22 assert set_type in ['val', 'test']23 uniform_pipeline = cfg.data[set_type].get('pipeline', None)24 if is_type_list(uniform_pipeline, dict):25 update_pipeline(cfg.data[set_type])26 elif is_2dlist(uniform_pipeline):27 for idx, _ in enumerate(uniform_pipeline):28 update_pipeline(cfg.data[set_type], idx)29 for dataset in cfg.data[set_type].get('datasets', []):30 if isinstance(dataset, list):31 for each_dataset in dataset:32 update_pipeline(each_dataset)33 else:34 update_pipeline(dataset)35 return cfg36def update_pipeline_recog(cfg, idx=None):37 warning_msg = 'Remove "MultiRotateAugOCR" to support batch ' + \38 'inference since samples_per_gpu > 1.'39 if idx is None:40 if cfg.get('pipeline',41 None) and cfg.pipeline[1].type == 'MultiRotateAugOCR':42 warnings.warn(warning_msg)43 cfg.pipeline = [cfg.pipeline[0], *cfg.pipeline[1].transforms]44 else:45 if cfg[idx][1].type == 'MultiRotateAugOCR':46 warnings.warn(warning_msg)47 cfg[idx] = [cfg[idx][0], *cfg[idx][1].transforms]48def disable_text_recog_aug_test(cfg, set_types=None):49 """Remove aug_test from test pipeline for text recognition.50 Args:51 cfg (mmcv.Config): Input config.52 set_types (list[str]): Type of dataset source. Should be53 None or sublist of ['test', 'val'].54 """55 assert set_types is None or isinstance(set_types, list)56 if set_types is None:57 set_types = ['val', 'test']58 cfg = copy.deepcopy(cfg)59 warnings.simplefilter('once')60 for set_type in set_types:61 assert set_type in ['val', 'test']62 dataset_type = cfg.data[set_type].type63 if dataset_type not in [64 'ConcatDataset', 'UniformConcatDataset', 'OCRDataset',65 'OCRSegDataset'66 ]:67 continue68 uniform_pipeline = cfg.data[set_type].get('pipeline', None)69 if is_type_list(uniform_pipeline, dict):70 update_pipeline_recog(cfg.data[set_type])71 elif is_2dlist(uniform_pipeline):72 for idx, _ in enumerate(uniform_pipeline):73 update_pipeline_recog(cfg.data[set_type].pipeline, idx)74 for dataset in cfg.data[set_type].get('datasets', []):75 if isinstance(dataset, list):76 for each_dataset in dataset:77 update_pipeline_recog(each_dataset)78 else:79 update_pipeline_recog(dataset)80 return cfg81def tensor2grayimgs(tensor, mean=(127, ), std=(127, ), **kwargs):82 """Convert tensor to 1-channel gray images.83 Args:84 tensor (torch.Tensor): Tensor that contains multiple images, shape (85 N, C, H, W).86 mean (tuple[float], optional): Mean of images. Defaults to (127).87 std (tuple[float], optional): Standard deviation of images.88 Defaults to (127).89 Returns:90 list[np.ndarray]: A list that contains multiple images.91 """92 assert torch.is_tensor(tensor) and tensor.ndim == 493 assert tensor.size(1) == len(mean) == len(std) == 194 num_imgs = tensor.size(0)95 mean = np.array(mean, dtype=np.float32)96 std = np.array(std, dtype=np.float32)97 imgs = []98 for img_id in range(num_imgs):99 img = tensor[img_id, ...].cpu().numpy().transpose(1, 2, 0)100 img = mmcv.imdenormalize(img, mean, std, to_bgr=False).astype(np.uint8)101 imgs.append(np.ascontiguousarray(img))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful