Best Python code snippet using slash
tasklets_test.py
Source:tasklets_test.py
...52 f = tasklets.Future()53 f.set_result(42)54 self.assertEqual(f._result, 42)55 self.assertEqual(f._exception, None)56 self.assertEqual(f.get_result(), 42)57 def testFuture_SetException(self):58 f = tasklets.Future()59 err = RuntimeError(42)60 f.set_exception(err)61 self.assertEqual(f.done(), True)62 self.assertEqual(f._exception, err)63 self.assertEqual(f._result, None)64 self.assertEqual(f.get_exception(), err)65 self.assertRaises(RuntimeError, f.get_result)66 def testFuture_AddDoneCallback_SetResult(self):67 f = tasklets.Future()68 f.add_callback(self.universal_callback, f)69 self.assertEqual(self.log, []) # Nothing happened yet.70 f.set_result(42)71 eventloop.run()72 self.assertEqual(self.log, [(f,)])73 def testFuture_SetResult_AddDoneCallback(self):74 f = tasklets.Future()75 f.set_result(42)76 self.assertEqual(f.get_result(), 42)77 f.add_callback(self.universal_callback, f)78 eventloop.run()79 self.assertEqual(self.log, [(f,)])80 def testFuture_AddDoneCallback_SetException(self):81 f = tasklets.Future()82 f.add_callback(self.universal_callback, f)83 f.set_exception(RuntimeError(42))84 eventloop.run()85 self.assertEqual(self.log, [(f,)])86 self.assertEqual(f.done(), True)87 def create_futures(self):88 self.futs = []89 for i in range(5):90 f = tasklets.Future()91 f.add_callback(self.universal_callback, f)92 def wake(fut, result):93 fut.set_result(result)94 self.ev.queue_call(i*0.01, wake, f, i)95 self.futs.append(f)96 return set(self.futs)97 def testFuture_WaitAny(self):98 self.assertEqual(tasklets.Future.wait_any([]), None)99 todo = self.create_futures()100 while todo:101 f = tasklets.Future.wait_any(todo)102 todo.remove(f)103 eventloop.run()104 self.assertEqual(self.log, [(f,) for f in self.futs])105 def testFuture_WaitAll(self):106 todo = self.create_futures()107 tasklets.Future.wait_all(todo)108 self.assertEqual(self.log, [(f,) for f in self.futs])109 def testSleep(self):110 log = []111 @tasklets.tasklet112 def foo():113 log.append(time.time())114 yield tasklets.sleep(0.1)115 log.append(time.time())116 foo()117 eventloop.run()118 t0, t1 = log119 dt = t1-t0120 self.assertAlmostEqual(dt, 0.1, places=2)121 def testMultiFuture(self):122 @tasklets.tasklet123 def foo(dt):124 yield tasklets.sleep(dt)125 raise tasklets.Return('foo-%s' % dt)126 @tasklets.tasklet127 def bar(n):128 for i in range(n):129 yield tasklets.sleep(0.01)130 raise tasklets.Return('bar-%d' % n)131 bar5 = bar(5)132 futs = [foo(0.05), foo(0.01), foo(0.03), bar(3), bar5, bar5]133 mfut = tasklets.MultiFuture()134 for fut in futs:135 mfut.add_dependent(fut)136 mfut.complete()137 results = mfut.get_result()138 self.assertEqual(set(results),139 set(['foo-0.01', 'foo-0.03', 'foo-0.05',140 'bar-3', 'bar-5']))141 def testMultiFuture_PreCompleted(self):142 @tasklets.tasklet143 def foo():144 yield tasklets.sleep(0.01)145 raise tasklets.Return(42)146 mfut = tasklets.MultiFuture()147 dep = foo()148 dep.wait()149 mfut.add_dependent(dep)150 mfut.complete()151 eventloop.run()152 self.assertTrue(mfut.done())153 self.assertEqual(mfut.get_result(), [42])154 def testMultiFuture_SetException(self):155 mf = tasklets.MultiFuture()156 f1 = Future()157 f2 = Future()158 f3 = Future()159 f2.set_result(2)160 mf.putq(f1)161 f1.set_result(1)162 mf.putq(f2)163 mf.putq(f3)164 mf.putq(4)165 self.ev.run()166 mf.set_exception(ZeroDivisionError())167 f3.set_result(3)168 self.ev.run()169 self.assertRaises(ZeroDivisionError, mf.get_result)170 def testMultiFuture_ItemException(self):171 mf = tasklets.MultiFuture()172 f1 = Future()173 f2 = Future()174 f3 = Future()175 f2.set_result(2)176 mf.putq(f1)177 f1.set_exception(ZeroDivisionError())178 mf.putq(f2)179 mf.putq(f3)180 f3.set_result(3)181 self.ev.run()182 mf.complete()183 self.assertRaises(ZeroDivisionError, mf.get_result)184 def testMultiFuture_Repr(self):185 mf = tasklets.MultiFuture('info')186 r1 = repr(mf)187 mf.putq(1)188 r2 = repr(mf)189 f2 = Future()190 f2.set_result(2)191 mf.putq(2)192 r3 = repr(mf)193 self.ev.run()194 r4 = repr(mf)195 f3 = Future()196 mf.putq(f3)197 r5 = repr(mf)198 mf.complete()199 r6 = repr(mf)200 f3.set_result(3)201 self.ev.run()202 r7 = repr(mf)203 for r in r1, r2, r3, r4, r5, r6, r7:204 self.assertTrue(205 re.match(206 r'<MultiFuture [\da-f]+ created by '207 r'(testMultiFuture_Repr\(tasklets_test.py:\d+\)|\?) for info; ',208 r))209 if r is r7:210 self.assertTrue('result' in r)211 else:212 self.assertTrue('pending' in r)213 def testQueueFuture(self):214 q = tasklets.QueueFuture()215 @tasklets.tasklet216 def produce_one(i):217 yield tasklets.sleep(i * 0.01)218 raise tasklets.Return(i)219 @tasklets.tasklet220 def producer():221 q.putq(0)222 for i in range(1, 10):223 q.add_dependent(produce_one(i))224 q.complete()225 @tasklets.tasklet226 def consumer():227 for i in range(10):228 val = yield q.getq()229 self.assertEqual(val, i)230 yield q231 self.assertRaises(EOFError, q.getq().get_result)232 @tasklets.tasklet233 def foo():234 yield producer(), consumer()235 foo().get_result()236 def testQueueFuture_Complete(self):237 qf = tasklets.QueueFuture()238 qf.putq(1)239 f2 = Future()240 qf.putq(f2)241 self.ev.run()242 g1 = qf.getq()243 g2 = qf.getq()244 g3 = qf.getq()245 f2.set_result(2)246 self.ev.run()247 qf.complete()248 self.ev.run()249 self.assertEqual(g1.get_result(), 1)250 self.assertEqual(g2.get_result(), 2)251 self.assertRaises(EOFError, g3.get_result)252 self.assertRaises(EOFError, qf.getq().get_result)253 def testQueueFuture_SetException(self):254 qf = tasklets.QueueFuture()255 f1 = Future()256 f1.set_result(1)257 qf.putq(f1)258 qf.putq(f1)259 self.ev.run()260 qf.putq(2)261 self.ev.run()262 f3 = Future()263 f3.set_exception(ZeroDivisionError())264 qf.putq(f3)265 self.ev.run()266 f4 = Future()267 qf.putq(f4)268 self.ev.run()269 qf.set_exception(KeyError())270 f4.set_result(4)271 self.ev.run()272 self.assertRaises(KeyError, qf.get_result)273 # Futures are returned in the order of completion, which should be274 # f1, f2, f3, f4. These produce 1, 2, ZeroDivisionError, 4,275 # respectively. After that KeyError (the exception set on qf276 # itself) is raised.277 self.assertEqual(qf.getq().get_result(), 1)278 self.assertEqual(qf.getq().get_result(), 2)279 self.assertRaises(ZeroDivisionError, qf.getq().get_result)280 self.assertEqual(qf.getq().get_result(), 4)281 self.assertRaises(KeyError, qf.getq().get_result)282 self.assertRaises(KeyError, qf.getq().get_result)283 def testQueueFuture_SetExceptionAlternative(self):284 qf = tasklets.QueueFuture()285 g1 = qf.getq()286 qf.set_exception(KeyError())287 self.ev.run()288 self.assertRaises(KeyError, g1.get_result)289 def testQueueFuture_ItemException(self):290 qf = tasklets.QueueFuture()291 qf.putq(1)292 f2 = Future()293 qf.putq(f2)294 f3 = Future()295 f3.set_result(3)296 self.ev.run()297 qf.putq(f3)298 self.ev.run()299 f4 = Future()300 f4.set_exception(ZeroDivisionError())301 self.ev.run()302 qf.putq(f4)303 f5 = Future()304 qf.putq(f5)305 self.ev.run()306 qf.complete()307 self.ev.run()308 f2.set_result(2)309 self.ev.run()310 f5.set_exception(KeyError())311 self.ev.run()312 # Futures are returned in the order of completion, which should be313 # f1, f3, f4, f2, f5. These produce 1, 3, ZeroDivisionError, 2,314 # KeyError, respectively. After that EOFError is raised.315 self.assertEqual(qf.getq().get_result(), 1)316 self.assertEqual(qf.getq().get_result(), 3)317 self.assertRaises(ZeroDivisionError, qf.getq().get_result)318 self.assertEqual(qf.getq().get_result(), 2)319 self.assertRaises(KeyError, qf.getq().get_result)320 self.assertRaises(EOFError, qf.getq().get_result)321 self.assertRaises(EOFError, qf.getq().get_result)322 def testSerialQueueFuture(self):323 q = tasklets.SerialQueueFuture()324 @tasklets.tasklet325 def produce_one(i):326 yield tasklets.sleep(random.randrange(10) * 0.01)327 raise tasklets.Return(i)328 @tasklets.tasklet329 def producer():330 for i in range(10):331 q.add_dependent(produce_one(i))332 q.complete()333 @tasklets.tasklet334 def consumer():335 for i in range(10):336 val = yield q.getq()337 self.assertEqual(val, i)338 yield q339 self.assertRaises(EOFError, q.getq().get_result)340 yield q341 @tasklets.synctasklet342 def foo():343 yield producer(), consumer()344 foo()345 def testSerialQueueFuture_Complete(self):346 sqf = tasklets.SerialQueueFuture()347 g1 = sqf.getq()348 sqf.complete()349 self.assertRaises(EOFError, g1.get_result)350 def testSerialQueueFuture_SetException(self):351 sqf = tasklets.SerialQueueFuture()352 g1 = sqf.getq()353 sqf.set_exception(KeyError())354 self.assertRaises(KeyError, g1.get_result)355 def testSerialQueueFuture_ItemException(self):356 sqf = tasklets.SerialQueueFuture()357 g1 = sqf.getq()358 f1 = Future()359 sqf.putq(f1)360 sqf.complete()361 f1.set_exception(ZeroDivisionError())362 self.assertRaises(ZeroDivisionError, g1.get_result)363 def testSerialQueueFuture_PutQ_1(self):364 sqf = tasklets.SerialQueueFuture()365 f1 = Future()366 sqf.putq(f1)367 sqf.complete()368 f1.set_result(1)369 self.assertEqual(sqf.getq().get_result(), 1)370 def testSerialQueueFuture_PutQ_2(self):371 sqf = tasklets.SerialQueueFuture()372 sqf.putq(1)373 sqf.complete()374 self.assertEqual(sqf.getq().get_result(), 1)375 def testSerialQueueFuture_PutQ_3(self):376 sqf = tasklets.SerialQueueFuture()377 g1 = sqf.getq()378 sqf.putq(1)379 sqf.complete()380 self.assertEqual(g1.get_result(), 1)381 def testSerialQueueFuture_PutQ_4(self):382 sqf = tasklets.SerialQueueFuture()383 g1 = sqf.getq()384 f1 = Future()385 sqf.putq(f1)386 sqf.complete()387 f1.set_result(1)388 self.assertEqual(g1.get_result(), 1)389 def testSerialQueueFuture_GetQ(self):390 sqf = tasklets.SerialQueueFuture()391 sqf.set_exception(KeyError())392 self.assertRaises(KeyError, sqf.getq().get_result)393 def testReducingFuture(self):394 def reducer(arg):395 return sum(arg)396 rf = tasklets.ReducingFuture(reducer, batch_size=10)397 for i in range(10):398 rf.putq(i)399 for i in range(10, 20):400 f = Future()401 rf.putq(f)402 f.set_result(i)403 rf.complete()404 self.assertEqual(rf.get_result(), sum(range(20)))405 def testReducingFuture_Empty(self):406 def reducer(arg):407 self.fail()408 rf = tasklets.ReducingFuture(reducer)409 rf.complete()410 self.assertEqual(rf.get_result(), None)411 def testReducingFuture_OneItem(self):412 def reducer(arg):413 self.fail()414 rf = tasklets.ReducingFuture(reducer)415 rf.putq(1)416 rf.complete()417 self.assertEqual(rf.get_result(), 1)418 def testReducingFuture_ItemException(self):419 def reducer(arg):420 return sum(arg)421 rf = tasklets.ReducingFuture(reducer)422 f1 = Future()423 f1.set_exception(ZeroDivisionError())424 rf.putq(f1)425 rf.complete()426 self.assertRaises(ZeroDivisionError, rf.get_result)427 def testReducingFuture_ReducerException_1(self):428 def reducer(arg):429 raise ZeroDivisionError430 rf = tasklets.ReducingFuture(reducer)431 rf.putq(1)432 rf.putq(1)433 rf.complete()434 self.assertRaises(ZeroDivisionError, rf.get_result)435 def testReducingFuture_ReducerException_2(self):436 def reducer(arg):437 raise ZeroDivisionError438 rf = tasklets.ReducingFuture(reducer, batch_size=2)439 rf.putq(1)440 rf.putq(1)441 rf.putq(1)442 rf.complete()443 self.assertRaises(ZeroDivisionError, rf.get_result)444 def testReducingFuture_ReducerFuture_1(self):445 def reducer(arg):446 f = Future()447 f.set_result(sum(arg))448 return f449 rf = tasklets.ReducingFuture(reducer, batch_size=2)450 rf.putq(1)451 rf.putq(1)452 rf.complete()453 self.assertEqual(rf.get_result(), 2)454 def testReducingFuture_ReducerFuture_2(self):455 # Weird hack to reach _internal_add_dependent() call in _mark_finished().456 def reducer(arg):457 res = sum(arg)458 if len(arg) < 3:459 f = Future()460 f.set_result(res)461 res = f462 return res463 rf = tasklets.ReducingFuture(reducer, batch_size=3)464 rf.putq(1)465 rf.putq(1)466 rf.putq(1)467 rf.putq(1)468 rf.complete()469 self.assertEqual(rf.get_result(), 4)470 def testGetReturnValue(self):471 r0 = tasklets.Return()472 r1 = tasklets.Return(42)473 r2 = tasklets.Return(42, 'hello')474 r3 = tasklets.Return((1, 2, 3))475 self.assertEqual(tasklets.get_return_value(r0), None)476 self.assertEqual(tasklets.get_return_value(r1), 42)477 self.assertEqual(tasklets.get_return_value(r2), (42, 'hello'))478 self.assertEqual(tasklets.get_return_value(r3), (1, 2, 3))479 def testTasklets_Basic(self):480 @tasklets.tasklet481 def t1():482 a = yield t2(3)483 b = yield t3(2)484 raise tasklets.Return(a + b)485 @tasklets.tasklet486 def t2(n):487 raise tasklets.Return(n)488 @tasklets.tasklet489 def t3(n):490 return n491 x = t1()492 self.assertTrue(isinstance(x, tasklets.Future))493 y = x.get_result()494 self.assertEqual(y, 5)495 def testTasklets_Raising(self):496 @tasklets.tasklet497 def t1():498 f = t2(True)499 try:500 a = yield f501 except RuntimeError, err:502 self.assertEqual(f.get_exception(), err)503 raise tasklets.Return(str(err))504 @tasklets.tasklet505 def t2(error):506 if error:507 raise RuntimeError('hello')508 else:509 yield tasklets.Future()510 x = t1()511 y = x.get_result()512 self.assertEqual(y, 'hello')513 def testTasklets_YieldRpcs(self):514 @tasklets.tasklet515 def main_tasklet():516 rpc1 = self.conn.async_get(None, [])517 rpc2 = self.conn.async_put(None, [])518 res1 = yield rpc1519 res2 = yield rpc2520 raise tasklets.Return(res1, res2)521 f = main_tasklet()522 result = f.get_result()523 self.assertEqual(result, ([], []))524 def testTasklet_YieldTuple(self):525 @tasklets.tasklet526 def fib(n):527 if n <= 1:528 raise tasklets.Return(n)529 a, b = yield fib(n - 1), fib(n - 2)530 # print 'fib(%r) = %r + %r = %r' % (n, a, b, a + b)531 self.assertTrue(a >= b, (a, b))532 raise tasklets.Return(a + b)533 fut = fib(10)534 val = fut.get_result()535 self.assertEqual(val, 55)536 def testTasklet_YieldTupleError(self):537 @tasklets.tasklet538 def good():539 yield tasklets.sleep(0)540 @tasklets.tasklet541 def bad():542 1/0543 yield tasklets.sleep(0)544 @tasklets.tasklet545 def foo():546 try:547 yield good(), bad(), good()548 self.assertFalse('Should have raised ZeroDivisionError')...
test_server.py
Source:test_server.py
1import os2import unittest3import time4import socket5import subprocess6import json7from unittest import TestCase8class ServerBaseTest(TestCase):9 def setUp(self):10 if os.path.isfile('queue.json'):11 self.save_previous_base_data()12 self.clear_data_base()13 self.restore = True14 else:15 self.restore = False16 self.host = '127.0.0.1'17 self.port = 123418 self.server = subprocess.Popen(['python3', 'server.py', str(self.port)])19 # даем ÑеÑвеÑÑ Ð²ÑÐµÐ¼Ñ Ð½Ð° запÑÑк20 time.sleep(0.5)21 def tearDown(self):22 self.restore_base_data()23 self.server.terminate()24 self.server.wait()25 def save_previous_base_data(self):26 with open('queue.json', 'r') as j:27 self.previous_data = json.loads(j.read())28 def restore_base_data(self):29 if self.restore:30 with open('queue.json', 'w') as j:31 j.write(json.dumps(self.previous_data, indent='\t'))32 else:33 self.clear_data_base()34 @staticmethod35 def clear_data_base():36 clear_data = {"queues": {}, "tasks in work": []}37 with open('queue.json', 'w') as j:38 j.write(json.dumps(clear_data))39 def send(self, command):40 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)41 s.connect((self.host, self.port))42 s.send(command)43 data = s.recv(1000000)44 s.close()45 return data46 def test_base_scenario(self):47 task_id = self.send(b'ADD 1 5 12345').strip(b'\n')48 self.assertEqual(b'YES\n', self.send(b'IN 1 ' + task_id))49 self.assertEqual(task_id + b' 5 12345\n', self.send(b'GET 1'))50 self.assertEqual(b'YES\n', self.send(b'IN 1 ' + task_id))51 self.assertEqual(b'OK\n', self.send(b'ACK 1 ' + task_id))52 self.assertEqual(b'NOT_OK\n', self.send(b'ACK 1 ' + task_id))53 self.assertEqual(b'NO\n', self.send(b'IN 1 ' + task_id))54 def test_two_tasks(self):55 first_task_id = self.send(b'ADD 1 5 12345').strip(b'\n')56 second_task_id = self.send(b'ADD 1 5 12345').strip(b'\n')57 self.assertEqual(b'YES\n', self.send(b'IN 1 ' + first_task_id))58 self.assertEqual(b'YES\n', self.send(b'IN 1 ' + second_task_id))59 self.assertEqual(first_task_id + b' 5 12345\n', self.send(b'GET 1'))60 self.assertEqual(b'YES\n', self.send(b'IN 1 ' + first_task_id))61 self.assertEqual(b'YES\n', self.send(b'IN 1 ' + second_task_id))62 self.assertEqual(second_task_id + b' 5 12345\n', self.send(b'GET 1'))63 self.assertEqual(b'OK\n', self.send(b'ACK 1 ' + second_task_id))64 self.assertEqual(b'NOT_OK\n', self.send(b'ACK 1 ' + second_task_id))65class ServerAddCommandTest(TestCase):66 def setUp(self):67 if os.path.isfile('queue.json'):68 self.save_previous_base_data()69 self.clear_data_base()70 self.restore = True71 else:72 self.restore = False73 self.host = '127.0.0.1'74 self.port = 123475 self.server = subprocess.Popen(['python3', 'server.py', str(self.port)])76 # даем ÑеÑвеÑÑ Ð²ÑÐµÐ¼Ñ Ð½Ð° запÑÑк77 time.sleep(0.5)78 def tearDown(self):79 self.restore_base_data()80 self.server.terminate()81 self.server.wait()82 def save_previous_base_data(self):83 with open('queue.json', 'r') as j:84 self.previous_data = json.loads(j.read())85 def restore_base_data(self):86 if self.restore:87 with open('queue.json', 'w') as j:88 j.write(json.dumps(self.previous_data, indent='\t'))89 else:90 self.clear_data_base()91 @staticmethod92 def clear_data_base():93 clear_data = {"queues": {}, "tasks in work": []}94 with open('queue.json', 'w') as j:95 j.write(json.dumps(clear_data))96 def send(self, command):97 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)98 s.connect((self.host, self.port))99 s.send(command)100 data = s.recv(1000000)101 s.close()102 return data103 def test_normal_command(self):104 task_id = self.send(b'ADD 1 5 12345').strip(b'\n')105 self.assertTrue(task_id)106 def test_command_with_spaces(self):107 task_id = self.send(b' ADD 1 5 12345 ').strip(b'\n')108 self.assertTrue(task_id)109 def test_lower_command(self):110 task_id = self.send(b'add 1 5 12345').strip(b'\n')111 self.assertTrue(task_id)112 def test_mixed_command(self):113 task_id = self.send(b'aDd 1 5 12345').strip(b'\n')114 self.assertTrue(task_id)115 def test_command_with_incorrect_length_parameter(self):116 task_id = self.send(b'ADD 1 5.0 12345').strip(b'\n')117 self.assertFalse(task_id)118 def test_command_with_incorrect_parameters_amount(self):119 task_id = self.send(b'ADD 1 2 5 12345').strip(b'\n')120 self.assertFalse(task_id)121 task_id = self.send(b'ADD').strip(b'\n')122 self.assertFalse(task_id)123 task_id = self.send(b'ADD 1').strip(b'\n')124 self.assertFalse(task_id)125 task_id = self.send(b'ADD 1 5').strip(b'\n')126 self.assertFalse(task_id)127 def test_command_with_length_parameter_more_than_1000000(self):128 data = ''.join('0123456789' for _ in range(10 ** 5 + 1)).encode('utf8')129 command = b'ADD 1 ' + str(len(data)).encode('utf8') + b' ' + data130 task_id = self.send(command).strip(b'\n')131 self.assertFalse(task_id)132 def test_command_with_data_more_than_length(self):133 task_id = self.send(b'ADD 1 5 123456').strip(b'\n')134 self.assertFalse(task_id)135 def test_command_with_data_less_than_length(self):136 task_id = self.send(b'ADD 1 5 1234').strip(b'\n')137 self.assertFalse(task_id)138class ServerGetCommandTest(TestCase):139 def setUp(self):140 if os.path.isfile('queue.json'):141 self.save_previous_base_data()142 self.clear_data_base()143 self.restore = True144 else:145 self.restore = False146 self.host = '127.0.0.1'147 self.port = 1234148 self.server = subprocess.Popen(['python3', 'server.py', str(self.port)])149 # даем ÑеÑвеÑÑ Ð²ÑÐµÐ¼Ñ Ð½Ð° запÑÑк150 time.sleep(0.5)151 self.task_id = self.preconditions()152 def tearDown(self):153 self.restore_base_data()154 self.server.terminate()155 self.server.wait()156 def save_previous_base_data(self):157 with open('queue.json', 'r') as j:158 self.previous_data = json.loads(j.read())159 def restore_base_data(self):160 if self.restore:161 with open('queue.json', 'w') as j:162 j.write(json.dumps(self.previous_data, indent='\t'))163 else:164 self.clear_data_base()165 @staticmethod166 def clear_data_base():167 clear_data = {"queues": {}, "tasks in work": []}168 with open('queue.json', 'w') as j:169 j.write(json.dumps(clear_data))170 def preconditions(self):171 # create queue and task:172 task_id = self.send(b'ADD 1 5 12345').strip(b'\n')173 self.assertTrue(task_id)174 return task_id175 def send(self, command):176 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)177 s.connect((self.host, self.port))178 s.send(command)179 data = s.recv(1000000)180 s.close()181 return data182 def test_command_with_incorrct_queue_name(self):183 get_result = self.send(b'GET 2').strip(b'\n')184 self.assertEqual(get_result, b'NONE')185 def test_command_with_incorrect_paramters_amount(self):186 get_result = self.send(b'GET 2 2').strip(b'\n')187 self.assertEqual(get_result, b'NONE')188 get_result = self.send(b'GET').strip(b'\n')189 self.assertEqual(get_result, b'NONE')190 def test_normal_command(self):191 get_result = self.send(b'GET 1').strip(b'\n')192 self.assertTrue(get_result)193 get_result = get_result.split()194 self.assertEqual(get_result[0], self.task_id)195 self.assertEqual(int(get_result[1]), len(get_result[2]))196 def test_lower_command(self):197 get_result = self.send(b'get 1').strip(b'\n')198 self.assertTrue(get_result)199 get_result = get_result.split()200 self.assertEqual(get_result[0], self.task_id)201 self.assertEqual(int(get_result[1]), len(get_result[2]))202 def test_mixed_command_with_spaces(self):203 get_result = self.send(b' GeT 1 ').strip(b'\n')204 self.assertTrue(get_result)205 get_result = get_result.split()206 self.assertEqual(get_result[0], self.task_id)207 self.assertEqual(int(get_result[1]), len(get_result[2]))208 def test_get_when_all_tasks_are_in_work(self):209 self.test_normal_command()210 get_result = self.send(b'GET 1').strip(b'\n')211 self.assertEqual(get_result, b'NONE')212 def test_undone_tasks_returns_to_queue_after_5_minutes(self):213 self.test_normal_command()214 time.sleep(60 * 5)215 get_result = self.send(b'GET 1').strip(b'\n')216 get_result = get_result.split()217 self.assertEqual(get_result[0], self.task_id)218 get_result = self.send(b'GET 1').strip(b'\n')219class ServerAckCommandTest(TestCase):220 def setUp(self):221 if os.path.isfile('queue.json'):222 self.save_previous_base_data()223 self.clear_data_base()224 self.restore = True225 else:226 self.restore = False227 self.host = '127.0.0.1'228 self.port = 1234229 self.server = subprocess.Popen(['python3', 'server.py', str(self.port)])230 # даем ÑеÑвеÑÑ Ð²ÑÐµÐ¼Ñ Ð½Ð° запÑÑк231 time.sleep(0.5)232 self.task_id = self.preconditions()233 def tearDown(self):234 self.restore_base_data()235 self.server.terminate()236 self.server.wait()237 def save_previous_base_data(self):238 with open('queue.json', 'r') as j:239 self.previous_data = json.loads(j.read())240 def restore_base_data(self):241 if self.restore:242 with open('queue.json', 'w') as j:243 j.write(json.dumps(self.previous_data, indent='\t'))244 else:245 self.clear_data_base()246 @staticmethod247 def clear_data_base():248 clear_data = {"queues": {}, "tasks in work": []}249 with open('queue.json', 'w') as j:250 j.write(json.dumps(clear_data))251 def preconditions(self):252 # create queue and tasks:253 task_id = self.send(b'ADD 1 5 12345').strip(b'\n')254 self.assertTrue(task_id)255 # issue tasks in work256 get_result = self.send(b'GET 1').strip(b'\n')257 self.assertTrue(get_result)258 get_result = get_result.split()259 self.assertEqual(get_result[0], task_id)260 self.assertEqual(int(get_result[1]), len(get_result[2]))261 return task_id262 def send(self, command):263 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)264 s.connect((self.host, self.port))265 s.send(command)266 data = s.recv(1000000)267 s.close()268 return data269 def test_command_with_incorrect_queue_name(self):270 ack_result = self.send(b'ACK 2 ' + self.task_id).strip(b'\n')271 self.assertEqual(ack_result, b'NOT_OK')272 def test_command_with_incorrect_task_name(self):273 ack_result = self.send(b'ACK 1 ' + self.task_id.upper()).strip(b'\n')274 self.assertEqual(ack_result, b'NOT_OK')275 def test_command_with_incorrect_parameters_amount(self):276 ack_result = self.send(b'ACK 1 ' + self.task_id + b' 2').strip(b'\n')277 self.assertEqual(ack_result, b'NOT_OK')278 ack_result = self.send(b'ACK').strip(b'\n')279 self.assertEqual(ack_result, b'NOT_OK')280 ack_result = self.send(b'ACK 1').strip(b'\n')281 self.assertEqual(ack_result, b'NOT_OK')282 def test_normal_command(self):283 ack_result = self.send(b'ACK 1 ' + self.task_id).strip(b'\n')284 self.assertEqual(ack_result, b'OK')285 def test_lower_command(self):286 ack_result = self.send(b'ack 1 ' + self.task_id).strip(b'\n')287 self.assertEqual(ack_result, b'OK')288 def test_mixed_command_with_spaces(self):289 ack_result = self.send(b' aCk 1 ' + self.task_id).strip(b'\n')290 self.assertEqual(ack_result, b'OK')291 def test_end_task_that_was_already_ended(self):292 self.test_normal_command()293 ack_result = self.send(b'ACK 1 ' + self.task_id).strip(b'\n')294 self.assertEqual(ack_result, b'NOT_OK')295 def test_end_task_that_was_returned_to_queue_after_5_minutes(self):296 time.sleep(60 * 5)297 ack_result = self.send(b'ACK 1 ' + self.task_id).strip(b'\n')298 self.assertEqual(ack_result, b'NOT_OK')299class ServerInCommandTest(TestCase):300 def setUp(self):301 if os.path.isfile('queue.json'):302 self.save_previous_base_data()303 self.clear_data_base()304 self.restore = True305 else:306 self.restore = False307 self.host = '127.0.0.1'308 self.port = 1234309 self.server = subprocess.Popen(['python3', 'server.py', str(self.port)])310 # даем ÑеÑвеÑÑ Ð²ÑÐµÐ¼Ñ Ð½Ð° запÑÑк311 time.sleep(0.5)312 self.task_id = self.preconditions()313 def tearDown(self):314 self.restore_base_data()315 self.server.terminate()316 self.server.wait()317 def save_previous_base_data(self):318 with open('queue.json', 'r') as j:319 self.previous_data = json.loads(j.read())320 def restore_base_data(self):321 if self.restore:322 with open('queue.json', 'w') as j:323 j.write(json.dumps(self.previous_data, indent='\t'))324 else:325 self.clear_data_base()326 @staticmethod327 def clear_data_base():328 clear_data = {"queues": {}, "tasks in work": []}329 with open('queue.json', 'w') as j:330 j.write(json.dumps(clear_data))331 def preconditions(self):332 # create queue and tasks:333 task_id = self.send(b'ADD 1 5 12345').strip(b'\n')334 self.assertTrue(task_id)335 return task_id336 def send(self, command):337 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)338 s.connect((self.host, self.port))339 s.send(command)340 data = s.recv(1000000)341 s.close()342 return data343 def test_command_with_incorrect_queue_name(self):344 in_result = self.send(b'IN 2 ' + self.task_id).strip(b'\n')345 self.assertEqual(in_result, b'NO')346 def test_command_with_incorrect_task_name(self):347 in_result = self.send(b'IN 1 ' + self.task_id.upper()).strip(b'\n')348 self.assertEqual(in_result, b'NO')349 def test_command_with_incorrect_parameters_amount(self):350 in_result = self.send(b'IN 1 ' + self.task_id + b' 2').strip(b'\n')351 self.assertEqual(in_result, b'NO')352 in_result = self.send(b'IN').strip(b'\n')353 self.assertEqual(in_result, b'NO')354 in_result = self.send(b'IN 1').strip(b'\n')355 self.assertEqual(in_result, b'NO')356 def test_normal_command(self):357 in_result = self.send(b'IN 1 ' + self.task_id).strip(b'\n')358 self.assertEqual(in_result, b'YES')359 def test_lower_command(self):360 in_result = self.send(b'in 1 ' + self.task_id).strip(b'\n')361 self.assertEqual(in_result, b'YES')362 def test_mixed_command_with_spaces(self):363 in_result = self.send(b' iN 1 ' + self.task_id).strip(b'\n')364 self.assertEqual(in_result, b'YES')365 def test_tasks_in_work(self):366 get_result = self.send(b'GET 1').strip(b'\n')367 self.assertTrue(get_result)368 get_result = get_result.split()369 self.assertEqual(get_result[0], self.task_id)370 self.assertEqual(int(get_result[1]), len(get_result[2]))371 in_result = self.send(b'IN 1 ' + self.task_id).strip(b'\n')372 self.assertEqual(in_result, b'YES')373 def test_ended_task(self):374 get_result = self.send(b'GET 1').strip(b'\n')375 self.assertTrue(get_result)376 get_result = get_result.split()377 self.assertEqual(get_result[0], self.task_id)378 self.assertEqual(int(get_result[1]), len(get_result[2]))379 ack_result = self.send(b'ACK 1 ' + self.task_id).strip(b'\n')380 self.assertEqual(ack_result, b'OK')381 in_result = self.send(b'IN 1 ' + self.task_id).strip(b'\n')382 self.assertEqual(in_result, b'NO')383if __name__ == '__main__':...
test_discovery_v1.py
Source:test_discovery_v1.py
...18 'X-Watson-Learning-Opt-Out': '1',19 'X-Watson-Test': '1'20 })21 collections = cls.discovery.list_collections(22 cls.environment_id).get_result()['collections']23 for collection in collections:24 if collection['name'] == cls.collection_name:25 cls.collection_id = collection['collection_id']26 if cls.collection_id is None:27 print("Creating a new temporary collection")28 cls.collection_id = cls.discovery.create_collection(29 cls.environment_id,30 cls.collection_name,31 description="Integration test for python sdk").get_result(32 )['collection_id']33 @classmethod34 def teardown_class(cls):35 collections = cls.discovery.list_collections(36 cls.environment_id).get_result()['collections']37 for collection in collections:38 if collection['name'] == cls.collection_name:39 print('Deleting the temporary collection')40 cls.discovery.delete_collection(cls.environment_id,41 cls.collection_id)42 break43 def test_environments(self):44 envs = self.discovery.list_environments().get_result()45 assert envs is not None46 env = self.discovery.get_environment(47 envs['environments'][0]['environment_id']).get_result()48 assert env is not None49 fields = self.discovery.list_fields(self.environment_id,50 self.collection_id).get_result()51 assert fields is not None52 def test_configurations(self):53 configs = self.discovery.list_configurations(54 self.environment_id).get_result()55 assert configs is not None56 name = 'test' + random.choice('ABCDEFGHIJKLMNOPQ')57 new_configuration_id = self.discovery.create_configuration(58 self.environment_id,59 name,60 description='creating new config for python sdk').get_result(61 )['configuration_id']62 assert new_configuration_id is not None63 self.discovery.get_configuration(self.environment_id,64 new_configuration_id).get_result()65 updated_config = self.discovery.update_configuration(66 self.environment_id, new_configuration_id, 'lala').get_result()67 assert updated_config['name'] == 'lala'68 deleted_config = self.discovery.delete_configuration(69 self.environment_id, new_configuration_id).get_result()70 assert deleted_config['status'] == 'deleted'71 def test_collections_and_expansions(self):72 self.discovery.get_collection(self.environment_id, self.collection_id)73 updated_collection = self.discovery.update_collection(74 self.environment_id,75 self.collection_id,76 self.collection_name,77 description='Updating description').get_result()78 assert updated_collection['description'] == 'Updating description'79 self.discovery.create_expansions(self.environment_id,80 self.collection_id, [{81 'input_terms': ['a'],82 'expanded_terms': ['aa']83 }]).get_result()84 expansions = self.discovery.list_expansions(85 self.environment_id, self.collection_id).get_result()86 assert expansions['expansions']87 self.discovery.delete_expansions(self.environment_id,88 self.collection_id)89 def test_documents(self):90 with open(91 os.path.join(os.path.dirname(__file__),92 '../../resources/simple.html'), 'r') as fileinfo:93 add_doc = self.discovery.add_document(94 environment_id=self.environment_id,95 collection_id=self.collection_id,96 file=fileinfo).get_result()97 assert add_doc['document_id'] is not None98 doc_status = self.discovery.get_document_status(99 self.environment_id, self.collection_id,100 add_doc['document_id']).get_result()101 assert doc_status is not None102 with open(103 os.path.join(os.path.dirname(__file__),104 '../../resources/simple.html'), 'r') as fileinfo:105 update_doc = self.discovery.update_document(106 self.environment_id,107 self.collection_id,108 add_doc['document_id'],109 file=fileinfo,110 filename='newname.html').get_result()111 assert update_doc is not None112 delete_doc = self.discovery.delete_document(113 self.environment_id, self.collection_id,114 add_doc['document_id']).get_result()115 assert delete_doc['status'] == 'deleted'116 def test_queries(self):117 query_results = self.discovery.query(118 self.environment_id,119 self.collection_id,120 filter='extracted_metadata.sha1::9181d244*').get_result()121 assert query_results is not None122 @pytest.mark.skip(123 reason="Temporary skipping because update_credentials fails")124 def test_credentials(self):125 credential_details = {126 'credential_type': 'username_password',127 'url': 'https://login.salesforce.com',128 'username': 'user@email.com',129 'password': 'xxx'130 }131 credentials = self.discovery.create_credentials(132 self.environment_id,133 source_type='salesforce',134 credential_details=credential_details).get_result()135 assert credentials['credential_id'] is not None136 credential_id = credentials['credential_id']137 get_credentials = self.discovery.get_credentials(138 self.environment_id, credential_id).get_result()139 assert get_credentials['credential_id'] == credential_id140 list_credentials = self.discovery.list_credentials(141 self.environment_id).get_result()142 assert list_credentials is not None143 new_credential_details = {144 'credential_type': 'username_password',145 'url': 'https://logo.salesforce.com',146 'username': 'user@email.com',147 'password': 'xxx'148 }149 updated_credentials = self.discovery.update_credentials(150 self.environment_id,151 credential_id,152 source_type='salesforce',153 credential_details=new_credential_details).get_result()154 assert updated_credentials is not None155 get_credentials = self.discovery.get_credentials(156 self.environment_id, credentials['credential_id']).get_result()157 assert get_credentials['credential_details'][158 'url'] == new_credential_details['url']159 delete_credentials = self.discovery.delete_credentials(160 self.environment_id, credential_id).get_result()161 assert delete_credentials['credential_id'] is not None162 def test_create_event(self):163 # create test document164 with open(165 os.path.join(os.path.dirname(__file__),166 '../../resources/simple.html'), 'r') as fileinfo:167 add_doc = self.discovery.add_document(168 environment_id=self.environment_id,169 collection_id=self.collection_id,170 file=fileinfo).get_result()171 assert add_doc['document_id'] is not None172 document_id = add_doc['document_id']173 # make query to get session token174 query = self.discovery.query(175 self.environment_id,176 self.collection_id,177 natural_language_query='The content of the first chapter'178 ).get_result()179 assert query['session_token'] is not None180 # create_event181 event_data = {182 "environment_id": self.environment_id,183 "session_token": query['session_token'],184 "collection_id": self.collection_id,185 "document_id": document_id,186 }187 create_event_response = self.discovery.create_event(188 'click', event_data).get_result()189 assert create_event_response['type'] == 'click'190 #delete the documment191 self.discovery.delete_document(self.environment_id, self.collection_id,192 document_id).get_result()193 @pytest.mark.skip(reason="Temporary disable")194 def test_tokenization_dictionary(self):195 result = self.discovery.get_tokenization_dictionary_status(196 self.environment_id, self.collection_id).get_result()197 assert result['status'] is not None198 def test_feedback(self):199 response = self.discovery.get_metrics_event_rate(200 start_time='2018-08-13T14:39:59.309Z',201 end_time='2018-08-14T14:39:59.309Z',202 result_type='document').get_result()203 assert response['aggregations'] is not None204 response = self.discovery.get_metrics_query(205 start_time='2018-08-13T14:39:59.309Z',206 end_time='2018-08-14T14:39:59.309Z',207 result_type='document').get_result()208 assert response['aggregations'] is not None209 response = self.discovery.get_metrics_query_event(210 start_time='2018-08-13T14:39:59.309Z',211 end_time='2018-08-14T14:39:59.309Z',212 result_type='document').get_result()213 assert response['aggregations'] is not None214 response = self.discovery.get_metrics_query_no_results(215 start_time='2018-07-13T14:39:59.309Z',216 end_time='2018-08-14T14:39:59.309Z',217 result_type='document').get_result()218 assert response['aggregations'] is not None219 response = self.discovery.get_metrics_query_token_event(220 count=10).get_result()221 assert response['aggregations'] is not None222 response = self.discovery.query_log(count=2).get_result()223 assert response is not None224 @pytest.mark.skip(reason="Skip temporarily.")225 def test_stopword_operations(self):226 with open(227 os.path.join(os.path.dirname(__file__),228 '../../resources/stopwords.txt'),229 'r') as stopwords_file:230 create_stopword_list_result = self.discovery.create_stopword_list(231 self.environment_id, self.collection_id,232 stopwords_file).get_result()233 assert create_stopword_list_result is not None234 delete_stopword_list_result = self.discovery.delete_stopword_list(235 self.environment_id, self.collection_id).get_result()236 assert delete_stopword_list_result is None237 def test_gateway_configuration(self):238 create_gateway_result = self.discovery.create_gateway(239 self.environment_id,240 name='test-gateway-configuration-python').get_result()241 assert create_gateway_result['gateway_id'] is not None242 get_gateway_result = self.discovery.get_gateway(243 self.environment_id,244 create_gateway_result['gateway_id']).get_result()245 assert get_gateway_result is not None246 list_gateways_result = self.discovery.list_gateways(247 self.environment_id).get_result()248 assert list_gateways_result is not None249 delete_gateways_result = self.discovery.delete_gateway(250 self.environment_id,251 create_gateway_result['gateway_id']).get_result()...
test.py
Source:test.py
...35# TEST 1: primitive type36#37#####################################################################################################38ret = client.set('test:string1', 'test...', timeout)39print(ret.get_result())40assert ret.get_result() == True41ret = client.get('test:string1')42print(ret.get_result())43assert ret.get_result() == 'test...'44ret = client.set('test:string2', 'test...2', timeout)45print(ret.get_result())46assert ret.get_result() == True47ret = client.get('test:string2')48print(ret.get_result())49assert ret.get_result() == 'test...2'50ret = client.set('test:int', 1, timeout)51print(ret.get_result())52assert ret.get_result() == True53ret = client.get('test:int')54print(ret.get_result())55assert ret.get_result() == 156ret = client.set('test:float', 1.2, timeout)57print(ret.get_result())58assert ret.get_result() == True59ret = client.get('test:float')60print(ret.get_result())61assert ret.get_result() == 1.262ret = client.set('test:bool', True, timeout)63print(ret.get_result())64assert ret.get_result() == True65ret = client.get('test:bool')66print(ret.get_result())67assert ret.get_result() == True68now = datetime.datetime.now()69ret = client.set('test:date', now, timeout)70print(ret.get_result())71assert ret.get_result() == True72ret = client.get('test:date')73print(ret.get_result())74print(now)75assert (abs(ret.get_result() - now)) < datetime.timedelta(1000)76ret = client.set('test:bytearray', b'bytes array', timeout)77print(ret.get_result())78assert ret.get_result() == True79ret = client.get('test:bytearray')80print(ret.get_result())81assert ret.get_result() == b'bytes array'82ret = client.set('test:incr', '1', timeout)83print(ret.get_result())84assert ret.get_result() == True85ret = client.incr('test:incr', 10)86print(ret.get_result())87assert ret.get_result() == 1188ret = client.decr('test:incr', 3)89print(ret.get_result())90assert ret.get_result() == 11-391ret = client.decr('test:incr', 100)92print(ret.get_result())93assert ret.get_result() == 0 # minimum value is 094#####################################################################################################95#96# TEST 2: list97#98#####################################################################################################99ret = client.lop_create('test:list_1', ArcusTranscoder.FLAG_STRING, timeout)100print(ret.get_result())101assert ret.get_result() == True102items = ['item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6']103for item in items:104 ret = client.lop_insert('test:list_1', -1, item)105 print(ret.get_result())106 assert ret.get_result() == True107ret = client.lop_get('test:list_1', (0, -1))108print(ret.get_result())109assert ret.get_result() == items110ret = client.lop_get('test:list_1', (2, 4))111print(ret.get_result())112assert ret.get_result() == items[2:4+1]113ret = client.lop_get('test:list_1', (1, -2))114print(ret.get_result())115assert ret.get_result() == items[1:-2+1]116#####################################################################################################117#118# TEST 3: set119#120#####################################################################################################121ret = client.sop_create('test:set_1', ArcusTranscoder.FLAG_STRING, timeout)122print(ret.get_result())123assert ret.get_result() == True124items = ['item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6']125set_items = set()126for item in items:127 set_items.add(item)128for item in set_items:129 ret = client.sop_insert('test:set_1', item)130 print(ret.get_result())131 assert ret.get_result() == True132ret = client.sop_get('test:set_1')133print(ret.get_result())134assert ret.get_result() == set_items135for item in set_items:136 ret = client.sop_exist('test:set_1', item)137 print(ret.get_result())138 assert ret.get_result() == True139ret = client.sop_exist('test:set_1', 'item 100')140print(ret.get_result())141assert ret.get_result() == False142#####################################################################################################143#144# TEST 4: btree145#146#####################################################################################################147def itoh(i):148 h = hex(i)149 if len(h) % 2 == 1:150 h = '0x0%s' % h[2:].upper()151 else:152 h = '0x%s' % h[2:].upper()153 return h154 155# int key156ret = client.bop_create('test:btree_int', ArcusTranscoder.FLAG_INTEGER, timeout)157print (ret.get_result())158assert ret.get_result() == True159for i in range(0, 1000):160 ret = client.bop_insert('test:btree_int', i, i, itoh(i))161 print(ret.get_result())162 assert ret.get_result() == True163ret = client.bop_get('test:btree_int', (200, 400))164print(ret.get_result())165result = ret.get_result()166for i in range(200, 400):167 assert result[i] == (itoh(i), i)168ret = client.bop_count('test:btree_int', (100, 199))169print(ret.get_result())170assert ret.get_result() == 100171# hex key172ret = client.bop_create('test:btree_hex', ArcusTranscoder.FLAG_STRING, timeout)173print (ret.get_result())174assert ret.get_result() == True175for i in range(0x10000, 0x10200):176 ret = client.bop_insert('test:btree_hex', itoh(i), 'bop item %d' % i, itoh(i))177 print(ret.get_result())178 assert ret.get_result() == True179ret = client.bop_get('test:btree_hex', ('0x010050', '0x010150'))180print(ret.get_result())181result = ret.get_result()182for i in range(0x10050, 0x10150):183 assert result[itoh(i)] == (itoh(i), 'bop item %d' % i)184# eflag test185ret = client.bop_create('test:btree_eflag', ArcusTranscoder.FLAG_INTEGER, timeout)186print (ret.get_result())187assert ret.get_result() == True188for i in range(0, 1000):189 ret = client.bop_insert('test:btree_eflag', i, i, itoh(i))190 print(ret.get_result())191 assert ret.get_result() == True192ret = client.bop_get('test:btree_eflag', (200, 400), EflagFilter('EFLAG & 0x00ff == 0x0001'))193print(ret.get_result())194result = ret.get_result()195assert result[257] == ('0x0101', 257)196ret = client.bop_get('test:btree_eflag', (200, 400), EflagFilter('EFLAG & 0x00ff > 0x0010'))197print(ret.get_result())198result = ret.get_result()199for i in range(200, 401):200 if (len(itoh(i)) < 6): 201 if i in result:202 assert False203 continue204 if (i & 0x00ff) <= 0x0010:205 if i in result:206 assert False207 continue208 assert result[i] == (itoh(i), i)209#####################################################################################################210#211# TEST 5: btree mget, smget212#213#####################################################################################################214# int key215ret = client.bop_create('test:btree_1', ArcusTranscoder.FLAG_INTEGER, timeout)216print (ret.get_result())217assert ret.get_result() == True218for i in range(0, 1000):219 ret = client.bop_insert('test:btree_1', i, i, itoh(i))220 print(ret.get_result())221 assert ret.get_result() == True222ret = client.bop_create('test:btree_2', ArcusTranscoder.FLAG_INTEGER, timeout)223print (ret.get_result())224assert ret.get_result() == True225for i in range(1000, 2000):226 ret = client.bop_insert('test:btree_2', i, i, itoh(i))227 print(ret.get_result())228 assert ret.get_result() == True229ret = client.bop_create('test:btree_3', ArcusTranscoder.FLAG_INTEGER, timeout)230print (ret.get_result())231assert ret.get_result() == True232for i in range(2000, 3000):233 ret = client.bop_insert('test:btree_3', i, i, itoh(i))234 print(ret.get_result())235 assert ret.get_result() == True236ret = client.bop_mget(['test:btree_1', 'test:btree_2', 'test:btree_3', 'test:btree_4', 'test:btree_5'], (500, 2500))237print(ret.get_result())238ret = client.bop_smget(['test:btree_1', 'test:btree_2', 'test:btree_3', 'test:btree_4', 'test:btree_5'], (500, 2500))239print(ret.get_result())240result = ret.get_result()241missed_key = ret.get_missed_key()242idx = 500243for item in result:244 if item[0] != idx: # bkey245 print(item[0])246 print(idx)247 assert item[0] == idx # bkey248 assert item[1][:11] == 'test:btree_' # key249 assert item[2] == itoh(idx) # eflag250 assert item[3] == idx # value251 idx += 1252 253assert missed_key == ['test:btree_4', 'test:btree_5']254#####################################################################################################...
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!!