How to use mark_finished method in Slash

Best Python code snippet using slash

test_order_book2.py

Source:test_order_book2.py Github

copy

Full Screen

...38 @classmethod39 def setUpClass(cls):40 with patch('builtins.input', side_effect=["0"]):41 cls.module = load_module(exercise, 'en')42 def test_1_mark_finished(self):43 reload_module(self.module)44 from src.order_book import OrderBook, Task45 code = """46t = OrderBook()47t.add_order("program web store", "Andy", 10)48t.mark_finished(1)49"""50 t = OrderBook()51 t.add_order("program web store", "Andy", 10)52 til = t.all_orders()53 id = til[0].id54 code += f"\n"55 56 try:57 t.mark_finished(id)58 except Exception as e:59 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method mark_finished(self, id: int) defined?')60 61 code = """62t = OrderBook()63t.add_order("program web store", "Andy", 10)64t.mark_finished(1)65t.all_orders()66"""67 val = t.all_orders()68 t1 = ("program web store", "Andy", 10, True) 69 all_ok = ook(val, [t1])70 expected = s([tt(t1)])71 self.assertTrue(all_ok, f"When executing the following code {code}\nmethod should return a list containing following tasks\n{expected}\nnow return was\n{ss(val)}")72 code = """73t = OrderBook()74t.add_order("program web store", "Andy", 10)75t.add_order("program mobile gane", "Eric", 5)76t.mark_finished(1)77t.mark_finished(2)78t.all_orders()79"""80 t.add_order("program mobile gane", "Eric", 5)81 til = t.all_orders()82 id1 = til[0].id83 id2 = til[1].id84 try:85 t.mark_finished(id1)86 t.mark_finished(id2)87 except Exception as e:88 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method mark_finished(self, id: int) defined?')89 90 val = t.all_orders()91 t2 = ("program mobile gane", "Eric", 5, True)92 all_ok = ook(val, [t1, t2])93 expected = s([tt(t1), tt(t2)])94 self.assertTrue(all_ok, f"When executing the following code {code}\nmethod should return a list containing following tasks\n{expected}\nnow return was\n{ss(val)}")95 def test_2_mark_finished_exception(self):96 reload_module(self.module)97 from src.order_book import OrderBook, Task98 code = """99t = OrderBook()100t.add_order("program web store", "Andy", 10)101t.mark_finished(999)102"""103 t = OrderBook()104 t.add_order("program web store", "Andy", 10)105 til = t.all_orders()106 id = til[0].id + 1107 code += f"\n"108 109 ok = False110 try:111 t.mark_finished(id)112 except ValueError:113 ok = True114 except Exception as e:115 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method mark_finished(self, id: int) defined?')116 self.assertTrue(ok, f'Executing the following code {code}should raise ValueError exception')117 def test_3_unfinished(self):118 from src.order_book import OrderBook, Task119 code = """120t = OrderBook()121t.unfinished_orders()122"""123 t = OrderBook()124 try:125 t.unfinished_orders()126 except Exception as e:127 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method unfinished_orders(self) defined?')128 code = """129t = OrderBook()130t.add_order("program web store", "Andy", 10)131t.unfinished_orders()132"""133 t = OrderBook()134 t.add_order("program web store", "Andy", 10)135 try:136 val = t.unfinished_orders()137 except Exception as e:138 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method unfinished_orders(self) defined?')139 taip = str(type(val)).replace("<class '","").replace("'>","")140 self.assertTrue(type(val) == type([]), f"When executing the following code{code}type of return value should be list, now it is of type {taip}")141 expected = 1142 self.assertTrue(len(val)==expected, f"When executing the following code{code}\nmethod should return a list, which length is {expected}, length of list was {len(val)}")143 144 ttt = Task("code hello world", "Eric", 3)145 taip = str(type(val[0])).replace("<class '","").replace("'>","")146 self.assertTrue(type(val[0]) == type(ttt), f"When executing the following code {code}type of first item in list returned should be Task, now it is of type {taip}")147 expected = 1148 self.assertTrue(len(val)==expected, f"When executing the following code{code}\nmethod should return a list, which length is {expected}, length of list was {len(val)}")149 t1 = ("program web store", "Andy", 10, False) 150 all_ok = ook(val, [t1])151 expected = s([tt(t1)])152 self.assertTrue(all_ok, f"When executing the following code {code}\nmethod should return a list containing following tasks\n{expected}\nnow return was\n{ss(val)}")153 code = """154t = OrderBook()155t.add_order("program web store", "Andy", 10)156t.add_order("program mobile gane", "Eric", 5)157t.add_order("code better facebook", "Jonas", 5000)158t.unfinished_orders()159"""160 t.add_order("program mobile gane", "Eric", 5)161 t.add_order("code better facebook", "Jonas", 5000)162 t2 = ("program mobile gane", "Eric", 5, False)163 t3 = ("code better facebook", "Jonas", 5000, False)164 try:165 val = t.unfinished_orders()166 except Exception as e:167 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method unfinished_orders(self) defined?')168 expected = 3169 self.assertTrue(len(val)==expected, f"When executing the following code{code}\nmethod should return a list, which length is {expected}, length of list was {len(val)}")170 all_ok = ook(val, [t1, t2, t3])171 expected = s([tt(t1), tt(t2), tt(t3)])172 self.assertTrue(all_ok, f"When executing the following code {code}\nmethod should return a list containing following tasks\n{expected}\nnow return was\n{ss(val)}")173 code = """174t = OrderBook()175t.add_order("program web store", "Andy", 10)176t.add_order("program mobile gane", "Eric", 5)177t.add_order("code better facebook", "Jonas", 5000)178t.mark_finished(1)179t.mark_finished(2)180t.unfinished_orders()181"""182 til = t.all_orders()183 id1 = til[0].id184 id2 = til[1].id185 try:186 t.mark_finished(id1)187 t.mark_finished(id2)188 except Exception as e:189 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method mark_finished(self, id: int) defined?')190 191 try:192 val = t.unfinished_orders()193 except Exception as e:194 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method unfinished_orders(self) defined?')195 expected = 1196 self.assertTrue(len(val)==expected, f"When executing the following code{code}\nmethod should return a list, which length is {expected}, length of list was {len(val)}")197 all_ok = ook(val, [t3])198 expected = s([tt(t3)])199 self.assertTrue(all_ok, f"When executing the following code {code}\nmethod should return a list containing following tasks\n{expected}\nnow return was\n{ss(val)}")200 def test_4_finished(self):201 reload_module(self.module)202 from src.order_book import OrderBook, Task203 code = """204t = OrderBook()205t.finished_orders()206"""207 t = OrderBook()208 try:209 t.finished_orders()210 except Exception as e:211 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method finished_orders(self) defined?')212 code = """213t = OrderBook()214t.add_order("program web store", "Andy", 10)215t.mark_finished(1)216t.finished_orders()217"""218 t = OrderBook()219 t.add_order("program web store", "Andy", 10)220 til = t.all_orders()221 id1 = til[0].id222 try:223 t.mark_finished(id1)224 except Exception as e:225 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method mark_finished(self, id: int) defined?')226 227 try:228 val = t.finished_orders()229 except Exception as e:230 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method unfinished_orders(self) defined?')231 taip = str(type(val)).replace("<class '","").replace("'>","")232 self.assertTrue(type(val) == type([]), f"When executing the following code{code}type of return value should be list, now it is of type {taip}")233 expected = 1234 self.assertTrue(len(val)==expected, f"When executing the following code{code}\nmethod should return a list, which length is {expected}, length of list was {len(val)}")235 236 ttt = Task("code hello world", "Eric", 3)237 taip = str(type(val[0])).replace("<class '","").replace("'>","")238 self.assertTrue(type(val[0]) == type(ttt), f"When executing the following code {code}type of first item in list returned should be Task, now it is of type {taip}")239 expected = 1240 self.assertTrue(len(val)==expected, f"When executing the following code{code}\nmethod should return a list, which length is {expected}, length of list was {len(val)}")241 t1 = ("program web store", "Andy", 10, True) 242 all_ok = ook(val, [t1])243 expected = s([tt(t1)])244 self.assertTrue(all_ok, f"When executing the following code {code}\nmethod should return a list containing following tasks\n{expected}\nnow return was\n{ss(val)}")245 code = """246t = OrderBook()247t.add_order("program web store", "Andy", 10)248t.add_order("program mobile gane", "Eric", 5)249t.add_order("code better facebook", "Jonas", 5000)250t.mark_finished(1)251t.mark_finished(2)252t.finished_orders()253"""254 t = OrderBook()255 t.add_order("program web store", "Andy", 10)256 t.add_order("program mobile gane", "Eric", 5)257 t.add_order("code better facebook", "Jonas", 5000)258 til = t.all_orders()259 id1 = til[0].id260 id2 = til[1].id261 try:262 t.mark_finished(id1)263 t.mark_finished(id2)264 except Exception as e:265 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method mark_finished(self, id: int) defined?')266 try:267 val = t.finished_orders()268 except Exception as e:269 self.fail(f'Executing the following code {code}threw an error\n{e}\nIs method unfinished_orders(self) defined?')270 expected = 2271 self.assertTrue(len(val)==expected, f"When executing the following code{code}\nmethod should return a list, which length is {expected}, length of list was {len(val)}")272 273 t1 = ("program web store", "Andy", 10, True) 274 t2 = ("program mobile gane", "Eric", 5, True) 275 all_ok = ook(val, [t1, t2])276 expected = s([tt(t1), tt(t1)])277 self.assertTrue(all_ok, f"When executing the following code {code}\nmethod should return a list containing following tasks\n{expected}\nnow return was\n{ss(val)}")278if __name__ == '__main__':279 unittest.main()

