How to use unique_id method in avocado

Best Python code snippet using avocado_python

common_tests.py

Source:common_tests.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import warnings3warnings.filterwarnings("ignore", category=RuntimeWarning)4warnings.resetwarnings()5class Generic(object):6 """Generic class for unit testing :mod:`pydblite.pydblite` and :mod:`pydblite.sqlite`"""7 def test_create_index(self):8 indices = self.filter_db.get_indices()9 self.assertEqual(indices, [])10 self.filter_db.create_index("name")11 indices = self.filter_db.get_indices()12 self.assertEqual(indices, ["name"])13 self.filter_db.create_index("active")14 indices = self.filter_db.get_indices()15 self.assertTrue("active" in indices)16 self.assertTrue("name" in indices)17 self.assertEqual(len(indices), 2)18 def test_delete_index(self):19 self.filter_db.create_index("name")20 self.filter_db.create_index("active")21 self.filter_db.delete_index("name")22 self.assertEqual(self.filter_db.get_indices(), ["active"])23 self.filter_db.delete_index("active")24 self.assertEqual(self.filter_db.get_indices(), [])25 def test_add_field(self):26 self.setup_db_for_filter()27 self.filter_db.add_field('age', column_type='INTEGER')28 # Check the value of age field for record that existed29 # before the new field was adde30 record = self.filter_db(unique_id=4)[0]31 self.assertEqual(record["age"], None)32 # Check value of age field for new record with age value33 status = {"unique_id": 110, 'age': 10}34 self.filter_db.insert(**status)35 record = self.filter_db(unique_id=110)[0]36 self.assertEqual(record["age"], 10)37 # Check value of age field for new record with no age value38 status = {"unique_id": 111}39 self.filter_db.insert(**status)40 record = self.filter_db(unique_id=111)[0]41 self.assertEqual(record["age"], None)42 def test_add_field_with_default_value(self):43 self.setup_db_for_filter()44 self.filter_db.add_field('age', column_type='INTEGER', default=5)45 # Check the value of age field for record that existed46 # before the new field was adde47 record = self.filter_db(unique_id=4)[0]48 self.assertEqual(record["age"], 5)49 # Check value of age field for new record with age value50 status = {"unique_id": 110, 'age': 10}51 self.filter_db.insert(**status)52 record = self.filter_db(unique_id=110)[0]53 self.assertEqual(record["age"], 10)54 # Check value of age field for new record with no age value55 status = {"unique_id": 111}56 record_id = self.filter_db.insert(**status)57 record = self.filter_db[record_id]58 self.assertEqual(record["age"], 5)59 def test_insert(self):60 status = {"unique_id": 1}61 res = self.filter_db.insert(**status)62 # First database record id should be 063 self.assertEqual(res, self.first_record_id)64 self.assertEqual(len(self.filter_db), 1)65 status = {"unique_id": 2}66 res = self.filter_db.insert(**status)67 # Second database record id should be 168 self.assertEqual(res, self.first_record_id + 1)69 self.assertEqual(len(self.filter_db), 2)70 def test_insert_values_in_order(self):71 status = (1,)72 res = self.filter_db.insert(*status)73 # First database record id should be 074 self.assertEqual(res, self.first_record_id)75 self.assertEqual(len(self.filter_db), 1)76 status = (2, "name_value", False)77 res = self.filter_db.insert(*status)78 # Second database record id should be 179 self.assertEqual(res, self.first_record_id + 1)80 self.assertEqual(len(self.filter_db), 2)81 rec = self.filter_db[res]82 # Verify that the values inserted in order are correct83 self.assertEqual(rec["unique_id"], status[0])84 self.assertEqual(rec["name"], status[1])85 self.assertEqual(rec["active"], status[2])86 def test_update(self):87 self.setup_db_for_filter()88 record = self.filter_db(unique_id=4)[0]89 self.filter_db.update(record, name=record['name'].upper())90 self.assertEqual(self.filter_db[record["__id__"]]["name"], "TEST4")91 def test_select(self):92 self.setup_db_for_filter()93 record = self.filter_db(unique_id=1)[0]94 self.assertTrue(record['active'] == 1 or record['active'] is True)95 self.assertEqual(record["unique_id"], 1)96 self.assertEqual(record["name"], 'Test0')97 def test_select_unicode(self):98 status = {"unique_id": 1, "active": True, "name": u"éçùï"}99 self.filter_db.insert(**status)100 self.assertEqual(self.filter_db(name='foo'), [])101 self.assertEqual(self.filter_db(name=u'éçùï')[0]["unique_id"], 1)102 def test_iter(self):103 self.setup_db_for_filter()104 self.assertEqual(len([x for x in self.filter_db]), len(self.filter_db))105 records = self.filter_db()106 for r in records:107 self.assertEqual([x for x in self.filter_db if x['unique_id'] == r['unique_id']],108 self.filter_db(unique_id=r['unique_id']))109 self.assertEqual([x for x in self.filter_db if x['name'] == r['name']],110 self.filter_db(name=r['name']))111 def test_fetch(self):112 torrent_count = 10113 for i in range(torrent_count):114 status = {"unique_id": i}115 self.filter_db.insert(**status)116 for i in range(torrent_count):117 records = self.filter_db(unique_id=i)118 self.assertEqual(records[0]["unique_id"], i)119 def test_delete(self):120 status = {"unique_id": 1}121 self.filter_db.insert(**status)122 status = {"unique_id": 2}123 self.filter_db.insert(**status)124 records = self.filter_db(unique_id=1)125 deleted_count = self.filter_db.delete(records[0])126 self.assertEqual(1, deleted_count)127 records = self.filter_db(unique_id=1)128 self.assertEqual(records, [])129 # Number of entries left should be 1130 self.assertEqual(len(self.filter_db()), 1)131 records = self.filter_db(unique_id=2)132 deleted_count = self.filter_db.delete(records[0])133 self.assertEqual(len(self.filter_db()), 0)134 def test_del(self):135 status = {"unique_id": 1}136 rec = self.filter_db.insert(**status)137 del self.filter_db[rec]138 self.assertEqual(self.filter_db(name='non-existent'), [])139 self.assertEqual(len(self.filter_db), 0)140 def reset_status_values_for_filter(self):141 self.status = []142 self.status.append({"unique_id": 1, "active": True, "name": "Test0"})143 self.status.append({"unique_id": 2, "active": True, "name": "Test0"})144 self.status.append({"unique_id": 3, "active": True, "name": "test0"})145 self.status.append({"unique_id": 4, "active": True, "name": "Test4"})146 self.status.append({"unique_id": 5, "active": False, "name": "Test4"})147 self.status.append({"unique_id": 6, "active": False, "name": "Test6"})148 self.status.append({"unique_id": 7, "active": False, "name": "Test7"})149 def setup_db_for_filter(self):150 self.reset_status_values_for_filter()151 res = self.filter_db.insert(self.status)152 self.assertTrue(res is None or res == 7) # Depends on the database driver...153 def test_filter_len(self):154 self.setup_db_for_filter()155 f = self.filter_db.filter()156 self.assertEqual(len(f), len(self.status))157 def test_filter_equals(self):158 self.setup_db_for_filter()159 self.assertEqual(len((self.filter_db("active") == True)), 4) # noqa160 def test_filter_not_equals(self):161 self.setup_db_for_filter()162 self.assertEqual(len((self.filter_db("active") != True)), 3) # noqa163 def test_filter_in(self):164 """Test IN ( == with a list"""165 self.setup_db_for_filter()166 self.assertEqual(len(self.filter_db("name") == ["Test4", "Test7"]), 3)167 def test_filter_greater(self):168 self.setup_db_for_filter()169 self.assertEqual(len((self.filter_db("unique_id") > 4)), 3)170 def test_filter_greater_equals(self):171 self.setup_db_for_filter()172 self.assertEqual(len((self.filter_db("unique_id") >= 4)), 4)173 def test_filter_less(self):174 self.setup_db_for_filter()175 self.assertEqual(len((self.filter_db("unique_id") < 3)), 2)176 def test_filter_less_equals(self):177 self.setup_db_for_filter()178 self.assertEqual(len((self.filter_db("unique_id") <= 3)), 3)179 def test_filter_ilike(self):180 """Test text case sensitive"""181 self.setup_db_for_filter()182 self.assertEqual(len(self.filter_db("name").ilike("Test")), 6)183 self.assertEqual(len(self.filter_db("name").ilike("Test0")), 2)184 def test_filter_like(self):185 """Test text case insensitive"""186 self.setup_db_for_filter()187 self.assertEqual(len(self.filter_db("name").like("Test")), 7)188 self.assertEqual(len(self.filter_db("name").like("Test0")), 3)189 def test_filter_and(self):190 """Test AND"""191 self.setup_db_for_filter()192 f = (self.filter_db.filter() &193 (self.filter_db.filter(key="name") == "Test4"))194 self.assertEqual(str(f), "name = 'Test4'")195 f = ((self.filter_db.filter(key="name") == "Test4") &196 (self.filter_db.filter(key="active") == False)) # noqa197 self.assertEqual(str(f), "((active = 0) AND (name = 'Test4'))")198 self.assertEqual(len(f), 1)199 def test_filter_or(self):200 """Test OR"""201 self.setup_db_for_filter()202 f = (self.filter_db.filter() |203 (self.filter_db.filter(key="name") == "Test4"))204 self.assertEqual(str(f), "name = 'Test4'")205 f = ((self.filter_db.filter(key="name") == "Test4") |206 (self.filter_db.filter(key="active") == False)) # noqa207 self.assertEqual(str(f), "((active = 0) OR (name = 'Test4'))")208 self.assertEqual(len(f), 4)209 def test_len_with_filter(self):210 self.setup_db_for_filter()211 f = self.filter_db.filter()212 f |= (self.filter_db("active") == True) # noqa213 self.assertEquals(self.filter_db._len(f), 4)214 def test_len_with_filter_non_matching(self):215 self.setup_db_for_filter()216 f = self.filter_db.filter()217 f |= (self.filter_db("unique_id") == -1) # Will not match any entries218 self.assertEqual(self.filter_db._len(f), 0)219 def test_filter_get_unique_ids(self):220 self.setup_db_for_filter()221 ids = self.filter_db.get_unique_ids("name")222 self.assertEqual(ids, set(['Test0', 'Test6', 'Test4', 'Test7', 'test0']))223 def test_filter_get_unique_ids_with_filter(self):224 self.setup_db_for_filter()225 f = self.filter_db.filter()226 f |= (self.filter_db("active") == True) # noqa227 ids = self.filter_db.get_unique_ids("name", f)228 self.assertEquals(ids, set(['Test0', 'Test4', 'test0']))229 def test_filter_get_unique_ids_with_filter_non_matching(self):230 self.setup_db_for_filter()231 f = self.filter_db.filter() | (self.filter_db("unique_id") == -1) # Will not match any232 ids = self.filter_db.get_unique_ids("name", f)233 self.assertEqual(ids, set())234 def make_group_count_result(self, key, test_key=None, test_val=None):235 counts = {}236 for e in self.status:237 if test_key and e[test_key] != test_val:238 continue239 counts[e[key]] = counts.get(e[key], 0) + 1240 return counts241 def test_get_group_count(self):242 self.setup_db_for_filter()243 counts = self.make_group_count_result("name")244 result = self.filter_db.get_group_count("name")245 for name, count in result:246 self.assertEqual(count, counts[name])247 def test_get_group_count_with_filter(self):248 self.setup_db_for_filter()249 counts = self.make_group_count_result("name", test_key="active", test_val=True)250 f = self.filter_db.filter() | (self.filter_db("active") == True) # noqa251 result = self.filter_db.get_group_count("name", f)252 for name, count in result:253 self.assertEqual(count, counts[name])254 def test_get_group_count_with_filter_non_matching(self):255 self.setup_db_for_filter()256 counts = self.make_group_count_result("name", test_key="unique_id", test_val=-1)257 f = self.filter_db.filter() | (self.filter_db("unique_id") == -1)258 result = self.filter_db.get_group_count("name", f)259 for name, count in result:...

