Best Python code snippet using Testify_python
tests.py
Source:tests.py
...81 82 def test_space_delimeted_string_as_input(self):83 ret = get_tag_list('cheese toast')84 self.assertEquals(len(ret), 2)85 self.failUnless(self.cheese in ret)86 self.failUnless(self.toast in ret)87 88 def test_comma_delimeted_string_as_input(self):89 ret = get_tag_list('cheese,toast')90 self.assertEquals(len(ret), 2)91 self.failUnless(self.cheese in ret)92 self.failUnless(self.toast in ret)93 94 def test_with_empty_list(self):95 self.assertEquals(get_tag_list([]), [])96 97 def test_list_of_two_strings(self):98 ret = get_tag_list(['cheese', 'toast'])99 self.assertEquals(len(ret), 2)100 self.failUnless(self.cheese in ret)101 self.failUnless(self.toast in ret)102 103 def test_list_of_tag_primary_keys(self):104 ret = get_tag_list([self.cheese.id, self.toast.id])105 self.assertEquals(len(ret), 2)106 self.failUnless(self.cheese in ret)107 self.failUnless(self.toast in ret)108 109 def test_list_of_strings_with_strange_nontag_string(self):110 ret = get_tag_list(['cheese', 'toast', 'Å ÄÄŽÄžšÄ'])111 self.assertEquals(len(ret), 2)112 self.failUnless(self.cheese in ret)113 self.failUnless(self.toast in ret)114 115 def test_list_of_tag_instances(self):116 ret = get_tag_list([self.cheese, self.toast])117 self.assertEquals(len(ret), 2)118 self.failUnless(self.cheese in ret)119 self.failUnless(self.toast in ret)120 121 def test_tuple_of_instances(self):122 ret = get_tag_list((self.cheese, self.toast))123 self.assertEquals(len(ret), 2)124 self.failUnless(self.cheese in ret)125 self.failUnless(self.toast in ret)126 127 def test_with_tag_filter(self):128 ret = get_tag_list(Tag.objects.filter(name__in=['cheese', 'toast']))129 self.assertEquals(len(ret), 2)130 self.failUnless(self.cheese in ret)131 self.failUnless(self.toast in ret)132 133 def test_with_invalid_input_mix_of_string_and_instance(self):134 try:135 get_tag_list(['cheese', self.toast])136 except ValueError, ve:137 self.assertEquals(str(ve),138 'If a list or tuple of tags is provided, they must all be tag names, Tag objects or Tag ids.')139 except Exception, e:140 raise self.failureException('the wrong type of exception was raised: type [%s] value [%]' %\141 (str(type(e)), str(e)))142 else:143 raise self.failureException('a ValueError exception was supposed to be raised!')144 145 def test_with_invalid_input(self):146 try:147 get_tag_list(29)148 except ValueError, ve:149 self.assertEquals(str(ve), 'The tag input given was invalid.')150 except Exception, e:151 raise self.failureException('the wrong type of exception was raised: type [%s] value [%s]' %\152 (str(type(e)), str(e)))153 else:154 raise self.failureException('a ValueError exception was supposed to be raised!')155 def test_with_tag_instance(self):156 self.assertEquals(get_tag(self.cheese), self.cheese)157 158 def test_with_string(self):159 self.assertEquals(get_tag('cheese'), self.cheese)160 161 def test_with_primary_key(self):162 self.assertEquals(get_tag(self.cheese.id), self.cheese)163 164 def test_nonexistent_tag(self):165 self.assertEquals(get_tag('mouse'), None)166class TestCalculateCloud(TestCase):167 def setUp(self):168 self.tags = []169 for line in open(os.path.join(os.path.dirname(__file__), 'tags.txt')).readlines():170 name, count = line.rstrip().split()171 tag = Tag(name=name)172 tag.count = int(count)173 self.tags.append(tag)174 175 def test_default_distribution(self):176 sizes = {}177 for tag in calculate_cloud(self.tags, steps=5):178 sizes[tag.font_size] = sizes.get(tag.font_size, 0) + 1179 180 # This isn't a pre-calculated test, just making sure it's consistent181 self.assertEquals(sizes[1], 48)182 self.assertEquals(sizes[2], 30)183 self.assertEquals(sizes[3], 19)184 self.assertEquals(sizes[4], 15)185 self.assertEquals(sizes[5], 10)186 187 def test_linear_distribution(self):188 sizes = {}189 for tag in calculate_cloud(self.tags, steps=5, distribution=LINEAR):190 sizes[tag.font_size] = sizes.get(tag.font_size, 0) + 1191 192 # This isn't a pre-calculated test, just making sure it's consistent193 self.assertEquals(sizes[1], 97)194 self.assertEquals(sizes[2], 12)195 self.assertEquals(sizes[3], 7)196 self.assertEquals(sizes[4], 2)197 self.assertEquals(sizes[5], 4)198 199 def test_invalid_distribution(self):200 try:201 calculate_cloud(self.tags, steps=5, distribution='cheese')202 except ValueError, ve:203 self.assertEquals(str(ve), 'Invalid distribution algorithm specified: cheese.')204 except Exception, e:205 raise self.failureException('the wrong type of exception was raised: type [%s] value [%s]' %\206 (str(type(e)), str(e)))207 else:208 raise self.failureException('a ValueError exception was supposed to be raised!')209 210###########211# Tagging #212###########213class TestBasicTagging(TestCase):214 def setUp(self):215 self.dead_parrot = Parrot.objects.create(state='dead')216 217 def test_update_tags(self):218 Tag.objects.update_tags(self.dead_parrot, 'foo,bar,"ter"')219 tags = Tag.objects.get_for_object(self.dead_parrot)220 self.assertEquals(len(tags), 3)221 self.failUnless(get_tag('foo') in tags)222 self.failUnless(get_tag('bar') in tags)223 self.failUnless(get_tag('ter') in tags)224 225 Tag.objects.update_tags(self.dead_parrot, '"foo" bar "baz"')226 tags = Tag.objects.get_for_object(self.dead_parrot)227 self.assertEquals(len(tags), 3)228 self.failUnless(get_tag('bar') in tags)229 self.failUnless(get_tag('baz') in tags)230 self.failUnless(get_tag('foo') in tags)231 232 def test_add_tag(self):233 # start off in a known, mildly interesting state234 Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')235 tags = Tag.objects.get_for_object(self.dead_parrot)236 self.assertEquals(len(tags), 3)237 self.failUnless(get_tag('bar') in tags)238 self.failUnless(get_tag('baz') in tags)239 self.failUnless(get_tag('foo') in tags)240 241 # try to add a tag that already exists242 Tag.objects.add_tag(self.dead_parrot, 'foo')243 tags = Tag.objects.get_for_object(self.dead_parrot)244 self.assertEquals(len(tags), 3)245 self.failUnless(get_tag('bar') in tags)246 self.failUnless(get_tag('baz') in tags)247 self.failUnless(get_tag('foo') in tags)248 249 # now add a tag that doesn't already exist250 Tag.objects.add_tag(self.dead_parrot, 'zip')251 tags = Tag.objects.get_for_object(self.dead_parrot)252 self.assertEquals(len(tags), 4)253 self.failUnless(get_tag('zip') in tags)254 self.failUnless(get_tag('bar') in tags)255 self.failUnless(get_tag('baz') in tags)256 self.failUnless(get_tag('foo') in tags)257 258 def test_add_tag_invalid_input_no_tags_specified(self):259 # start off in a known, mildly interesting state260 Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')261 tags = Tag.objects.get_for_object(self.dead_parrot)262 self.assertEquals(len(tags), 3)263 self.failUnless(get_tag('bar') in tags)264 self.failUnless(get_tag('baz') in tags)265 self.failUnless(get_tag('foo') in tags)266 267 try:268 Tag.objects.add_tag(self.dead_parrot, ' ')269 except AttributeError, ae:270 self.assertEquals(str(ae), 'No tags were given: " ".')271 except Exception, e:272 raise self.failureException('the wrong type of exception was raised: type [%s] value [%s]' %\273 (str(type(e)), str(e)))274 else:275 raise self.failureException('an AttributeError exception was supposed to be raised!')276 277 def test_add_tag_invalid_input_multiple_tags_specified(self):278 # start off in a known, mildly interesting state279 Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')280 tags = Tag.objects.get_for_object(self.dead_parrot)281 self.assertEquals(len(tags), 3)282 self.failUnless(get_tag('bar') in tags)283 self.failUnless(get_tag('baz') in tags)284 self.failUnless(get_tag('foo') in tags)285 286 try:287 Tag.objects.add_tag(self.dead_parrot, 'one two')288 except AttributeError, ae:289 self.assertEquals(str(ae), 'Multiple tags were given: "one two".')290 except Exception, e:291 raise self.failureException('the wrong type of exception was raised: type [%s] value [%s]' %\292 (str(type(e)), str(e)))293 else:294 raise self.failureException('an AttributeError exception was supposed to be raised!')295 296 def test_update_tags_exotic_characters(self):297 # start off in a known, mildly interesting state298 Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')299 tags = Tag.objects.get_for_object(self.dead_parrot)300 self.assertEquals(len(tags), 3)301 self.failUnless(get_tag('bar') in tags)302 self.failUnless(get_tag('baz') in tags)303 self.failUnless(get_tag('foo') in tags)304 305 Tag.objects.update_tags(self.dead_parrot, u'Å ÄÄŽÄžšÄ')306 tags = Tag.objects.get_for_object(self.dead_parrot)307 self.assertEquals(len(tags), 1)308 self.assertEquals(tags[0].name, u'Å ÄÄŽÄžšÄ')309 310 Tag.objects.update_tags(self.dead_parrot, u'ä½ å¥½')311 tags = Tag.objects.get_for_object(self.dead_parrot)312 self.assertEquals(len(tags), 1)313 self.assertEquals(tags[0].name, u'ä½ å¥½')314 315 def test_update_tags_with_none(self):316 # start off in a known, mildly interesting state317 Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')318 tags = Tag.objects.get_for_object(self.dead_parrot)319 self.assertEquals(len(tags), 3)320 self.failUnless(get_tag('bar') in tags)321 self.failUnless(get_tag('baz') in tags)322 self.failUnless(get_tag('foo') in tags)323 324 Tag.objects.update_tags(self.dead_parrot, None)325 tags = Tag.objects.get_for_object(self.dead_parrot)326 self.assertEquals(len(tags), 0)327class TestModelTagField(TestCase):328 """ Test the 'tags' field on models. """329 330 def test_create_with_tags_specified(self):331 f1 = FormTest.objects.create(tags=u'test3 test2 test1')332 tags = Tag.objects.get_for_object(f1)333 test1_tag = get_tag('test1')334 test2_tag = get_tag('test2')335 test3_tag = get_tag('test3')336 self.failUnless(None not in (test1_tag, test2_tag, test3_tag))337 self.assertEquals(len(tags), 3)338 self.failUnless(test1_tag in tags)339 self.failUnless(test2_tag in tags)340 self.failUnless(test3_tag in tags)341 342 def test_update_via_tags_field(self):343 f1 = FormTest.objects.create(tags=u'test3 test2 test1')344 tags = Tag.objects.get_for_object(f1)345 test1_tag = get_tag('test1')346 test2_tag = get_tag('test2')347 test3_tag = get_tag('test3')348 self.failUnless(None not in (test1_tag, test2_tag, test3_tag))349 self.assertEquals(len(tags), 3)350 self.failUnless(test1_tag in tags)351 self.failUnless(test2_tag in tags)352 self.failUnless(test3_tag in tags)353 354 f1.tags = u'test4'355 f1.save()356 tags = Tag.objects.get_for_object(f1)357 test4_tag = get_tag('test4')358 self.assertEquals(len(tags), 1)359 self.assertEquals(tags[0], test4_tag)360 361 f1.tags = ''362 f1.save()363 tags = Tag.objects.get_for_object(f1)364 self.assertEquals(len(tags), 0)365 366class TestSettings(TestCase):367 def setUp(self):368 self.original_force_lower_case_tags = settings.FORCE_LOWERCASE_TAGS369 self.dead_parrot = Parrot.objects.create(state='dead')370 371 def tearDown(self):372 settings.FORCE_LOWERCASE_TAGS = self.original_force_lower_case_tags373 374 def test_force_lowercase_tags(self):375 """ Test forcing tags to lowercase. """376 377 settings.FORCE_LOWERCASE_TAGS = True378 379 Tag.objects.update_tags(self.dead_parrot, 'foO bAr Ter')380 tags = Tag.objects.get_for_object(self.dead_parrot)381 self.assertEquals(len(tags), 3)382 foo_tag = get_tag('foo')383 bar_tag = get_tag('bar')384 ter_tag = get_tag('ter')385 self.failUnless(foo_tag in tags)386 self.failUnless(bar_tag in tags)387 self.failUnless(ter_tag in tags)388 389 Tag.objects.update_tags(self.dead_parrot, 'foO bAr baZ')390 tags = Tag.objects.get_for_object(self.dead_parrot)391 baz_tag = get_tag('baz')392 self.assertEquals(len(tags), 3)393 self.failUnless(bar_tag in tags)394 self.failUnless(baz_tag in tags)395 self.failUnless(foo_tag in tags)396 397 Tag.objects.add_tag(self.dead_parrot, 'FOO')398 tags = Tag.objects.get_for_object(self.dead_parrot)399 self.assertEquals(len(tags), 3)400 self.failUnless(bar_tag in tags)401 self.failUnless(baz_tag in tags)402 self.failUnless(foo_tag in tags)403 404 Tag.objects.add_tag(self.dead_parrot, 'Zip')405 tags = Tag.objects.get_for_object(self.dead_parrot)406 self.assertEquals(len(tags), 4)407 zip_tag = get_tag('zip')408 self.failUnless(bar_tag in tags)409 self.failUnless(baz_tag in tags)410 self.failUnless(foo_tag in tags)411 self.failUnless(zip_tag in tags)412 413 f1 = FormTest.objects.create()414 f1.tags = u'TEST5'415 f1.save()416 tags = Tag.objects.get_for_object(f1)417 test5_tag = get_tag('test5')418 self.assertEquals(len(tags), 1)419 self.failUnless(test5_tag in tags)420 self.assertEquals(f1.tags, u'test5')421class TestTagUsageForModelBaseCase(TestCase):422 def test_tag_usage_for_model_empty(self):423 self.assertEquals(Tag.objects.usage_for_model(Parrot), [])424class TestTagUsageForModel(TestCase):425 def setUp(self):426 parrot_details = (427 ('pining for the fjords', 9, True, 'foo bar'),428 ('passed on', 6, False, 'bar baz ter'),429 ('no more', 4, True, 'foo ter'),430 ('late', 2, False, 'bar ter'),431 )432 433 for state, perch_size, perch_smelly, tags in parrot_details:434 perch = Perch.objects.create(size=perch_size, smelly=perch_smelly)435 parrot = Parrot.objects.create(state=state, perch=perch)436 Tag.objects.update_tags(parrot, tags)437 438 def test_tag_usage_for_model(self):439 tag_usage = Tag.objects.usage_for_model(Parrot, counts=True)440 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]441 self.assertEquals(len(relevant_attribute_list), 4)442 self.failUnless((u'bar', 3) in relevant_attribute_list)443 self.failUnless((u'baz', 1) in relevant_attribute_list)444 self.failUnless((u'foo', 2) in relevant_attribute_list)445 self.failUnless((u'ter', 3) in relevant_attribute_list)446 447 def test_tag_usage_for_model_with_min_count(self):448 tag_usage = Tag.objects.usage_for_model(Parrot, min_count = 2)449 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]450 self.assertEquals(len(relevant_attribute_list), 3)451 self.failUnless((u'bar', 3) in relevant_attribute_list)452 self.failUnless((u'foo', 2) in relevant_attribute_list)453 self.failUnless((u'ter', 3) in relevant_attribute_list)454 455 def test_tag_usage_with_filter_on_model_objects(self):456 tag_usage = Tag.objects.usage_for_model(Parrot, counts=True, filters=dict(state='no more'))457 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]458 self.assertEquals(len(relevant_attribute_list), 2)459 self.failUnless((u'foo', 1) in relevant_attribute_list)460 self.failUnless((u'ter', 1) in relevant_attribute_list)461 462 tag_usage = Tag.objects.usage_for_model(Parrot, counts=True, filters=dict(state__startswith='p'))463 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]464 self.assertEquals(len(relevant_attribute_list), 4)465 self.failUnless((u'bar', 2) in relevant_attribute_list)466 self.failUnless((u'baz', 1) in relevant_attribute_list)467 self.failUnless((u'foo', 1) in relevant_attribute_list)468 self.failUnless((u'ter', 1) in relevant_attribute_list)469 470 tag_usage = Tag.objects.usage_for_model(Parrot, counts=True, filters=dict(perch__size__gt=4))471 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]472 self.assertEquals(len(relevant_attribute_list), 4)473 self.failUnless((u'bar', 2) in relevant_attribute_list)474 self.failUnless((u'baz', 1) in relevant_attribute_list)475 self.failUnless((u'foo', 1) in relevant_attribute_list)476 self.failUnless((u'ter', 1) in relevant_attribute_list)477 478 tag_usage = Tag.objects.usage_for_model(Parrot, counts=True, filters=dict(perch__smelly=True))479 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]480 self.assertEquals(len(relevant_attribute_list), 3)481 self.failUnless((u'bar', 1) in relevant_attribute_list)482 self.failUnless((u'foo', 2) in relevant_attribute_list)483 self.failUnless((u'ter', 1) in relevant_attribute_list)484 485 tag_usage = Tag.objects.usage_for_model(Parrot, min_count=2, filters=dict(perch__smelly=True))486 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]487 self.assertEquals(len(relevant_attribute_list), 1)488 self.failUnless((u'foo', 2) in relevant_attribute_list)489 490 tag_usage = Tag.objects.usage_for_model(Parrot, filters=dict(perch__size__gt=4))491 relevant_attribute_list = [(tag.name, hasattr(tag, 'counts')) for tag in tag_usage]492 self.assertEquals(len(relevant_attribute_list), 4)493 self.failUnless((u'bar', False) in relevant_attribute_list)494 self.failUnless((u'baz', False) in relevant_attribute_list)495 self.failUnless((u'foo', False) in relevant_attribute_list)496 self.failUnless((u'ter', False) in relevant_attribute_list)497 498 tag_usage = Tag.objects.usage_for_model(Parrot, filters=dict(perch__size__gt=99))499 relevant_attribute_list = [(tag.name, hasattr(tag, 'counts')) for tag in tag_usage]500 self.assertEquals(len(relevant_attribute_list), 0)501class TestTagsRelatedForModel(TestCase):502 def setUp(self):503 parrot_details = (504 ('pining for the fjords', 9, True, 'foo bar'),505 ('passed on', 6, False, 'bar baz ter'),506 ('no more', 4, True, 'foo ter'),507 ('late', 2, False, 'bar ter'),508 )509 510 for state, perch_size, perch_smelly, tags in parrot_details:511 perch = Perch.objects.create(size=perch_size, smelly=perch_smelly)512 parrot = Parrot.objects.create(state=state, perch=perch)513 Tag.objects.update_tags(parrot, tags)514 515 def test_related_for_model_with_tag_query_sets_as_input(self):516 related_tags = Tag.objects.related_for_model(Tag.objects.filter(name__in=['bar']), Parrot, counts=True)517 relevant_attribute_list = [(tag.name, tag.count) for tag in related_tags]518 self.assertEquals(len(relevant_attribute_list), 3)519 self.failUnless((u'baz', 1) in relevant_attribute_list)520 self.failUnless((u'foo', 1) in relevant_attribute_list)521 self.failUnless((u'ter', 2) in relevant_attribute_list)522 523 related_tags = Tag.objects.related_for_model(Tag.objects.filter(name__in=['bar']), Parrot, min_count=2)524 relevant_attribute_list = [(tag.name, tag.count) for tag in related_tags]525 self.assertEquals(len(relevant_attribute_list), 1)526 self.failUnless((u'ter', 2) in relevant_attribute_list)527 528 related_tags = Tag.objects.related_for_model(Tag.objects.filter(name__in=['bar']), Parrot, counts=False)529 relevant_attribute_list = [tag.name for tag in related_tags]530 self.assertEquals(len(relevant_attribute_list), 3)531 self.failUnless(u'baz' in relevant_attribute_list)532 self.failUnless(u'foo' in relevant_attribute_list)533 self.failUnless(u'ter' in relevant_attribute_list)534 535 related_tags = Tag.objects.related_for_model(Tag.objects.filter(name__in=['bar', 'ter']), Parrot, counts=True)536 relevant_attribute_list = [(tag.name, tag.count) for tag in related_tags]537 self.assertEquals(len(relevant_attribute_list), 1)538 self.failUnless((u'baz', 1) in relevant_attribute_list)539 540 related_tags = Tag.objects.related_for_model(Tag.objects.filter(name__in=['bar', 'ter', 'baz']), Parrot, counts=True)541 relevant_attribute_list = [(tag.name, tag.count) for tag in related_tags]542 self.assertEquals(len(relevant_attribute_list), 0)543 544 def test_related_for_model_with_tag_strings_as_input(self):545 # Once again, with feeling (strings)546 related_tags = Tag.objects.related_for_model('bar', Parrot, counts=True)547 relevant_attribute_list = [(tag.name, tag.count) for tag in related_tags]548 self.assertEquals(len(relevant_attribute_list), 3)549 self.failUnless((u'baz', 1) in relevant_attribute_list)550 self.failUnless((u'foo', 1) in relevant_attribute_list)551 self.failUnless((u'ter', 2) in relevant_attribute_list)552 553 related_tags = Tag.objects.related_for_model('bar', Parrot, min_count=2)554 relevant_attribute_list = [(tag.name, tag.count) for tag in related_tags]555 self.assertEquals(len(relevant_attribute_list), 1)556 self.failUnless((u'ter', 2) in relevant_attribute_list)557 558 related_tags = Tag.objects.related_for_model('bar', Parrot, counts=False)559 relevant_attribute_list = [tag.name for tag in related_tags]560 self.assertEquals(len(relevant_attribute_list), 3)561 self.failUnless(u'baz' in relevant_attribute_list)562 self.failUnless(u'foo' in relevant_attribute_list)563 self.failUnless(u'ter' in relevant_attribute_list)564 565 related_tags = Tag.objects.related_for_model(['bar', 'ter'], Parrot, counts=True)566 relevant_attribute_list = [(tag.name, tag.count) for tag in related_tags]567 self.assertEquals(len(relevant_attribute_list), 1)568 self.failUnless((u'baz', 1) in relevant_attribute_list)569 570 related_tags = Tag.objects.related_for_model(['bar', 'ter', 'baz'], Parrot, counts=True)571 relevant_attribute_list = [(tag.name, tag.count) for tag in related_tags]572 self.assertEquals(len(relevant_attribute_list), 0)573 574class TestGetTaggedObjectsByModel(TestCase):575 def setUp(self):576 parrot_details = (577 ('pining for the fjords', 9, True, 'foo bar'),578 ('passed on', 6, False, 'bar baz ter'),579 ('no more', 4, True, 'foo ter'),580 ('late', 2, False, 'bar ter'),581 )582 583 for state, perch_size, perch_smelly, tags in parrot_details:584 perch = Perch.objects.create(size=perch_size, smelly=perch_smelly)585 parrot = Parrot.objects.create(state=state, perch=perch)586 Tag.objects.update_tags(parrot, tags)587 588 self.foo = Tag.objects.get(name='foo')589 self.bar = Tag.objects.get(name='bar')590 self.baz = Tag.objects.get(name='baz')591 self.ter = Tag.objects.get(name='ter')592 593 self.pining_for_the_fjords_parrot = Parrot.objects.get(state='pining for the fjords')594 self.passed_on_parrot = Parrot.objects.get(state='passed on')595 self.no_more_parrot = Parrot.objects.get(state='no more')596 self.late_parrot = Parrot.objects.get(state='late')597 598 def test_get_by_model_simple(self):599 parrots = TaggedItem.objects.get_by_model(Parrot, self.foo)600 self.assertEquals(len(parrots), 2)601 self.failUnless(self.no_more_parrot in parrots)602 self.failUnless(self.pining_for_the_fjords_parrot in parrots)603 604 parrots = TaggedItem.objects.get_by_model(Parrot, self.bar)605 self.assertEquals(len(parrots), 3)606 self.failUnless(self.late_parrot in parrots)607 self.failUnless(self.passed_on_parrot in parrots)608 self.failUnless(self.pining_for_the_fjords_parrot in parrots)609 610 def test_get_by_model_intersection(self):611 parrots = TaggedItem.objects.get_by_model(Parrot, [self.foo, self.baz])612 self.assertEquals(len(parrots), 0)613 614 parrots = TaggedItem.objects.get_by_model(Parrot, [self.foo, self.bar])615 self.assertEquals(len(parrots), 1)616 self.failUnless(self.pining_for_the_fjords_parrot in parrots)617 618 parrots = TaggedItem.objects.get_by_model(Parrot, [self.bar, self.ter])619 self.assertEquals(len(parrots), 2)620 self.failUnless(self.late_parrot in parrots)621 self.failUnless(self.passed_on_parrot in parrots)622 623 # Issue 114 - Intersection with non-existant tags624 parrots = TaggedItem.objects.get_intersection_by_model(Parrot, [])625 self.assertEquals(len(parrots), 0)626 627 def test_get_by_model_with_tag_querysets_as_input(self):628 parrots = TaggedItem.objects.get_by_model(Parrot, Tag.objects.filter(name__in=['foo', 'baz']))629 self.assertEquals(len(parrots), 0)630 631 parrots = TaggedItem.objects.get_by_model(Parrot, Tag.objects.filter(name__in=['foo', 'bar']))632 self.assertEquals(len(parrots), 1)633 self.failUnless(self.pining_for_the_fjords_parrot in parrots)634 635 parrots = TaggedItem.objects.get_by_model(Parrot, Tag.objects.filter(name__in=['bar', 'ter']))636 self.assertEquals(len(parrots), 2)637 self.failUnless(self.late_parrot in parrots)638 self.failUnless(self.passed_on_parrot in parrots)639 640 def test_get_by_model_with_strings_as_input(self):641 parrots = TaggedItem.objects.get_by_model(Parrot, 'foo baz')642 self.assertEquals(len(parrots), 0)643 644 parrots = TaggedItem.objects.get_by_model(Parrot, 'foo bar')645 self.assertEquals(len(parrots), 1)646 self.failUnless(self.pining_for_the_fjords_parrot in parrots)647 648 parrots = TaggedItem.objects.get_by_model(Parrot, 'bar ter')649 self.assertEquals(len(parrots), 2)650 self.failUnless(self.late_parrot in parrots)651 self.failUnless(self.passed_on_parrot in parrots)652 653 def test_get_by_model_with_lists_of_strings_as_input(self):654 parrots = TaggedItem.objects.get_by_model(Parrot, ['foo', 'baz'])655 self.assertEquals(len(parrots), 0)656 657 parrots = TaggedItem.objects.get_by_model(Parrot, ['foo', 'bar'])658 self.assertEquals(len(parrots), 1)659 self.failUnless(self.pining_for_the_fjords_parrot in parrots)660 661 parrots = TaggedItem.objects.get_by_model(Parrot, ['bar', 'ter'])662 self.assertEquals(len(parrots), 2)663 self.failUnless(self.late_parrot in parrots)664 self.failUnless(self.passed_on_parrot in parrots)665 666 def test_get_by_nonexistent_tag(self):667 # Issue 50 - Get by non-existent tag668 parrots = TaggedItem.objects.get_by_model(Parrot, 'argatrons')669 self.assertEquals(len(parrots), 0)670 671 def test_get_union_by_model(self):672 parrots = TaggedItem.objects.get_union_by_model(Parrot, ['foo', 'ter'])673 self.assertEquals(len(parrots), 4)674 self.failUnless(self.late_parrot in parrots)675 self.failUnless(self.no_more_parrot in parrots)676 self.failUnless(self.passed_on_parrot in parrots)677 self.failUnless(self.pining_for_the_fjords_parrot in parrots)678 679 parrots = TaggedItem.objects.get_union_by_model(Parrot, ['bar', 'baz'])680 self.assertEquals(len(parrots), 3)681 self.failUnless(self.late_parrot in parrots)682 self.failUnless(self.passed_on_parrot in parrots)683 self.failUnless(self.pining_for_the_fjords_parrot in parrots)684 685 # Issue 114 - Union with non-existant tags686 parrots = TaggedItem.objects.get_union_by_model(Parrot, [])687 self.assertEquals(len(parrots), 0)688class TestGetRelatedTaggedItems(TestCase):689 def setUp(self):690 parrot_details = (691 ('pining for the fjords', 9, True, 'foo bar'),692 ('passed on', 6, False, 'bar baz ter'),693 ('no more', 4, True, 'foo ter'),694 ('late', 2, False, 'bar ter'),695 )696 697 for state, perch_size, perch_smelly, tags in parrot_details:698 perch = Perch.objects.create(size=perch_size, smelly=perch_smelly)699 parrot = Parrot.objects.create(state=state, perch=perch)700 Tag.objects.update_tags(parrot, tags)701 702 self.l1 = Link.objects.create(name='link 1')703 Tag.objects.update_tags(self.l1, 'tag1 tag2 tag3 tag4 tag5')704 self.l2 = Link.objects.create(name='link 2')705 Tag.objects.update_tags(self.l2, 'tag1 tag2 tag3')706 self.l3 = Link.objects.create(name='link 3')707 Tag.objects.update_tags(self.l3, 'tag1')708 self.l4 = Link.objects.create(name='link 4')709 710 self.a1 = Article.objects.create(name='article 1')711 Tag.objects.update_tags(self.a1, 'tag1 tag2 tag3 tag4')712 713 def test_get_related_objects_of_same_model(self):714 related_objects = TaggedItem.objects.get_related(self.l1, Link)715 self.assertEquals(len(related_objects), 2)716 self.failUnless(self.l2 in related_objects)717 self.failUnless(self.l3 in related_objects)718 719 related_objects = TaggedItem.objects.get_related(self.l4, Link)720 self.assertEquals(len(related_objects), 0)721 722 def test_get_related_objects_of_same_model_limited_number_of_results(self):723 # This fails on Oracle because it has no support for a 'LIMIT' clause.724 # See http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:127412348064725 726 # ask for no more than 1 result727 related_objects = TaggedItem.objects.get_related(self.l1, Link, num=1)728 self.assertEquals(len(related_objects), 1)729 self.failUnless(self.l2 in related_objects)730 731 def test_get_related_objects_of_same_model_limit_related_items(self):732 related_objects = TaggedItem.objects.get_related(self.l1, Link.objects.exclude(name='link 3'))733 self.assertEquals(len(related_objects), 1)734 self.failUnless(self.l2 in related_objects)735 736 def test_get_related_objects_of_different_model(self):737 related_objects = TaggedItem.objects.get_related(self.a1, Link)738 self.assertEquals(len(related_objects), 3)739 self.failUnless(self.l1 in related_objects)740 self.failUnless(self.l2 in related_objects)741 self.failUnless(self.l3 in related_objects)742 743 Tag.objects.update_tags(self.a1, 'tag6')744 related_objects = TaggedItem.objects.get_related(self.a1, Link)745 self.assertEquals(len(related_objects), 0)746 747class TestTagUsageForQuerySet(TestCase):748 def setUp(self):749 parrot_details = (750 ('pining for the fjords', 9, True, 'foo bar'),751 ('passed on', 6, False, 'bar baz ter'),752 ('no more', 4, True, 'foo ter'),753 ('late', 2, False, 'bar ter'),754 )755 756 for state, perch_size, perch_smelly, tags in parrot_details:757 perch = Perch.objects.create(size=perch_size, smelly=perch_smelly)758 parrot = Parrot.objects.create(state=state, perch=perch)759 Tag.objects.update_tags(parrot, tags)760 761 def test_tag_usage_for_queryset(self):762 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(state='no more'), counts=True)763 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]764 self.assertEquals(len(relevant_attribute_list), 2)765 self.failUnless((u'foo', 1) in relevant_attribute_list)766 self.failUnless((u'ter', 1) in relevant_attribute_list)767 768 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(state__startswith='p'), counts=True)769 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]770 self.assertEquals(len(relevant_attribute_list), 4)771 self.failUnless((u'bar', 2) in relevant_attribute_list)772 self.failUnless((u'baz', 1) in relevant_attribute_list)773 self.failUnless((u'foo', 1) in relevant_attribute_list)774 self.failUnless((u'ter', 1) in relevant_attribute_list)775 776 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=4), counts=True)777 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]778 self.assertEquals(len(relevant_attribute_list), 4)779 self.failUnless((u'bar', 2) in relevant_attribute_list)780 self.failUnless((u'baz', 1) in relevant_attribute_list)781 self.failUnless((u'foo', 1) in relevant_attribute_list)782 self.failUnless((u'ter', 1) in relevant_attribute_list)783 784 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__smelly=True), counts=True)785 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]786 self.assertEquals(len(relevant_attribute_list), 3)787 self.failUnless((u'bar', 1) in relevant_attribute_list)788 self.failUnless((u'foo', 2) in relevant_attribute_list)789 self.failUnless((u'ter', 1) in relevant_attribute_list)790 791 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__smelly=True), min_count=2)792 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]793 self.assertEquals(len(relevant_attribute_list), 1)794 self.failUnless((u'foo', 2) in relevant_attribute_list)795 796 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=4))797 relevant_attribute_list = [(tag.name, hasattr(tag, 'counts')) for tag in tag_usage]798 self.assertEquals(len(relevant_attribute_list), 4)799 self.failUnless((u'bar', False) in relevant_attribute_list)800 self.failUnless((u'baz', False) in relevant_attribute_list)801 self.failUnless((u'foo', False) in relevant_attribute_list)802 self.failUnless((u'ter', False) in relevant_attribute_list)803 804 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=99))805 relevant_attribute_list = [(tag.name, hasattr(tag, 'counts')) for tag in tag_usage]806 self.assertEquals(len(relevant_attribute_list), 0)807 808 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')), counts=True)809 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]810 self.assertEquals(len(relevant_attribute_list), 3)811 self.failUnless((u'bar', 2) in relevant_attribute_list)812 self.failUnless((u'foo', 1) in relevant_attribute_list)813 self.failUnless((u'ter', 1) in relevant_attribute_list)814 815 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')), min_count=2)816 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]817 self.assertEquals(len(relevant_attribute_list), 1)818 self.failUnless((u'bar', 2) in relevant_attribute_list)819 820 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')))821 relevant_attribute_list = [(tag.name, hasattr(tag, 'counts')) for tag in tag_usage]822 self.assertEquals(len(relevant_attribute_list), 3)823 self.failUnless((u'bar', False) in relevant_attribute_list)824 self.failUnless((u'foo', False) in relevant_attribute_list)825 self.failUnless((u'ter', False) in relevant_attribute_list)826 827 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.exclude(state='passed on'), counts=True)828 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]829 self.assertEquals(len(relevant_attribute_list), 3)830 self.failUnless((u'bar', 2) in relevant_attribute_list)831 self.failUnless((u'foo', 2) in relevant_attribute_list)832 self.failUnless((u'ter', 2) in relevant_attribute_list)833 834 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.exclude(state__startswith='p'), min_count=2)835 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]836 self.assertEquals(len(relevant_attribute_list), 1)837 self.failUnless((u'ter', 2) in relevant_attribute_list)838 839 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.exclude(Q(perch__size__gt=6) | Q(perch__smelly=False)), counts=True)840 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]841 self.assertEquals(len(relevant_attribute_list), 2)842 self.failUnless((u'foo', 1) in relevant_attribute_list)843 self.failUnless((u'ter', 1) in relevant_attribute_list)844 845 tag_usage = Tag.objects.usage_for_queryset(Parrot.objects.exclude(perch__smelly=True).filter(state__startswith='l'), counts=True)846 relevant_attribute_list = [(tag.name, tag.count) for tag in tag_usage]847 self.assertEquals(len(relevant_attribute_list), 2)848 self.failUnless((u'bar', 1) in relevant_attribute_list)849 self.failUnless((u'ter', 1) in relevant_attribute_list)850 851################852# Model Fields #853################854class TestTagFieldInForms(TestCase):855 def test_tag_field_in_modelform(self):856 # Ensure that automatically created forms use TagField857 class TestForm(forms.ModelForm):858 class Meta:859 model = FormTest860 861 form = TestForm()862 self.assertEquals(form.fields['tags'].__class__.__name__, 'TagField')863 ...
test_operator.py
Source:test_operator.py
...6 self.failIf(operator.lt(1, 0))7 self.failIf(operator.lt(1, 0.0))8 self.failIf(operator.lt(1, 1))9 self.failIf(operator.lt(1, 1.0))10 self.failUnless(operator.lt(1, 2))11 self.failUnless(operator.lt(1, 2.0))12 def test_le(self):13 self.failIf(operator.le(1, 0))14 self.failIf(operator.le(1, 0.0))15 self.failUnless(operator.le(1, 1))16 self.failUnless(operator.le(1, 1.0))17 self.failUnless(operator.le(1, 2))18 self.failUnless(operator.le(1, 2.0))19 def test_eq(self):20 self.failIf(operator.eq(1, 0))21 self.failIf(operator.eq(1, 0.0))22 self.failUnless(operator.eq(1, 1))23 self.failUnless(operator.eq(1, 1.0))24 self.failIf(operator.eq(1, 2))25 self.failIf(operator.eq(1, 2.0))26 def test_ne(self):27 self.failUnless(operator.ne(1, 0))28 self.failUnless(operator.ne(1, 0.0))29 self.failIf(operator.ne(1, 1))30 self.failIf(operator.ne(1, 1.0))31 self.failUnless(operator.ne(1, 2))32 self.failUnless(operator.ne(1, 2.0))33 def test_ge(self):34 self.failUnless(operator.ge(1, 0))35 self.failUnless(operator.ge(1, 0.0))36 self.failUnless(operator.ge(1, 1))37 self.failUnless(operator.ge(1, 1.0))38 self.failIf(operator.ge(1, 2))39 self.failIf(operator.ge(1, 2.0))40 def test_gt(self):41 self.failUnless(operator.gt(1, 0))42 self.failUnless(operator.gt(1, 0.0))43 self.failIf(operator.gt(1, 1))44 self.failIf(operator.gt(1, 1.0))45 self.failIf(operator.gt(1, 2))46 self.failIf(operator.gt(1, 2.0))47 def test_abs(self):48 self.failUnless(operator.abs(-1) == 1)49 self.failUnless(operator.abs(1) == 1)50 def test_add(self):51 self.failUnless(operator.add(3, 4) == 7)52 def test_bitwise_and(self):53 self.failUnless(operator.and_(0xf, 0xa) == 0xa)54 def test_concat(self):55 self.failUnless(operator.concat('py', 'thon') == 'python')56 self.failUnless(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])57 def test_countOf(self):58 self.failUnless(operator.countOf([1, 2, 1, 3, 1, 4], 3) == 1)59 self.failUnless(operator.countOf([1, 2, 1, 3, 1, 4], 5) == 0)60 def test_delitem(self):61 a = [4, 3, 2, 1]62 self.failUnless(operator.delitem(a, 1) is None)63 self.assert_(a == [4, 2, 1])64 def test_delslice(self):65 a = range(10)66 self.failUnless(operator.delslice(a, 2, 8) is None)67 self.assert_(a == [0, 1, 8, 9])68 def test_div(self):69 self.failUnless(operator.floordiv(5, 2) == 2)70 def test_floordiv(self):71 self.failUnless(operator.floordiv(5, 2) == 2)72 def test_truediv(self):73 self.failUnless(operator.truediv(5, 2) == 2.5)74 def test_getitem(self):75 a = range(10)76 self.failUnless(operator.getitem(a, 2) == 2)77 def test_getslice(self):78 a = range(10)79 self.failUnless(operator.getslice(a, 4, 6) == [4, 5])80 def test_indexOf(self):81 self.failUnless(operator.indexOf([4, 3, 2, 1], 3) == 1)82 self.assertRaises(ValueError, operator.indexOf, [4, 3, 2, 1], 0)83 def test_invert(self):84 self.failUnless(operator.inv(4) == -5)85 def test_isCallable(self):86 class C:87 pass88 def check(self, o, v):89 self.assert_(operator.isCallable(o) == callable(o) == v)90 check(self, 4, 0)91 check(self, operator.isCallable, 1)92 check(self, C, 1)93 check(self, C(), 0)94 def test_isMappingType(self):95 self.failIf(operator.isMappingType(1))96 self.failIf(operator.isMappingType(operator.isMappingType))97 self.failUnless(operator.isMappingType(operator.__dict__))98 self.failUnless(operator.isMappingType({}))99 def test_isNumberType(self):100 self.failUnless(operator.isNumberType(8))101 self.failUnless(operator.isNumberType(8j))102 self.failUnless(operator.isNumberType(8L))103 self.failUnless(operator.isNumberType(8.3))104 self.failIf(operator.isNumberType(dir()))105 def test_isSequenceType(self):106 self.failUnless(operator.isSequenceType(dir()))107 self.failUnless(operator.isSequenceType(()))108 self.failUnless(operator.isSequenceType(xrange(10)))109 self.failUnless(operator.isSequenceType('yeahbuddy'))110 self.failIf(operator.isSequenceType(3))111 def test_lshift(self):112 self.failUnless(operator.lshift(5, 1) == 10)113 self.failUnless(operator.lshift(5, 0) == 5)114 self.assertRaises(ValueError, operator.lshift, 2, -1)115 def test_mod(self):116 self.failUnless(operator.mod(5, 2) == 1)117 def test_mul(self):118 self.failUnless(operator.mul(5, 2) == 10)119 def test_neg(self):120 self.failUnless(operator.neg(5) == -5)121 self.failUnless(operator.neg(-5) == 5)122 self.failUnless(operator.neg(0) == 0)123 self.failUnless(operator.neg(-0) == 0)124 def test_bitwise_or(self):125 self.failUnless(operator.or_(0xa, 0x5) == 0xf)126 def test_pos(self):127 self.failUnless(operator.pos(5) == 5)128 self.failUnless(operator.pos(-5) == -5)129 self.failUnless(operator.pos(0) == 0)130 self.failUnless(operator.pos(-0) == 0)131 def test_repeat(self):132 a = range(3)133 self.failUnless(operator.repeat(a, 2) == a+a)134 self.failUnless(operator.repeat(a, 1) == a)135 self.failUnless(operator.repeat(a, 0) == [])136 a = (1, 2, 3)137 self.failUnless(operator.repeat(a, 2) == a+a)138 self.failUnless(operator.repeat(a, 1) == a)139 self.failUnless(operator.repeat(a, 0) == ())140 a = '123'141 self.failUnless(operator.repeat(a, 2) == a+a)142 self.failUnless(operator.repeat(a, 1) == a)143 self.failUnless(operator.repeat(a, 0) == '')144 def test_rshift(self):145 self.failUnless(operator.rshift(5, 1) == 2)146 self.failUnless(operator.rshift(5, 0) == 5)147 self.assertRaises(ValueError, operator.rshift, 2, -1)148 def test_contains(self):149 self.failUnless(operator.contains(range(4), 2))150 self.failIf(operator.contains(range(4), 5))151 self.failUnless(operator.sequenceIncludes(range(4), 2))152 self.failIf(operator.sequenceIncludes(range(4), 5))153 def test_setitem(self):154 a = range(3)155 self.failUnless(operator.setitem(a, 0, 2) is None)156 self.assert_(a == [2, 1, 2])157 self.assertRaises(IndexError, operator.setitem, a, 4, 2)158 def test_setslice(self):159 a = range(4)160 self.failUnless(operator.setslice(a, 1, 3, [2, 1]) is None)161 self.assert_(a == [0, 2, 1, 3])162 def test_sub(self):163 self.failUnless(operator.sub(5, 2) == 3)164 def test_truth(self):165 self.failUnless(operator.truth(5))166 self.failUnless(operator.truth([0]))167 self.failIf(operator.truth(0))168 self.failIf(operator.truth([]))169 def test_bitwise_xor(self):170 self.failUnless(operator.xor(0xb, 0xc) == 0x7)171def test_main():172 test_support.run_unittest(OperatorTestCase)173if __name__ == "__main__":...
set.py
Source:set.py
...19class SimpleSetTestCase(unittest.TestCase):20 21 def testLen1(self):22 s1 = S()23 self.failUnless(len(s1) == 0)24 def testLen2(self):25 s1 = S([1, 2, 3])26 self.failUnless(len(s1) == 3)27 def testLen3(self):28 s1 = S([1, 2, 3, 3, 3])29 self.failUnless(len(s1) == 3)30 def testUnion1(self):31 s1 = S([1, 2, 3])32 s2 = S([1, 2, 3])33 e = S([1, 2, 3])34 self.failUnless(s1 | s2 == e)35 def testUnion2(self):36 s1 = S([1, 2, 3])37 s2 = S([])38 e = S([1, 2, 3])39 self.failUnless(s1 | s2 == e)40 def testUnion3(self):41 s1 = S([1, 2, 3])42 s2 = S([3, 4])43 e = S([1, 2, 3, 4])44 self.failUnless(s1 | s2 == e)45 def testIntersection1(self):46 s1 = S([1, 2, 3])47 s2 = S([1, 2, 3])48 e = S([1, 2, 3])49 self.failUnless(s1 & s2 == e)50 def testIntersection2(self):51 s1 = S([0, 1, 2, 3])52 s2 = S([1, 2, 3, 4])53 e = S([1, 2, 3])54 self.failUnless(s1 & s2 == e)55 def testIntersection3(self):56 s1 = S([1, 2, 3])57 s2 = S([])58 e = S([])59 self.failUnless(s1 & s2 == e)60 def testIntersection4(self):61 s1 = S([1, 2, 3])62 s2 = S([5, 4])63 e = S([])64 self.failUnless(s1 & s2 == e)65 def testDifference1(self):66 s1 = S([1, 2, 3])67 s2 = S([5, 4])68 e = S([1, 2, 3])69 self.failUnless(s1 - s2 == e)70 def testDifference2(self):71 s1 = S([1, 2, 3])72 s2 = S([])73 e = S([1, 2, 3])74 self.failUnless(s1 - s2 == e)75 def testDifference3(self):76 s1 = S([1, 2, 3])77 s2 = S([3, 2])78 e = S([1])79 self.failUnless(s1 - s2 == e)80 def testDifference4(self):81 s1 = S([1, 2, 3])82 s2 = S([3, 2, 1])83 e = S([])84 self.failUnless(s1 - s2 == e)85 def testSubset1(self):86 s1 = S([1, 2, 3])87 s2 = S([3, 2, 1])88 self.failUnless(s1.issubset(s2))89 def testSubset2(self):90 s1 = S([1, 2, 3])91 self.failUnless(s1.issubset(s1))92 def testSubset3(self):93 s1 = S([])94 s2 = S([1, 2, 3])95 self.failUnless(s1.issubset(s2))96 def testSubset4(self):97 s1 = S([1])98 s2 = S([1, 2, 3])99 self.failUnless(s1.issubset(s2))100 def testSubset5(self):101 s1 = S([])102 s2 = S([])103 self.failUnless(s1.issubset(s2))104 def testSubset6(self):105 s1 = S([1, 4])106 s2 = S([1, 2, 3])107 self.failUnless(not s1.issubset(s2))108 def testSuperset1(self):109 s1 = S([1, 2, 3])110 s2 = S([3, 2, 1])111 self.failUnless(s1.issuperset(s2))112 def testSuperset2(self):113 s1 = S([1, 2, 3])114 self.failUnless(s1.issuperset(s1))115 def testSuperset3(self):116 s1 = S([1, 2, 3])117 s2 = S([])118 self.failUnless(s1.issuperset(s2))119 def testSuperset4(self):120 s1 = S([1, 2, 3])121 s2 = S([1])122 self.failUnless(s1.issuperset(s2))123 def testSuperset5(self):124 s1 = S([])125 s2 = S([])126 self.failUnless(s1.issuperset(s2))127 def testSuperset6(self):128 s1 = S([1, 2, 3])129 s2 = S([1, 4])130 self.failUnless(not s1.issuperset(s2))131 def testUpdate1(self):132 s1 = S([1, 2, 3])133 u = (4, 5, 6)134 e = S([1, 2, 3, 4, 5, 6])135 s1.update(u)136 self.failUnless(s1 == e)137 def testUpdate2(self):138 s1 = S([1, 2, 3])139 u = []140 e = S([1, 2, 3])141 s1.update(u)142 self.failUnless(s1 == e)143 def testGetitem(self):144 s1 = S([1, 2, 3])145 i0 = s1[0]146 i1 = s1[1]147 i2 = s1[2]148 s2 = S([i0, i1, i2])149 self.failUnless(s1 == s2)150 def testGetslice(self):151 s1 = S([1, 2, 3])152 slice = s1[0:2]153 self.failUnless(len(slice) == 2)154 item = s1[2]155 slice.append(item)156 s2 = S(slice)157 self.failUnless(s1 == s2)158 def testDelitem(self):159 s1 = S([1, 2, 3])160 del s1[0]161 i1 = s1[0]162 i2 = s1[1]163 self.failUnless(i1 != i2)164 self.failUnless(i1 == 1 or i1 == 2 or i1 == 3)165 self.failUnless(i2 == 1 or i2 == 2 or i2 == 3)166 def testDelslice(self):167 s1 = S([1, 2, 3])168 del s1[0:2]169 i1 = s1[0]170 self.failUnless(i1 == 1 or i1 == 2 or i1 == 3)171if __name__ == '__main__':...
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!!