Best Python code snippet using localstack_python
test_include.py
Source:test_include.py
...51 assert e.name == 'a'52 assert e.data == 'a(b)'53 def test_IncludeHandlesCircularRecursion(self):54 # detect circular recursion and create error message55 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{page2}}')56 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{page3}}')57 update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{page4}}')58 update_item(u'page4', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{page2}}')59 page1 = Item.create(u'page1')60 rendered = page1.content._render_data()61 # an error message will follow strong tag62 assert '<strong class="moin-error">' in rendered63 def test_Include_Read_Permission_Denied(self):64 # attempt to include an item that user cannot read65 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8', ACL: u'All:write,create,admin,destroy'}, u'no one can read')66 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'some text{{page1}}more text')67 page2 = Item.create(u'page2')68 rendered = page2.content._render_data()69 # an error message will follow p tag, similar to: Access Denied, transcluded content suppressed.70 assert '<div class="warning"><p>' in rendered71 def test_ExternalInclude(self):72 # external include73 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{http://moinmo.in}}')74 rendered = Item.create(u'page1').content._render_data()75 assert '<object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object>' in rendered76 # external include embedded within text (object is an inline tag)77 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{http://moinmo.in}} after')78 rendered = Item.create(u'page1').content._render_data()79 assert '<p>before <object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object> after</p>' in rendered80 # external include embedded within text italic and bold markup (object is an inline tag)81 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"before ''italic '''bold {{http://moinmo.in}} bold''' italic'' normal")82 rendered = Item.create(u'page1').content._render_data()83 assert '<p>before <em>italic <strong>bold <object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object> bold</strong> italic</em> normal</p>' in rendered84 def test_InlineInclude(self):85 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{page2}} after')86 # transclude single paragraph as inline87 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'Single line')88 rendered = Item.create(u'page1').content._render_data()89 assert '<p>before <span class="moin-transclusion" data-href="/page2">Single line</span> after</p>' in rendered90 # transclude multiple paragraphs as block91 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'Two\n\nParagraphs')92 rendered = Item.create(u'page1').content._render_data()93 assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><p>Two</p><p>Paragraphs</p></div><p> after</p></div>' in rendered94 # transclude single paragraph with internal markup as inline95 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"this text contains ''italic'' string")96 rendered = Item.create(u'page1').content._render_data()97 assert 'before <span class="moin-transclusion" data-href="/page2">this text contains <em>italic</em>' in rendered98 # transclude single paragraph as only content within a paragraph99 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'Content of page2 is\n\n{{page2}}')100 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Single Line")101 rendered = Item.create(u'page1').content._render_data()102 assert '<p>Content of page2 is</p><p><span class="moin-transclusion" data-href="/page2">Single Line</span></p>' in rendered103 # transclude single row table within a paragraph, block element forces paragraph to be split into 2 parts104 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{page2}} after')105 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"|| table || cell ||")106 rendered = Item.create(u'page1').content._render_data()107 assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><table' in rendered108 assert '</table></div><p> after</p>' in rendered109 assert rendered.count('<table>') == 1110 # transclude two row table within a paragraph, block element forces paragraph to be split into 2 parts111 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{page2}} after')112 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"|| this || has ||\n|| two || rows ||")113 rendered = Item.create(u'page1').content._render_data()114 # inclusion of block item within a paragraph results in a before and after p115 assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><table' in rendered116 assert '</table></div><p> after</p>' in rendered117 assert rendered.count('<table>') == 1118 # transclude nonexistent item119 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{nonexistent}} after')120 rendered = Item.create(u'page1').content._render_data()121 assert '<p>before <span class="moin-transclusion" data-href="/nonexistent"><a href="/+modify/nonexistent">' in rendered122 assert '</a></span> after</p>' in rendered123 # transclude empty item124 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text {{page2}} text')125 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"")126 rendered = Item.create(u'page1').content._render_data()127 assert '<p>text <span class="moin-transclusion" data-href="/page2"></span> text</p>' in rendered128 def test_InlineIncludeCreole(self):129 # transclude single paragraph as inline using creole parser130 update_item(u'creole', {CONTENTTYPE: u'text/x.moin.creole;charset=utf-8'}, u'creole item')131 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.creole;charset=utf-8'}, u'before {{creole}} after')132 rendered = Item.create(u'page1').content._render_data()133 assert '<p>before <span class="moin-transclusion" data-href="/creole">creole item</span> after</p>' in rendered134 def test_InlineIncludeWithinMarkup(self):135 # transclude single line item within italic and bold markup136 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Normal ''italic '''bold {{page2}} bold''' italic'' normal")137 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Single Line")138 rendered = Item.create(u'page1').content._render_data()139 assert '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/page2">Single Line</span> bold</strong> italic</em> normal</p>' in rendered140 # transclude double line item within italic and bold markup141 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Normal ''italic '''bold {{page2}} bold''' italic'' normal")142 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Double\n\nLine")143 rendered = Item.create(u'page1').content._render_data()144 assert '<p>Normal <em>italic <strong>bold </strong></em></p><div class="moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div><p><em><strong> bold</strong> italic</em> normal</p>' in rendered145 # transclude single line item within comment146 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"comment /* before {{page2}} after */")147 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Single Line")148 rendered = Item.create(u'page1').content._render_data()149 assert '<p>comment <span class="comment">before <span class="moin-transclusion" data-href="/page2">Single Line</span> after</span></p>' in rendered150 # transclude double line item within comment151 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"comment /* before {{page2}} after */")152 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Double\n\nLine")153 rendered = Item.create(u'page1').content._render_data()154 assert '<p>comment <span class="comment">before </span></p><div class="comment moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div><p><span class="comment"> after</span></p>' in rendered155 def test_InlineIncludeImage(self):156 # the 3rd parameter, u'', should be a binary string defining a png image, but it is not needed for this simple test157 update_item(u'logo.png', {CONTENTTYPE: u'image/png'}, u'')158 # simple transclusion159 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{logo.png}}')160 rendered = Item.create(u'page1').content._render_data()161 assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered162 assert '/logo.png" /></span></p>' in rendered163 # simple transclusion with alt text and width164 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{logo.png|my alt text|width="100"}}')165 rendered = Item.create(u'page1').content._render_data()166 assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="my alt text" src=' in rendered167 assert 'logo.png" width="100" /></span></p>' in rendered168 # within paragraph169 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text {{logo.png}} text')170 rendered = Item.create(u'page1').content._render_data()171 assert '<p>text <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered172 assert '/logo.png" /></span> text</p>' in rendered173 # within markup174 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Normal ''italic '''bold {{logo.png}} bold''' italic'' normal")175 rendered = Item.create(u'page1').content._render_data()176 assert '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered177 assert '/logo.png" /></span> bold</strong> italic</em> normal</p>' in rendered178 # multiple transclusions179 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{logo.png}}{{logo.png}}')180 rendered = Item.create(u'page1').content._render_data()181 assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered182 assert '/logo.png" /></span><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered183 # check for old bug184 assert '<p />' not in rendered185 assert '<p></p>' not in rendered186 def test_IncludeAsLinkAlternate(self):187 # the 3rd parameter, u'', should be a binary string defining a png image, but it is not needed for this simple test188 update_item(u'logo.png', {CONTENTTYPE: u'image/png'}, u'')189 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Single Line")190 # image as link alternate191 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"text [[page2|{{logo.png}}]] text")192 rendered = Item.create(u'page1').content._render_data()193 assert '<p>text <a href="/page2"><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered194 assert '/logo.png" /></span></a> text</p>' in rendered195 # link alternate with image embedded in markup196 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"text [[page2|plain '''bold {{logo.png}} bold''' plain]] text")197 rendered = Item.create(u'page1').content._render_data()198 assert '<p>text <a href="/page2">plain <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered199 assert '/logo.png" /></span> bold</strong> plain</a> text</p>' in rendered200 # nonexistent image used in link alternate201 # XXX html validation errora: A inside A - the image alternate turns into an A-tag to create the non-existant image. Error is easily seen.202 # IE9, Firefox, Chrome, Safari, and Opera display this OK; the only usable hyperlink is to create the missing image.203 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"text [[page2|{{logoxxx.png}}]] text")204 rendered = Item.create(u'page1').content._render_data()205 assert '<p>text <a href="/page2"><span class="moin-transclusion" data-href="/logoxxx.png"><a href="/+modify/logoxxx.png">' in rendered206 assert '</a></span></a> text</p>' in rendered207 # image used as alternate to nonexistent page208 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"text [[page2xxx|{{logo.png}}]] text")209 rendered = Item.create(u'page1').content._render_data()210 assert '<p>text <a class="moin-nonexistent" href="/page2xxx"><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered211 assert '/logo.png" /></span></a> text</p>' in rendered212 # transclude block elem as link alternate to nonexistent page213 # XXX html validation errors, block element inside A.214 # IE9, Firefox, Chrome, Safari, and Opera display this OK; the hyperlink is the entire div enclosing the block elem215 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text [[MyPage|{{page2}}]] text')216 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Double\n\nLine")217 rendered = Item.create(u'page1').content._render_data()218 assert '<p>text <a class="moin-nonexistent" href="/MyPage"><div class="moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div></a> text</p>' in rendered219 # transclude empty item as link alternate to nonexistent page220 # hyperlink will be empty span and invisible221 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text [[MyPage|{{page2}}]] text')222 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"")223 rendered = Item.create(u'page1').content._render_data()224 assert '<p>text <a class="moin-nonexistent" href="/MyPage"><span class="moin-transclusion" data-href="/page2"></span></a> text</p>' in rendered225 # transclude external page as link alternate to nonexistent page226 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text [[MyPage|{{http://moinmo.in}}]] text')227 rendered = Item.create(u'page1').content._render_data()...
database.py
Source:database.py
1# To initialise this, run the function create_table() first, and then run the regular code.234import sqlite356import time7import serial89# ser = serial.Serial('COM7', 9600)10# ser.flush()1112try:13 ser = serial.Serial('COM7', 9600) #check the port number for your device14 ser.flush()15except:16 ser=serial.Serial()171819# Item_Id, Item_Name, Compartment, X_Pos, Height, Stock2021ERROR_TUPLE = (-1, -1, -1, -1, -1, -1)222324def create_table():25 conn = sqlite3.connect('sqlite_test.db')26 cursor = conn.cursor()2728 cursor.execute("DROP TABLE IF EXISTS TEST1")2930 sql = '''CREATE TABLE TEST1(31 Item_ID INT NOT NULL,32 Item_Name CHAR(1000),33 Compartment CHAR(100),34 X_Pos INT,35 Height INT,36 Stock INT37 )'''38 cursor.execute(sql)39 print("Table created successfully........")4041 conn.commit()4243 conn.close()444546def get_all_locations_of_item(item_id):47 conn = sqlite3.connect('sqlite_test.db')48 cursor = conn.cursor()4950 get_data = '''SELECT Item_ID, Item_Name, Compartment, X_Pos, Height, Stock51 FROM TEST152 WHERE Item_ID= '''53 get_data = get_data + str(item_id)5455 cursor.execute(get_data)56 output = cursor.fetchall()5758 conn.commit()5960 conn.close()6162 return output6364def get_list_of_items():65 conn = sqlite3.connect('sqlite_test.db')66 cursor = conn.cursor()6768 get_data = '''SELECT Item_ID, Item_Name69 FROM TEST1'''7071 cursor.execute(get_data)72 output=cursor.fetchall()7374 conn.commit()7576 conn.close()7778 return output798081# only gets non-zero stock item82def get_item(item_id):83 conn = sqlite3.connect('sqlite_test.db')84 cursor = conn.cursor()8586 get_data = '''SELECT Item_ID, Item_Name, Compartment, X_Pos, Height, Stock87 FROM TEST188 WHERE Item_ID= '''89 get_data = get_data + str(item_id)90 get_data = get_data + " AND Stock > "91 get_data = get_data + str(0)9293 cursor.execute(get_data)94 output = cursor.fetchall()9596 conn.commit()9798 conn.close()99100 if len(output) > 0:101 return output[0] # optimise output102 else:103 return ERROR_TUPLE104105106def drop_item(item_id, item_name, compartment, x_pos, height, stock):107 if stock > 0:108 conn = sqlite3.connect('sqlite_test.db')109 cursor = conn.cursor()110111 # motor function to drop item112 if item_id==1:113 time.sleep(1)114 try:115 ser.write(b'A')116 except:117 print("Port is not open. If it was, item would drop")118119 else:120 time.sleep(1)121 try:122 ser.write(b'B')123 except:124 print("Port is not open. If it was, the item would drop")125126 update_item = '''UPDATE TEST1127 SET Stock='''128 update_item = update_item + str(stock - 1)129 update_item = update_item + '''130 WHERE Item_ID= '''131 update_item = update_item + str(item_id)132 update_item = update_item + ''' AND Item_Name= "'''133 update_item = update_item + item_name134 update_item = update_item + '''" AND Compartment= "'''135 update_item = update_item + compartment136 update_item = update_item + '''" AND X_Pos= '''137 update_item = update_item + str(x_pos)138 update_item = update_item + ''' AND Height= '''139 update_item = update_item + str(height)140141 cursor.execute(update_item)142143 conn.commit()144145 conn.close()146147148def fetch_item(tup):149 if tup == ERROR_TUPLE:150 print("Stock of item is over, or item does not exist")151152 else:153154 item_id = tup[0]155 item_name = tup[1]156 compartment = tup[2]157 x_pos = tup[3]158 height = tup[4]159 stock = tup[5]160161 drop_item(item_id, item_name, compartment, x_pos, height, stock)162163164def delete_item(item_id, item_name, compartment, x_pos, height, stock):165 conn = sqlite3.connect('sqlite_test.db')166 cursor = conn.cursor()167168 delete_item = '''DELETE FROM TEST1 WHERE Item_ID= '''169 delete_item = delete_item + str(item_id)170 delete_item = delete_item + ''' AND Item_Name= "'''171 delete_item = delete_item + item_name172 delete_item = delete_item + '''" AND Compartment= "'''173 delete_item = delete_item + compartment174 delete_item = delete_item + '''" AND X_Pos= '''175 delete_item = delete_item + str(x_pos)176 delete_item = delete_item + ''' AND Height= '''177 delete_item = delete_item + str(height)178 delete_item = delete_item + ''' AND Stock= '''179 delete_item = delete_item + str(stock)180181 cursor.execute(delete_item)182183 conn.commit()184185 conn.close()186187188def add_new_item(item_id, item_name, compartment, x_pos, height, stock):189 conn = sqlite3.connect('sqlite_test.db')190 cursor = conn.cursor()191192 search_for_item_occupied = '''SELECT * FROM TEST1 WHERE Compartment= "'''193 search_for_item_occupied = search_for_item_occupied + str(compartment)194 search_for_item_occupied = search_for_item_occupied + '''" AND X_Pos= '''195 search_for_item_occupied = search_for_item_occupied + str(x_pos)196 search_for_item_occupied = search_for_item_occupied + ''' AND Height= '''197 search_for_item_occupied = search_for_item_occupied + str(height)198199 cursor.execute(search_for_item_occupied)200201 output = cursor.fetchall()202203 if len(output) > 0:204 print("Already Occupied")205 else:206 insert_item = '''INSERT INTO TEST1 (Item_ID,Item_Name,Compartment,X_Pos,Height,Stock)207 VALUES ('''208209 insert_item = insert_item + str(item_id) + ", '"210 insert_item = insert_item + item_name + "', "211 insert_item = insert_item + "'" + compartment + "', "212 insert_item = insert_item + str(x_pos) + ", "213 insert_item = insert_item + str(height) + ", "214 insert_item = insert_item + str(stock) + " )"215216 cursor.execute(insert_item)217218 conn.commit()219220 conn.close()221222223def add_stock_to_item(item_id, item_name, compartment, x_pos, height, stock, added_stock):224 conn = sqlite3.connect('sqlite_test.db')225 cursor = conn.cursor()226227 update_item = '''UPDATE TEST1228 SET Stock='''229 update_item = update_item + str(stock + added_stock)230 update_item = update_item + '''231 WHERE Item_ID= '''232 update_item = update_item + str(item_id)233 update_item = update_item + ''' AND Item_Name= "'''234 update_item = update_item + item_name235 update_item = update_item + '''" AND Compartment= "'''236 update_item = update_item + compartment237 update_item = update_item + '''" AND X_Pos= '''238 update_item = update_item + str(x_pos)239 update_item = update_item + ''' AND Height= '''240 update_item = update_item + str(height)241242 cursor.execute(update_item)243244 conn.commit()245246 conn.close()247248249def set_stock_for_item(item_id, item_name, compartment, x_pos, height, stock, new_stock):250 conn = sqlite3.connect('sqlite_test.db')251 cursor = conn.cursor()252253 update_item = '''UPDATE TEST1254 SET Stock='''255 update_item = update_item + str(new_stock)256 update_item = update_item + '''257 WHERE Item_ID= '''258 update_item = update_item + str(item_id)259 update_item = update_item + ''' AND Item_Name= "'''260 update_item = update_item + item_name261 update_item = update_item + '''" AND Compartment= "'''262 update_item = update_item + compartment263 update_item = update_item + '''" AND X_Pos= '''264 update_item = update_item + str(x_pos)265 update_item = update_item + ''' AND Height= '''266 update_item = update_item + str(height)267268 cursor.execute(update_item)269270 conn.commit()271272 conn.close()273274275def clear_table():276 conn = sqlite3.connect('sqlite_test.db')277 cursor = conn.cursor()278279 clear_table = "DELETE FROM TEST1"280281 cursor.execute(clear_table)282283 conn.commit()284285 conn.close()286287288def print_table():289 conn = sqlite3.connect('sqlite_test.db')290 cursor = conn.cursor()291292 get_table = "SELECT * FROM TEST1"293294 cursor.execute(get_table)295296 output = cursor.fetchall()297298 print("Item_ID, Item_Name, Compartment, X_Pos, Height, Stock")299 for row in output:300 print(row)301302303def test_add_table():304 clear_table()305 add_new_item(1, "apple", "A", 1, 1, 2)306 add_new_item(1, "apple", "A", 1, 2, 2)307 add_new_item(1, "apple", "A", 2, 1, 1)308 add_new_item(1, "apple", "A", 2, 2, 1)309 add_new_item(2, "banana", "B", 1, 1, 2)310 add_new_item(2, "banana", "B", 1, 2, 2)311 add_new_item(3, "orange", "B", 2, 1, 3)
...
experiment_db_client.py
Source:experiment_db_client.py
...31 """32 Updates ExperimentDb record for experiment_id with new training_workflow_metadata,33 while validating, next_model_to_train_id is as expected in the old record.34 """35 self.table_session.update_item(36 Key={"experiment_id": experiment_id},37 UpdateExpression=f"SET training_workflow_metadata = :new_val",38 ConditionExpression="training_workflow_metadata.next_model_to_train_id = :exp_model_id",39 ExpressionAttributeValues={40 ":new_val": training_workflow_metadata,41 ":exp_model_id": expected_current_next_model_to_train_id,42 },43 )44 def update_experiment_training_state(self, experiment_id, training_state):45 self.table_session.update_item(46 Key={"experiment_id": experiment_id},47 UpdateExpression=f"SET training_workflow_metadata.training_state = :val",48 ExpressionAttributeValues={":val": training_state},49 )50 def update_experiment_last_trained_model_id(self, experiment_id, last_trained_model_id):51 self.table_session.update_item(52 Key={"experiment_id": experiment_id},53 UpdateExpression=f"SET training_workflow_metadata.last_trained_model_id = :val",54 ExpressionAttributeValues={":val": last_trained_model_id},55 )56 def update_experiment_next_model_to_train_id(self, experiment_id, next_model_to_train_id):57 self.table_session.update_item(58 Key={"experiment_id": experiment_id},59 UpdateExpression=f"SET training_workflow_metadata.next_model_to_train_id = :val",60 ExpressionAttributeValues={":val": next_model_to_train_id},61 )62 #### Update states for hosting workflow63 def update_experiment_hosting_state(self, experiment_id, hosting_state):64 self.table_session.update_item(65 Key={"experiment_id": experiment_id},66 UpdateExpression=f"SET hosting_workflow_metadata.hosting_state = :val",67 ExpressionAttributeValues={":val": hosting_state},68 )69 def update_experiment_last_hosted_model_id(self, experiment_id, last_hosted_model_id):70 self.table_session.update_item(71 Key={"experiment_id": experiment_id},72 UpdateExpression=f"SET hosting_workflow_metadata.last_hosted_model_id = :val",73 ExpressionAttributeValues={":val": last_hosted_model_id},74 )75 def update_experiment_next_model_to_host_id(self, experiment_id, next_model_to_host_id):76 self.table_session.update_item(77 Key={"experiment_id": experiment_id},78 UpdateExpression=f"SET hosting_workflow_metadata.next_model_to_host_id = :val",79 ExpressionAttributeValues={":val": next_model_to_host_id},80 )81 def update_experiment_hosting_endpoint(self, experiment_id, hosting_endpoint):82 self.table_session.update_item(83 Key={"experiment_id": experiment_id},84 UpdateExpression=f"SET hosting_workflow_metadata.hosting_endpoint = :val",85 ExpressionAttributeValues={":val": hosting_endpoint},86 )87 #### Update states for joining workflow88 def update_experiment_joining_state(self, experiment_id, joining_state):89 self.table_session.update_item(90 Key={"experiment_id": experiment_id},91 UpdateExpression=f"SET joining_workflow_metadata.joining_state = :val",92 ExpressionAttributeValues={":val": joining_state},93 )94 def update_experiment_last_joined_job_id(self, experiment_id, last_joined_job_id):95 self.table_session.update_item(96 Key={"experiment_id": experiment_id},97 UpdateExpression=f"SET joining_workflow_metadata.last_joined_job_id = :val",98 ExpressionAttributeValues={":val": last_joined_job_id},99 )100 def update_experiment_next_join_job_id(self, experiment_id, next_join_job_id):101 self.table_session.update_item(102 Key={"experiment_id": experiment_id},103 UpdateExpression=f"SET joining_workflow_metadata.next_join_job_id = :val",104 ExpressionAttributeValues={":val": next_join_job_id},105 )106 #### Update states for evaluation workflow107 def update_experiment_evaluation_state(self, experiment_id, evaluation_state):108 self.table_session.update_item(109 Key={"experiment_id": experiment_id},110 UpdateExpression=f"SET evaluation_workflow_metadata.evaluation_state = :val",111 ExpressionAttributeValues={":val": evaluation_state},112 )113 def update_experiment_last_evaluation_job_id(self, experiment_id, last_evaluation_job_id):114 self.table_session.update_item(115 Key={"experiment_id": experiment_id},116 UpdateExpression=f"SET evaluation_workflow_metadata.last_evaluation_job_id = :val",117 ExpressionAttributeValues={":val": last_evaluation_job_id},118 )119 def update_experiment_next_evaluation_job_id(self, experiment_id, next_evaluation_job_id):120 self.table_session.update_item(121 Key={"experiment_id": experiment_id},122 UpdateExpression=f"SET evaluation_workflow_metadata.next_evaluation_job_id = :val",123 ExpressionAttributeValues={":val": next_evaluation_job_id},...
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!!