Full Screen

Full Screen

InanimateAgents.py

Source:InanimateAgents.py Github

copy

Full Screen

1from mesa import Agent2class Item(Agent):3 def __init__(self, unique_id, model):4 super().__init__(unique_id, model)5 def step(self):6 pass7class Desk(Item):8 def __init__(self, unique_id, model):9 super().__init__(unique_id, model)10class DeskInteractive(Item):11 """12 That's basically the chair now.13 """14 def __init__(self, unique_id, model):15 super().__init__(unique_id, model)16class HelpDesk(Item):17 def __init__(self, unique_id, model):18 super().__init__(unique_id, model)19class HelpdeskInteractiveForHelper(Item):20 def __init__(self, unique_id, model):21 super().__init__(unique_id, model)22class HelpdeskInteractiveForHelpee(Item):23 def __init__(self, unique_id, model):24 super().__init__(unique_id, model)25class Office(Item):26 def __init__(self, unique_id, model):27 super().__init__(unique_id, model)28class Shelf(Item):29 def __init__(self, unique_id, model):30 super().__init__(unique_id, model)31class ShelfInteractive(Item):32 def __init__(self, unique_id, model):33 super().__init__(unique_id, model)34class Exit(Item):35 def __init__(self, unique_id, model):36 super().__init__(unique_id, model)37class ExitA(Exit):38 def __init__(self, unique_id, model):39 super().__init__(unique_id, model)40class ExitB(Exit):41 def __init__(self, unique_id, model):42 super().__init__(unique_id, model)43class ExitC(Exit):44 def __init__(self, unique_id, model):45 super().__init__(unique_id, model)46class Wall(Item):47 def __init__(self, unique_id, model):48 super().__init__(unique_id, model)49class Obstacle(Item):50 def __init__(self, unique_id, model):51 super().__init__(unique_id, model)52class WalkableFloor(Item):53 # useful to note: can spawn people on these spaces54 def __init__(self, unique_id, model):55 super().__init__(unique_id, model)56class OutOfBounds(Item):57 def __init__(self, unique_id, model):58 super().__init__(unique_id, model)59class Alarm(Agent):60 def __init__(self, unique_id, model, timer=30):61 super().__init__(unique_id, model)62 self.is_activated = False63 self.starting_time = timer64 self.timer = timer65 self.model.schedule.add(self)66 def step(self):67 self.timer -= 168 if self.timer <= 0:69 self.is_activated = True...

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 avocado 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