Full Screen

Full Screen

ll_dag_test.py

Source:ll_dag_test.py Github

copy

Full Screen

...17def test_finish_item():18 g = StringGraph(nodes=['foo', 'bar'], edges=[19 ('foo', 'bar'),20 ])21 g.mark_finished('foo')22 assert set(g.ready_nodes) == {'bar'}23def test_finish_item_two_chain():24 g = StringGraph(nodes={'foo', 'bar', 'baz'}, edges=[25 ('foo', 'bar'),26 ('bar', 'baz'),27 ])28 g.mark_finished('foo')29 assert set(g.ready_nodes) == {'bar'}30 g.mark_finished('bar')31 assert set(g.ready_nodes) == {'baz'}32 g.mark_finished('baz')33 assert set(g.ready_nodes) == set()34def test_finish_item_multi_inputs():35 g = StringGraph(nodes=('foo', 'bar', 'baz'), edges=[36 ('foo', 'baz'),37 ('bar', 'baz'),38 ])39 assert set(g.ready_nodes) == {'foo', 'bar'}40 g.mark_finished('foo')41 assert set(g.ready_nodes) == {'bar'}42 g.mark_finished('bar')43 assert set(g.ready_nodes) == {'baz'}44def test_finish_item_multi_outputs():45 g = StringGraph(nodes=('foo', 'bar', 'baz'), edges=[46 ('foo', 'bar'),47 ('foo', 'baz'),48 ])49 g.mark_finished('foo')50 assert set(g.ready_nodes) == {'bar', 'baz'}51def test_finish_item_cross():52 g = StringGraph(nodes=('foo', 'bar', 'baz', 'quux'),53 edges=[54 ('foo', 'bar'),55 ('foo', 'baz'),56 ('quux', 'bar'),57 ('quux', 'baz'),58 ])59 assert set(g.ready_nodes) == {'foo', 'quux'}60 g.mark_finished('foo')61 assert set(g.ready_nodes) == {'quux'}62 g.mark_finished('quux')63 assert set(g.ready_nodes) == {'bar', 'baz'}64def test_detect_cycles():65 g = StringGraph(nodes=('foo', 'bar', 'baz', 'quux'), edges=[66 ('foo', 'bar'),67 ('foo', 'baz'),68 ('baz', 'quux'),69 ])70 with pytest.raises(ll_dag.CycleError, match="['quux', 'baz', 'quux']"):71 g.add(edges=[('quux', 'baz')])72 with pytest.raises(ll_dag.CycleError, match="['quux', 'baz', 'foo', 'quux']"):73 g.add(edges=[('quux', 'foo')])74 g.add(edges=[('quux', 'bar')])75def test_detect_cycles_2():76 g = StringGraph(nodes=['foo', 'bar', 'baz'])77 g.add(edges=[78 ('foo', 'bar'),79 ('bar', 'baz'),80 ])81 with pytest.raises(ll_dag.CycleError):82 g.add(edges=[('baz', 'foo')])83 with pytest.raises(ll_dag.CycleError):84 g.add(edges=[('bar', 'foo')])85def test_detect_not_cycle():86 g = StringGraph(nodes=['foo', 'bar', 'baz', 'quux'], edges=[87 ('foo', 'bar'),88 ('baz', 'quux'),89 ])90 g.add(edges=[('bar', 'baz')])91def test_self_dep():92 g = StringGraph()93 with pytest.raises(ll_dag.CycleError, match="['foo', 'foo']"):94 g.add(edges=[('foo', 'foo')])95def test_add_edge_on_finished_error():96 g = StringGraph(nodes=['foo', 'bar'], edges=[('foo', 'bar')])97 assert set(g.ready_nodes) == {'foo'}98 g.mark_finished('foo')99 g.add(nodes=['baz'])100 assert set(g.ready_nodes) == {'bar', 'baz'}101 with pytest.raises(ll_dag.GraphStateError, match='foo'):102 g.add(edges=[('baz', 'foo')])103def test_add_dup_edge_error():104 g = StringGraph(nodes=['foo', 'bar'])105 g.add(edges=[('foo', 'bar')])106 assert set(g.ready_nodes) == {'foo'}107 with pytest.raises(ll_dag.DuplicateEdgeError, match="from_='foo', to='bar'"):108 g.add(edges=[('foo', 'bar')])109def test_add_dup_node_error():110 g = StringGraph(nodes=['foo'])111 with pytest.raises(ll_dag.DuplicateNodeError, match='foo'):112 g.add(nodes=['foo'])113def test_missing_node_error():114 g = StringGraph(nodes=['foo', 'bar'])115 with pytest.raises(ll_dag.MissingNodeError, match='quux'):116 g.add(edges=[('quux', 'bar')])117def test_random_large_graph():118 import random119 items: list[str] = ['foo', 'bar', 'baz']120 g = StringGraph(nodes=items)121 count = 1000122 for v in range(count):123 g.add(nodes=[str(v)])124 items.append(str(v))125 for _ in range(count):126 first = random.randrange(0, len(items) - 4)127 second = random.randrange(first + 1, len(items) - 1)128 try:129 g.add(edges=[(items[first], items[second])])130 except ll_dag.DuplicateEdgeError:131 pass132def test_restore():133 g = StringGraph()134 assert set(g.ready_nodes) == set()135 with pytest.raises(ll_dag.DuplicateNodeError):136 g.add(nodes=['foo', 'bar', 'bar', 'baz'])137 assert set(g.ready_nodes) == set()138 assert list(g.all_nodes) == []139 g.add(nodes=['foo', 'bar', 'baz'], edges=[('foo', 'bar'), ('bar', 'baz')])140 assert set(g.ready_nodes) == {'foo'}141 with pytest.raises(ll_dag.CycleError):142 g.add(edges=[('baz', 'foo')])143 assert set(g.ready_nodes) == {'foo'}144def test_copy():145 g = StringGraph(nodes=['foo', 'baz', 'bar'], edges=[('foo', 'bar'), ('bar', 'baz')])146 assert set(g.ready_nodes) == {'foo'}147 g2 = g.copy()148 g2.mark_running('foo')149 assert set(g.ready_nodes) == {'foo'}150 assert set(g2.ready_nodes) == set()151 g2.mark_finished('foo')152 assert set(g.ready_nodes) == {'foo'}153 assert set(g2.ready_nodes) == {'bar'}154 g2.mark_finished('bar')155 assert set(g.ready_nodes) == {'foo'}156 assert set(g2.ready_nodes) == {'baz'}157 g.add(nodes=['quux'], edges=[('baz', 'quux')])158 assert set(g.all_nodes) == {'foo', 'bar', 'baz', 'quux'}159 assert set(g2.all_nodes) == {'foo', 'bar', 'baz'}160def test_sameness():161 import dagon.core.ll_dag...

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