How to use task2 method in locust

Best Python code snippet using locust

auto.js

Source:auto.js Github

copy

Full Screen

1var async = require('../lib');2var expect = require('chai').expect;3var _ = require('lodash');4describe('auto', function () {5 it('basics', function(done){6 var callOrder = [];7 async.auto({8 task1: ['task2', function(results, callback){9 setTimeout(function(){10 callOrder.push('task1');11 callback();12 }, 25);13 }],14 task2: function(callback){15 setTimeout(function(){16 callOrder.push('task2');17 callback();18 }, 50);19 },20 task3: ['task2', function(results, callback){21 callOrder.push('task3');22 callback();23 }],24 task4: ['task1', 'task2', function(results, callback){25 callOrder.push('task4');26 callback();27 }],28 task5: ['task2', function(results, callback){29 setTimeout(function(){30 callOrder.push('task5');31 callback();32 }, 0);33 }],34 task6: ['task2', function(results, callback){35 callOrder.push('task6');36 callback();37 }]38 },39 function(err){40 expect(err).to.equal(null);41 expect(callOrder).to.eql(['task2','task3','task6','task5','task1','task4']);42 done();43 });44 });45 it('auto concurrency', function (done) {46 var concurrency = 2;47 var runningTasks = [];48 function makeCallback(taskName) {49 return function(/*..., callback*/) {50 var callback = _.last(arguments);51 runningTasks.push(taskName);52 setTimeout(function(){53 // Each task returns the array of running tasks as results.54 var result = runningTasks.slice(0);55 runningTasks.splice(runningTasks.indexOf(taskName), 1);56 callback(null, result);57 });58 };59 }60 async.auto({61 task1: ['task2', makeCallback('task1')],62 task2: makeCallback('task2'),63 task3: ['task2', makeCallback('task3')],64 task4: ['task1', 'task2', makeCallback('task4')],65 task5: ['task2', makeCallback('task5')],66 task6: ['task2', makeCallback('task6')]67 }, concurrency, function(err, results){68 _.each(results, function(result) {69 expect(result.length).to.be.below(concurrency + 1);70 });71 done();72 });73 });74 it('auto petrify', function (done) {75 var callOrder = [];76 async.auto({77 task1: ['task2', function (results, callback) {78 setTimeout(function () {79 callOrder.push('task1');80 callback();81 }, 100);82 }],83 task2: function (callback) {84 setTimeout(function () {85 callOrder.push('task2');86 callback();87 }, 200);88 },89 task3: ['task2', function (results, callback) {90 callOrder.push('task3');91 callback();92 }],93 task4: ['task1', 'task2', function (results, callback) {94 callOrder.push('task4');95 callback();96 }]97 },98 function (err) {99 if (err) throw err;100 expect(callOrder).to.eql(['task2', 'task3', 'task1', 'task4']);101 done();102 });103 });104 it('auto results', function(done){105 var callOrder = [];106 async.auto({107 task1: ['task2', function(results, callback){108 expect(results.task2).to.eql('task2');109 setTimeout(function(){110 callOrder.push('task1');111 callback(null, 'task1a', 'task1b');112 }, 25);113 }],114 task2: function(callback){115 setTimeout(function(){116 callOrder.push('task2');117 callback(null, 'task2');118 }, 50);119 },120 task3: ['task2', function(results, callback){121 expect(results.task2).to.eql('task2');122 callOrder.push('task3');123 callback(null);124 }],125 task4: ['task1', 'task2', function(results, callback){126 expect(results.task1).to.eql(['task1a','task1b']);127 expect(results.task2).to.eql('task2');128 callOrder.push('task4');129 callback(null, 'task4');130 }]131 },132 function(err, results){133 expect(callOrder).to.eql(['task2','task3','task1','task4']);134 expect(results).to.eql({task1: ['task1a','task1b'], task2: 'task2', task3: undefined, task4: 'task4'});135 done();136 });137 });138 it('auto empty object', function(done){139 async.auto({}, function(err){140 expect(err).to.equal(null);141 done();142 });143 });144 it('auto error', function(done){145 async.auto({146 task1: function(callback){147 callback('testerror');148 },149 task2: ['task1', function(/*results, callback*/){150 throw new Error('task2 should not be called');151 }],152 task3: function(callback){153 callback('testerror2');154 }155 },156 function(err){157 expect(err).to.equal('testerror');158 });159 setTimeout(done, 100);160 });161 it('auto no callback', function(done){162 async.auto({163 task1: function(callback){callback();},164 task2: ['task1', function(results, callback){callback(); done();}]165 });166 });167 it('auto concurrency no callback', function(done){168 async.auto({169 task1: function(callback){callback();},170 task2: ['task1', function(results, callback){callback(); done();}]171 }, 1);172 });173 it('auto error should pass partial results', function(done) {174 async.auto({175 task1: function(callback){176 callback(false, 'result1');177 },178 task2: ['task1', function(results, callback){179 callback('testerror', 'result2');180 }],181 task3: ['task2', function(){182 throw new Error('task3 should not be called');183 }]184 },185 function(err, results){186 expect(err).to.equal('testerror');187 expect(results.task1).to.equal('result1');188 expect(results.task2).to.equal('result2');189 done();190 });191 });192 // Issue 24 on github: https://github.com/caolan/async/issues#issue/24193 // Issue 76 on github: https://github.com/caolan/async/issues#issue/76194 it('auto removeListener has side effect on loop iteratee', function(done) {195 async.auto({196 task1: ['task3', function(/*callback*/) { done(); }],197 task2: ['task3', function(/*callback*/) { /* by design: DON'T call callback */ }],198 task3: function(callback) { callback(); }199 });200 });201 // Issue 410 on github: https://github.com/caolan/async/issues/410202 it('auto calls callback multiple times', function(done) {203 var finalCallCount = 0;204 try {205 async.auto({206 task1: function(callback) { callback(null); },207 task2: ['task1', function(results, callback) { callback(null); }]208 },209 // Error throwing final callback. This should only run once210 function() {211 finalCallCount++;212 var e = new Error('An error');213 e._test_error = true;214 throw e;215 });216 } catch (e) {217 if (!e._test_error) {218 throw e;219 }220 }221 setTimeout(function () {222 expect(finalCallCount).to.equal(1);223 done();224 }, 10);225 });226 it('auto calls callback multiple times with parallel functions', function(done) {227 async.auto({228 task1: function(callback) { setTimeout(callback,0,'err'); },229 task2: function(callback) { setTimeout(callback,0,'err'); }230 },231 // Error throwing final callback. This should only run once232 function(err) {233 expect(err).to.equal('err');234 done();235 });236 });237 // Issue 462 on github: https://github.com/caolan/async/issues/462238 it('auto modifying results causes final callback to run early', function(done) {239 async.auto({240 task1: function(callback){241 callback(null, 'task1');242 },243 task2: ['task1', function(results, callback){244 results.inserted = true;245 setTimeout(function(){246 callback(null, 'task2');247 }, 50);248 }],249 task3: function(callback){250 setTimeout(function(){251 callback(null, 'task3');252 }, 100);253 }254 },255 function(err, results){256 expect(results.inserted).to.equal(true);257 expect(results.task3).to.equal('task3');258 done();259 });260 });261 // Issue 263 on github: https://github.com/caolan/async/issues/263262 it('auto prevent dead-locks due to inexistant dependencies', function(done) {263 expect(function () {264 async.auto({265 task1: ['noexist', function(results, callback){266 callback(null, 'task1');267 }]268 });269 }).to.throw(/dependency `noexist`/);270 done();271 });272 // Issue 263 on github: https://github.com/caolan/async/issues/263273 it('auto prevent dead-locks due to cyclic dependencies', function(done) {274 expect(function () {275 async.auto({276 task1: ['task2', function(results, callback){277 callback(null, 'task1');278 }],279 task2: ['task1', function(results, callback){280 callback(null, 'task2');281 }]282 });283 }).to.throw();284 done();285 });286 // Issue 1092 on github: https://github.com/caolan/async/issues/1092287 it('extended cycle detection', function(done) {288 var task = function (name) {289 return function (results, callback) {290 callback(null, 'task ' + name);291 };292 };293 expect(function () {294 async.auto({295 a: ['c', task('a')],296 b: ['a', task('b')],297 c: ['b', task('c')]298 });299 }).to.throw();300 done();301 });302 // Issue 988 on github: https://github.com/caolan/async/issues/988303 it('auto stops running tasks on error', function(done) {304 async.auto({305 task1: function (callback) {306 callback('error');307 },308 task2: function (/*callback*/) {309 throw new Error('test2 should not be called');310 }311 }, 1, function (error) {312 expect(error).to.equal('error');313 done();314 });315 });316 it('ignores results after an error', function (done) {317 async.auto({318 task1: function (cb) {319 setTimeout(cb, 25, 'error');320 },321 task2: function (cb) {322 setTimeout(cb, 30, null);323 },324 task3: ['task2', function () {325 throw new Error("task should not have been called");326 }]327 }, function (err) {328 expect(err).to.equal('error');329 setTimeout(done, 25, null);330 });331 });332 it("does not allow calling callbacks twice", function () {333 expect(function () {334 async.auto({335 bad: function (cb) {336 cb();337 cb();338 }339 }, function () {});340 }).to.throw();341 });342 it('should handle array tasks with just a function', function (done) {343 async.auto({344 a: [function (cb) {345 cb(null, 1);346 }],347 b: ["a", function (results, cb) {348 expect(results.a).to.equal(1);349 cb();350 }]351 }, done);352 });353 it("should avoid unncecessary deferrals", function (done) {354 var isSync = true;355 async.auto({356 step1: function (cb) { cb(null, 1); },357 step2: ["step1", function (results, cb) {358 cb();359 }]360 }, function () {361 expect(isSync).to.equal(true);362 done();363 });364 isSync = false;365 });366 // Issue 1358 on github: https://github.com/caolan/async/issues/1358367 it('should report errors when a task name is an array method', function (done) {368 async.auto({369 'one': function (next) {370 next('Something bad happened here');371 },372 'filter': function (next) {373 _.delay(function () {374 next(null, 'All fine here though');375 }, 25);376 },377 'finally': ['one', 'filter', function (a, next) {378 _.defer(next);379 }]380 }, function (err) {381 expect(err).to.equal('Something bad happened here');382 _.delay(done, 30);383 });384 });385 it('should report errors when a task name is an obj prototype method', function (done) {386 async.auto({387 'one': function (next) {388 next('Something bad happened here');389 },390 'hasOwnProperty': function (next) {391 _.delay(function () {392 next(null, 'All fine here though');393 }, 25);394 },395 'finally': ['one', 'hasOwnProperty', function (a, next) {396 _.defer(next);397 }]398 }, function (err) {399 expect(err).to.equal('Something bad happened here');400 _.delay(done, 30);401 });402 });...

Full Screen

Full Screen

test_graph_flow.py

Source:test_graph_flow.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15from taskflow import exceptions as exc16from taskflow.patterns import graph_flow as gf17from taskflow import retry18from taskflow import test19from taskflow.tests import utils20def _task(name, provides=None, requires=None):21 return utils.ProvidesRequiresTask(name, provides, requires)22class GraphFlowTest(test.TestCase):23 def test_graph_flow_starts_as_empty(self):24 f = gf.Flow('test')25 self.assertEqual(len(f), 0)26 self.assertEqual(list(f), [])27 self.assertEqual(list(f.iter_links()), [])28 self.assertEqual(f.requires, set())29 self.assertEqual(f.provides, set())30 expected = 'taskflow.patterns.graph_flow.Flow: test; 0'31 self.assertEqual(str(f), expected)32 def test_graph_flow_add_nothing(self):33 f = gf.Flow('test')34 result = f.add()35 self.assertIs(f, result)36 self.assertEqual(len(f), 0)37 def test_graph_flow_one_task(self):38 f = gf.Flow('test')39 task = _task(name='task1', requires=['a', 'b'], provides=['c', 'd'])40 result = f.add(task)41 self.assertIs(f, result)42 self.assertEqual(len(f), 1)43 self.assertEqual(list(f), [task])44 self.assertEqual(list(f.iter_links()), [])45 self.assertEqual(f.requires, set(['a', 'b']))46 self.assertEqual(f.provides, set(['c', 'd']))47 def test_graph_flow_two_independent_tasks(self):48 task1 = _task(name='task1')49 task2 = _task(name='task2')50 f = gf.Flow('test').add(task1, task2)51 self.assertEqual(len(f), 2)52 self.assertItemsEqual(f, [task1, task2])53 self.assertEqual(list(f.iter_links()), [])54 def test_graph_flow_two_dependent_tasks(self):55 task1 = _task(name='task1', provides=['a'])56 task2 = _task(name='task2', requires=['a'])57 f = gf.Flow('test').add(task1, task2)58 self.assertEqual(len(f), 2)59 self.assertItemsEqual(f, [task1, task2])60 self.assertEqual(list(f.iter_links()), [61 (task1, task2, {'reasons': set(['a'])})62 ])63 self.assertEqual(f.requires, set())64 self.assertEqual(f.provides, set(['a']))65 def test_graph_flow_two_dependent_tasks_two_different_calls(self):66 task1 = _task(name='task1', provides=['a'])67 task2 = _task(name='task2', requires=['a'])68 f = gf.Flow('test').add(task1).add(task2)69 self.assertEqual(len(f), 2)70 self.assertItemsEqual(f, [task1, task2])71 self.assertEqual(list(f.iter_links()), [72 (task1, task2, {'reasons': set(['a'])})73 ])74 def test_graph_flow_two_task_same_provide(self):75 task1 = _task(name='task1', provides=['a', 'b'])76 task2 = _task(name='task2', provides=['a', 'c'])77 f = gf.Flow('test')78 f.add(task2, task1)79 self.assertEqual(set(['a', 'b', 'c']), f.provides)80 def test_graph_flow_ambiguous_provides(self):81 task1 = _task(name='task1', provides=['a', 'b'])82 task2 = _task(name='task2', provides=['a'])83 f = gf.Flow('test')84 f.add(task1, task2)85 self.assertEqual(set(['a', 'b']), f.provides)86 task3 = _task(name='task3', requires=['a'])87 self.assertRaises(exc.AmbiguousDependency, f.add, task3)88 def test_graph_flow_no_resolve_requires(self):89 task1 = _task(name='task1', provides=['a', 'b', 'c'])90 task2 = _task(name='task2', requires=['a', 'b'])91 f = gf.Flow('test')92 f.add(task1, task2, resolve_requires=False)93 self.assertEqual(set(['a', 'b']), f.requires)94 def test_graph_flow_no_resolve_existing(self):95 task1 = _task(name='task1', requires=['a', 'b'])96 task2 = _task(name='task2', provides=['a', 'b'])97 f = gf.Flow('test')98 f.add(task1)99 f.add(task2, resolve_existing=False)100 self.assertEqual(set(['a', 'b']), f.requires)101 def test_graph_flow_resolve_existing(self):102 task1 = _task(name='task1', requires=['a', 'b'])103 task2 = _task(name='task2', provides=['a', 'b'])104 f = gf.Flow('test')105 f.add(task1)106 f.add(task2, resolve_existing=True)107 self.assertEqual(set([]), f.requires)108 def test_graph_flow_with_retry(self):109 ret = retry.AlwaysRevert(requires=['a'], provides=['b'])110 f = gf.Flow('test', ret)111 self.assertIs(f.retry, ret)112 self.assertEqual(ret.name, 'test_retry')113 self.assertEqual(f.requires, set(['a']))114 self.assertEqual(f.provides, set(['b']))115 def test_graph_flow_ordering(self):116 task1 = _task('task1', provides=set(['a', 'b']))117 task2 = _task('task2', provides=['c'], requires=['a', 'b'])118 task3 = _task('task3', provides=[], requires=['c'])119 f = gf.Flow('test').add(task1, task2, task3)120 self.assertEqual(3, len(f))121 self.assertItemsEqual(list(f.iter_links()), [122 (task1, task2, {'reasons': set(['a', 'b'])}),123 (task2, task3, {'reasons': set(['c'])})124 ])125 def test_graph_flow_links(self):126 task1 = _task('task1')127 task2 = _task('task2')128 f = gf.Flow('test').add(task1, task2)129 linked = f.link(task1, task2)130 self.assertIs(linked, f)131 self.assertItemsEqual(list(f.iter_links()), [132 (task1, task2, {'manual': True})133 ])134 def test_graph_flow_links_and_dependencies(self):135 task1 = _task('task1', provides=['a'])136 task2 = _task('task2', requires=['a'])137 f = gf.Flow('test').add(task1, task2)138 linked = f.link(task1, task2)139 self.assertIs(linked, f)140 expected_meta = {141 'manual': True,142 'reasons': set(['a'])143 }144 self.assertItemsEqual(list(f.iter_links()), [145 (task1, task2, expected_meta)146 ])147 def test_graph_flow_link_from_unknown_node(self):148 task1 = _task('task1')149 task2 = _task('task2')150 f = gf.Flow('test').add(task2)151 self.assertRaisesRegexp(ValueError, 'Item .* not found to link from',152 f.link, task1, task2)153 def test_graph_flow_link_to_unknown_node(self):154 task1 = _task('task1')155 task2 = _task('task2')156 f = gf.Flow('test').add(task1)157 self.assertRaisesRegexp(ValueError, 'Item .* not found to link to',158 f.link, task1, task2)159 def test_graph_flow_link_raises_on_cycle(self):160 task1 = _task('task1', provides=['a'])161 task2 = _task('task2', requires=['a'])162 f = gf.Flow('test').add(task1, task2)163 self.assertRaises(exc.DependencyFailure, f.link, task2, task1)164 def test_graph_flow_link_raises_on_link_cycle(self):165 task1 = _task('task1')166 task2 = _task('task2')167 f = gf.Flow('test').add(task1, task2)168 f.link(task1, task2)169 self.assertRaises(exc.DependencyFailure, f.link, task2, task1)170 def test_graph_flow_dependency_cycle(self):171 task1 = _task('task1', provides=['a'], requires=['c'])172 task2 = _task('task2', provides=['b'], requires=['a'])173 task3 = _task('task3', provides=['c'], requires=['b'])174 f = gf.Flow('test').add(task1, task2)175 self.assertRaises(exc.DependencyFailure, f.add, task3)176class TargetedGraphFlowTest(test.TestCase):177 def test_targeted_flow_restricts(self):178 f = gf.TargetedFlow("test")179 task1 = _task('task1', provides=['a'], requires=[])180 task2 = _task('task2', provides=['b'], requires=['a'])181 task3 = _task('task3', provides=[], requires=['b'])182 task4 = _task('task4', provides=[], requires=['b'])183 f.add(task1, task2, task3, task4)184 f.set_target(task3)185 self.assertEqual(len(f), 3)186 self.assertItemsEqual(f, [task1, task2, task3])187 self.assertNotIn('c', f.provides)188 def test_targeted_flow_reset(self):189 f = gf.TargetedFlow("test")190 task1 = _task('task1', provides=['a'], requires=[])191 task2 = _task('task2', provides=['b'], requires=['a'])192 task3 = _task('task3', provides=[], requires=['b'])193 task4 = _task('task4', provides=['c'], requires=['b'])194 f.add(task1, task2, task3, task4)195 f.set_target(task3)196 f.reset_target()197 self.assertEqual(len(f), 4)198 self.assertItemsEqual(f, [task1, task2, task3, task4])199 self.assertIn('c', f.provides)200 def test_targeted_flow_bad_target(self):201 f = gf.TargetedFlow("test")202 task1 = _task('task1', provides=['a'], requires=[])203 task2 = _task('task2', provides=['b'], requires=['a'])204 f.add(task1)205 self.assertRaisesRegexp(ValueError, '^Item .* not found',206 f.set_target, task2)207 def test_targeted_flow_one_node(self):208 f = gf.TargetedFlow("test")209 task1 = _task('task1', provides=['a'], requires=[])210 f.add(task1)211 f.set_target(task1)212 self.assertEqual(len(f), 1)213 self.assertItemsEqual(f, [task1])214 def test_recache_on_add(self):215 f = gf.TargetedFlow("test")216 task1 = _task('task1', provides=[], requires=['a'])217 f.add(task1)218 f.set_target(task1)219 self.assertEqual(1, len(f))220 task2 = _task('task2', provides=['a'], requires=[])221 f.add(task2)222 self.assertEqual(2, len(f))223 def test_recache_on_add_no_deps(self):224 f = gf.TargetedFlow("test")225 task1 = _task('task1', provides=[], requires=[])226 f.add(task1)227 f.set_target(task1)228 self.assertEqual(1, len(f))229 task2 = _task('task2', provides=[], requires=[])230 f.add(task2)231 self.assertEqual(1, len(f))232 def test_recache_on_link(self):233 f = gf.TargetedFlow("test")234 task1 = _task('task1', provides=[], requires=[])235 task2 = _task('task2', provides=[], requires=[])236 f.add(task1, task2)237 f.set_target(task1)238 self.assertEqual(1, len(f))239 f.link(task2, task1)240 self.assertEqual(2, len(f))241 self.assertEqual(list(f.iter_links()), [242 (task2, task1, {'manual': True})...

Full Screen

Full Screen

test_base_tasks.py

Source:test_base_tasks.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# =============================================================================3# module : test_database.py4# author : Matthieu Dartiailh5# license : MIT license6# =============================================================================7from hqc_meas.tasks.api import RootTask, SimpleTask, ComplexTask8from nose.tools import assert_equal, assert_is, assert_raises, assert_not_in9from ..util import complete_line10def setup_module():11 print complete_line(__name__ + ': setup_module()', '~', 78)12def teardown_module():13 print complete_line(__name__ + ': teardown_module()', '~', 78)14def test_register_in_database1():15 # Check that the root task does write its default entries in the database16 # when instantiated.17 root = RootTask()18 assert_equal(root.get_from_database('default_path'), '')19def test_child_addition_handling1():20 # Test that adding a task to the root task is correctly handled.21 root = RootTask()22 task1 = ComplexTask(task_name='task1',23 task_database_entries={'val1': 2.0})24 root.children_task.append(task1)25 assert_equal(task1.task_depth, 1)26 assert_equal(task1.task_path, 'root')27 assert_is(task1.task_database, root.task_database)28 assert_is(task1.root_task, root)29 assert_is(task1.parent_task, root)30 assert_equal(task1.get_from_database('task1_val1'), 2.0)31 assert_equal(root.get_from_database('task1_val1'), 2.0)32def test_child_addition_handling2():33 # Test that adding a task to a complex task below the root task is34 # correctly handled.35 root = RootTask()36 task1 = ComplexTask(task_name='task1',37 task_database_entries={'val1': 2.0})38 root.children_task.append(task1)39 task2 = SimpleTask(task_name='task2',40 task_database_entries={'val2': 'r'})41 task1.children_task.append(task2)42 assert_equal(task2.task_depth, 2)43 assert_equal(task2.task_path, 'root/task1')44 assert_is(task2.task_database, root.task_database)45 assert_is(task2.root_task, root)46 assert_is(task2.parent_task, task1)47 assert_equal(task2.get_from_database('task2_val2'), 'r')48def test_child_deletion_handling1():49 # Test that adding a task to the root task is correctly handled.50 root = RootTask()51 task1 = ComplexTask(task_name='task1',52 task_database_entries={'val1': 2.0})53 root.children_task.append(task1)54 root.children_task = []55def test_giving_root1():56 # Test assembling a hierarchy and giving it a root task only later.57 root = RootTask()58 task1 = ComplexTask(task_name='task1')59 task2 = ComplexTask(task_name='task2')60 task1.children_task.append(task2)61 task3 = ComplexTask(task_name='task3')62 task2.children_task.append(task3)63 task4 = SimpleTask(task_name='task4',64 task_database_entries={'val2': 'r'})65 task3.children_task.append(task4)66 task3.access_exs = ['task4_val2']67 task2.access_exs = ['task4_val2']68 root.children_task.append(task1)69 assert_equal(task2.get_from_database('task4_val2'), 'r')70 task3.children_task = []71# assert_raises(KeyError, task2.get_from_database, 'task4_val2')72# task3.children_task.append(task4)73# assert_equal(task2.get_from_database('task4_val2'), 'r')74def test_ex_access_handling1():75 # Test adding an ex_access for an entry.76 root = RootTask()77 task1 = ComplexTask(task_name='task1')78 root.children_task.append(task1)79 task2 = SimpleTask(task_name='task2',80 task_database_entries={'val2': 'r'})81 task1.children_task.append(task2)82 assert_raises(KeyError, root.get_from_database, 'task2_val2')83 task1.add_access_exception('task2_val2')84 assert_equal(root.get_from_database('task2_val2'), 'r')85def test_ex_access_handling1bis():86 # Test adding an ex_access for a deep entry.87 root = RootTask()88 task1 = ComplexTask(task_name='task1')89 root.children_task.append(task1)90 task2 = ComplexTask(task_name='task2')91 task1.children_task.append(task2)92 task3 = SimpleTask(task_name='task3',93 task_database_entries={'val2': 'r'})94 task2.children_task.append(task3)95 assert_raises(KeyError, task2.get_from_database, 'task3_val2')96 task2.add_access_exception('task3_val2')97 assert_equal(task2.get_from_database('task3_val2'), 'r')98 assert_raises(KeyError, task1.get_from_database, 'task3_val2')99 task1.add_access_exception('task3_val2')100 assert_equal(task1.get_from_database('task3_val2'), 'r')101def test_ex_access_handling2():102 # Test removing an ex_access for an entry.103 root = RootTask()104 task1 = ComplexTask(task_name='task1')105 root.children_task.append(task1)106 task2 = SimpleTask(task_name='task2',107 task_database_entries={'val2': 'r'})108 task1.children_task.append(task2)109 task1.add_access_exception('task2_val2')110 assert_equal(root.get_from_database('task2_val2'), 'r')111 task1.remove_access_exception('task2_val2')112 assert_raises(KeyError, root.get_from_database, 'task2_val2')113def test_ex_access_handling3():114 # Test moving a task with whose one entry has an ex_access.115 root = RootTask()116 task1 = ComplexTask(task_name='task1')117 root.children_task.append(task1)118 task2 = SimpleTask(task_name='task2',119 task_database_entries={'val2': 'r'})120 task1.children_task.append(task2)121 task1.add_access_exception('task2_val2')122 assert_equal(root.get_from_database('task2_val2'), 'r')123 task1.children_task = []124 assert_raises(KeyError, root.get_from_database, 'task2_val2')125 task1.children_task.append(task2)126 assert_equal(root.get_from_database('task2_val2'), 'r')127def test_ex_access_handling4():128 # Test removing a task with whose one entry has an ex_access, adding a new129 # one and re-adding the first.130 root = RootTask()131 task1 = ComplexTask(task_name='task1')132 root.children_task.append(task1)133 task2 = SimpleTask(task_name='task2',134 task_database_entries={'val2': 'r'})135 task1.children_task.append(task2)136 task1.add_access_exception('task2_val2')137 assert_equal(root.get_from_database('task2_val2'), 'r')138 task1.children_task = []139 assert_raises(KeyError, root.get_from_database, 'task2_val2')140 task3 = SimpleTask(task_name='task3',141 task_database_entries={'val3': 'r'})142 task1.children_task.append(task3)143 task1.children_task.append(task2)144 assert_raises(KeyError, root.get_from_database, 'task2_val2')145def test_ex_access_handling5():146 # Test removing a task with whose one entry has an ex_access, and then147 # adding a different task (same name, same class, etc)148 root = RootTask()149 task1 = ComplexTask(task_name='task1')150 root.children_task.append(task1)151 task2 = SimpleTask(task_name='task2',152 task_database_entries={'val2': 'r'})153 task1.children_task.append(task2)154 task1.add_access_exception('task2_val2')155 assert_equal(root.get_from_database('task2_val2'), 'r')156 task1.children_task = []157 assert_raises(KeyError, root.get_from_database, 'task2_val2')158 task3 = SimpleTask(task_name='task2',159 task_database_entries={'val2': 'r'})160 task1.children_task.append(task3)161 assert_raises(KeyError, root.get_from_database, 'task2_val2')162def test_ex_access_handling6():163 # Test moving a task to which two access exs are linked.164 root = RootTask()165 task1 = ComplexTask(task_name='task1')166 root.children_task.append(task1)167 task2 = ComplexTask(task_name='task2')168 task1.children_task.append(task2)169 task3 = ComplexTask(task_name='task3')170 task2.children_task.append(task3)171 task4 = SimpleTask(task_name='task4',172 task_database_entries={'val2': 'r'})173 task3.children_task.append(task4)174 task3.add_access_exception('task4_val2')175 task2.add_access_exception('task4_val2')176 assert_equal(task2.get_from_database('task4_val2'), 'r')177 task3.children_task = []178 assert_raises(KeyError, task2.get_from_database, 'task4_val2')179 task3.children_task.append(task4)180 assert_equal(task2.get_from_database('task4_val2'), 'r')181def test_ex_access_handling7():182 # Test moving a task to which two access exs are linked.183 root = RootTask()184 task1 = ComplexTask(task_name='task1')185 root.children_task.append(task1)186 task2 = ComplexTask(task_name='task2')187 task1.children_task.append(task2)188 task3 = ComplexTask(task_name='task3')189 task2.children_task.append(task3)190 task4 = SimpleTask(task_name='task4',191 task_database_entries={'val2': 'r'})192 task3.children_task.append(task4)193 task3.add_access_exception('task4_val2')194 task2.add_access_exception('task4_val2')195 assert_equal(task2.get_from_database('task4_val2'), 'r')196 task3.remove_access_exception('task4_val2')...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var assert = require('assert');4var task1 = require('./1');5var task2 = require('./2');6var input1 = String(fs.readFileSync(path.resolve(__dirname, 'test-input-1.txt')));7var input2 = String(fs.readFileSync(path.resolve(__dirname, 'test-input-2.txt')));8var DELIMITER = '~~~~~~';9describe('Day 18', () => {10 it('Task 1', () => {11 var maps = input1.split(DELIMITER);12 var map0 = task1.convertToMap(maps[0]);13 var map1 = task1.convertToMap(maps[1]);14 var map2 = task1.convertToMap(maps[2]);15 var map3 = task1.convertToMap(maps[3]);16 var map4 = task1.convertToMap(maps[4]);17 assert.equal(task1.countOn(map0), 15);18 assert.equal(task1.countOn(map1), 11);19 assert.equal(task1.countOn(map2), 8);20 assert.equal(task1.countOn(map3), 4);21 assert.equal(task1.countOn(map4), 4);22 assert.deepEqual(task1.animate(map0, 0), map0);23 assert.deepEqual(task1.animate(map0, 1), map1);24 assert.deepEqual(task1.animate(map0, 2), map2);25 assert.deepEqual(task1.animate(map0, 4), map4);26 assert.deepEqual(task1.animate(map1, 2), map3);27 assert.deepEqual(task1.animate(map2, 1), map3);28 assert.deepEqual(task1.animate(map2, 2), map4);29 });30 it('Task 2', () => {31 var maps = input2.split(DELIMITER);32 var map0 = task2.convertToMap(maps[0]);33 var map1 = task2.convertToMap(maps[1]);34 var map2 = task2.convertToMap(maps[2]);35 var map3 = task2.convertToMap(maps[3]);36 var map4 = task2.convertToMap(maps[4]);37 var map5 = task2.convertToMap(maps[5]);38 assert.equal(task2.countOn(map0), 17);39 assert.equal(task2.countOn(map1), 18);40 assert.equal(task2.countOn(map2), 18);41 assert.equal(task2.countOn(map3), 18);42 assert.equal(task2.countOn(map4), 14);43 assert.equal(task2.countOn(map5), 17);44 assert.deepEqual(task2.animate(map0, 0), map0);45 assert.deepEqual(task2.animate(map0, 1), map1);46 assert.deepEqual(task2.animate(map0, 2), map2);47 assert.deepEqual(task2.animate(map0, 4), map4);48 assert.deepEqual(task2.animate(map0, 5), map5);49 assert.deepEqual(task2.animate(map1, 2), map3);50 assert.deepEqual(task2.animate(map2, 1), map3);51 assert.deepEqual(task2.animate(map2, 2), map4);52 assert.deepEqual(task2.animate(map2, 3), map5);53 });...

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