Best Python code snippet using molecule_python
test-if.js
Source:test-if.js
...11 'output = -1;',12 'if (args[0] > args [1])',13 ' output = args[0];'14 ];15 verifier = helper.verifier(__filename, code);16 cb(null);17 },18 "should cover then path": function (test) {19 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1, 3: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });20 test.done();21 },22 "should cover else path": function (test) {23 verifier.verify(test, [ 10, 20 ], -1, { lines: { 1: 1, 2: 1, 3: 0 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });24 test.done();25 }26 },27 "as a block": {28 setUp: function (cb) {29 code = [30 'output = -1;',31 'if (args[0] > args [1]) {',32 ' output = args[0];',33 '}'34 ];35 verifier = helper.verifier(__filename, code);36 cb();37 },38 "should cover then path": function (test) {39 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1, 3: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });40 test.done();41 },42 "should cover else path": function (test) {43 verifier.verify(test, [ 10, 20 ], -1, { lines: { 1: 1, 2: 1, 3: 0 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });44 test.done();45 }46 },47 "on a single line": {48 "as statement": {49 setUp: function (cb) {50 code = [51 'output = -1;',52 'if (args[0] > args [1]) output = args[0];'53 ];54 verifier = helper.verifier(__filename, code);55 cb();56 },57 "should cover then path": function (test) {58 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });59 test.done();60 },61 "should cover else path": function (test) {62 verifier.verify(test, [ 10, 20 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });63 test.done();64 }65 },66 "as block": {67 setUp: function (cb) {68 code = [69 'output = -1;',70 'if (args[0] > args [1]) { output = args[0]; }'71 ];72 verifier = helper.verifier(__filename, code);73 cb();74 },75 "should cover then path": function (test) {76 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });77 test.done();78 },79 "should cover else path": function (test) {80 verifier.verify(test, [ 10, 20 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });81 test.done();82 }83 }84 }85 },86 "with a simple if-else": {87 "as a statement": {88 setUp: function (cb) {89 code = [90 'if (args[0] > args [1])',91 ' output = args[0];',92 'else',93 ' output = args[1];'94 ];95 verifier = helper.verifier(__filename, code);96 cb(null);97 },98 "should cover then path": function (test) {99 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1, 4: 0 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });100 test.done();101 },102 "should cover else path": function (test) {103 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1, 2: 0, 4: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });104 test.done();105 }106 },107 "as a block": {108 setUp: function (cb) {109 code = [110 'if (args[0] > args [1]) {',111 ' output = args[0];',112 '} else {',113 ' output = args[1];',114 '}'115 ];116 verifier = helper.verifier(__filename, code);117 cb();118 },119 "should cover then path": function (test) {120 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1, 4: 0 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });121 test.done();122 },123 "should cover else path": function (test) {124 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1, 2: 0, 4: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });125 test.done();126 }127 },128 "on a single line": {129 "as statement": {130 setUp: function (cb) {131 code = [132 'if (args[0] > args [1]) output = args[0]; else output = args[1];'133 ];134 verifier = helper.verifier(__filename, code);135 cb();136 },137 "should cover then path": function (test) {138 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });139 test.done();140 },141 "should cover else path": function (test) {142 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });143 test.done();144 }145 },146 "as block": {147 setUp: function (cb) {148 code = [149 'if (args[0] > args [1]) { output = args[0]; } else { output = args[1]; }'150 ];151 verifier = helper.verifier(__filename, code);152 cb();153 },154 "should cover then path": function (test) {155 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });156 test.done();157 },158 "should cover else path": function (test) {159 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });160 test.done();161 }162 },163 "as mixed with then-block": {164 setUp: function (cb) {165 code = [166 'if (args[0] > args [1]) { output = args[0]; } else output = args[1];'167 ];168 verifier = helper.verifier(__filename, code);169 cb();170 },171 "should cover then path": function (test) {172 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });173 test.done();174 },175 "should cover else path": function (test) {176 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });177 test.done();178 }179 },180 "as mixed with else-block": {181 setUp: function (cb) {182 code = [183 'if (args[0] > args [1]) output = args[0]; else { output = args[1]; }'184 ];185 verifier = helper.verifier(__filename, code);186 cb();187 },188 "should cover then path": function (test) {189 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });190 test.done();191 },192 "should cover else path": function (test) {193 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });194 test.done();195 }196 }197 }198 },199 "with nested ifs": {200 "without an else": {201 "and no blocks": {202 setUp: function (cb) {203 code = [204 'output = -1;',205 'if (args[0] > args[1]) if (args[1] > args[2]) output = args[2];'206 ];207 verifier = helper.verifier(__filename, code);208 cb();209 },210 "should cover first else and nothing below": function (test) {211 verifier.verify(test, [ 10, 20, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0 } });212 test.done();213 },214 "should cover first then": function (test) {215 verifier.verify(test, [ 20, 10, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 0 } });216 test.done();217 },218 "should cover first then and second then": function (test) {219 verifier.verify(test, [ 20, 10, 5 ], 5, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1 } });220 test.done();221 }222 },223 "and blocks": {224 setUp: function (cb) {225 code = [226 'output = -1;',227 'if (args[0] > args[1]) { if (args[1] > args[2]) { output = args[2]; } }'228 ];229 verifier = helper.verifier(__filename, code);230 cb();231 },232 "should cover first else and nothing below": function (test) {233 verifier.verify(test, [ 10, 20, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0 } });234 test.done();235 },236 "should cover first then": function (test) {237 verifier.verify(test, [ 20, 10, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 0 } });238 test.done();239 },240 "should cover first then and second then": function (test) {241 verifier.verify(test, [ 20, 10, 5 ], 5, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1 } });242 test.done();243 }244 }245 },246 "with elses": {247 "and no blocks": {248 setUp: function (cb) {249 code = [250 'output = -1;',251 'if (args[0] > args[1]) if (args[1] > args[2]) output = args[2]; else output = args[1];'252 ];253 verifier = helper.verifier(__filename, code);254 cb();255 },256 "should cover first else and nothing below": function (test) {257 verifier.verify(test, [ 10, 20, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0 } });258 test.done();259 },260 "should cover first then": function (test) {261 verifier.verify(test, [ 20, 10, 15 ], 10, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 0, '5': 1 } });262 test.done();263 },264 "should cover first then and second then": function (test) {265 verifier.verify(test, [ 20, 10, 5 ], 5, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1, '5': 0 } });266 test.done();267 }268 },269 "including else ifs with blocks": {270 setUp: function (cb) {271 code = [272 'if (args[0] < args[1]) {',273 ' output = args[0];',274 '} else if (args[1] < args[2]) {',275 ' output = args[1];',276 '} else if (args[2] < args[3]) {',277 ' output = args[2];',278 '} else {',279 ' output = args[3];',280 '}'281 ];282 verifier = helper.verifier(__filename, code);283 cb();284 },285 "should cover all else paths": function (test) {286 verifier.verify(test, [ 4, 3, 2, 1 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 0, 8: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 0, '7': 1 } });287 test.done();288 },289 "should cover one then path": function (test) {290 verifier.verify(test, [ 4, 3, 1, 2 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 1, 8: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 1, '7': 0 } });291 test.done();292 },293 "should cover upper then paths": function (test) {294 verifier.verify(test, [ 4, 2, 3, 1 ], 2, { lines: { 1: 1, 2: 0, 3: 1, 4: 1, 5: 0, 6: 0, 8: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 1, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 1, '5': 0, '6': 0, '7': 0 } });295 test.done();296 },297 "should cover uppermost then paths": function (test) {298 verifier.verify(test, [ 1, 2, 3, 1 ], 1, { lines: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 0, 6: 0, 8: 0 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0 } });299 test.done();300 }301 },302 "including else ifs without blocks": {303 setUp: function (cb) {304 code = [305 'if (args[0] < args[1])',306 ' output = args[0];',307 'else if (args[1] < args[2])',308 ' output = args[1];',309 'else if (args[2] < args[3])',310 ' output = args[2];',311 'else',312 ' output = args[3];'313 ];314 verifier = helper.verifier(__filename, code);315 cb();316 },317 "should cover all else paths": function (test) {318 verifier.verify(test, [ 4, 3, 2, 1 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 0, 8: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 0, '7': 1 } });319 test.done();320 },321 "should cover one then path": function (test) {322 verifier.verify(test, [ 4, 3, 1, 2 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 1, 8: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 1, '7': 0 } });323 test.done();324 },325 "should cover upper then paths": function (test) {326 verifier.verify(test, [ 4, 2, 3, 1 ], 2, { lines: { 1: 1, 2: 0, 3: 1, 4: 1, 5: 0, 6: 0, 8: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 1, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 1, '5': 0, '6': 0, '7': 0 } });327 test.done();328 },329 "should cover uppermost then paths": function (test) {330 verifier.verify(test, [ 1, 2, 3, 1 ], 1, { lines: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 0, 6: 0, 8: 0 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0 } });331 test.done();332 }333 },334 "including else ifs without blocks (compact)": {335 setUp: function (cb) {336 code = [337 'if (args[0] < args[1]) output = args[0]; else if (args[1] < args[2]) output = args[1]; else if (args[2] < args[3]) output = args[2]; else output = args[3];'338 ];339 verifier = helper.verifier(__filename, code);340 cb();341 },342 "should cover all else paths": function (test) {343 verifier.verify(test, [ 4, 3, 2, 1 ], 1, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 0, '7': 1 } });344 test.done();345 },346 "should cover one then path": function (test) {347 verifier.verify(test, [ 4, 3, 1, 2 ], 1, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 1, '7': 0 } });348 test.done();349 },350 "should cover upper then paths": function (test) {351 verifier.verify(test, [ 4, 2, 3, 1 ], 2, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 1, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 1, '5': 0, '6': 0, '7': 0 } });352 test.done();353 },354 "should cover uppermost then paths": function (test) {355 verifier.verify(test, [ 1, 2, 3, 1 ], 1, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0 } });356 test.done();357 }358 },359 "including else ifs without blocks (modified)": {360 setUp: function (cb) {361 code = [362 'output = args[3]; if (args[0] < args[1])',363 ' output = args[0];',364 'else if (args[1] < args[2])',365 ' output = args[1];',366 'else if (args[2] < args[3])',367 ' output = args[2];'368 ];369 verifier = helper.verifier(__filename, code);370 cb();371 },372 "should cover all else paths": function (test) {373 verifier.verify(test, [ 4, 3, 2, 1 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1, '5': 0, '6': 1, '7': 0 } });374 test.done();375 },376 "should cover one then path": function (test) {377 verifier.verify(test, [ 4, 3, 1, 2 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1, '5': 0, '6': 1, '7': 1 } });378 test.done();379 },380 "should cover upper then paths": function (test) {381 verifier.verify(test, [ 4, 2, 3, 1 ], 2, { lines: { 1: 1, 2: 0, 3: 1, 4: 1, 5: 0, 6: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 1, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1, '5': 1, '6': 0, '7': 0 } });382 test.done();383 },...
test-statement.js
Source:test-statement.js
...9 code = [10 'var x = args[0] > 5 ? args[0] : "undef";',11 'output = x;'12 ];13 verifier = helper.verifier(__filename, code);14 cb();15 },16 "should cover line and one branch": function (test) {17 verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 1 }, branches: { 1: [1, 0 ]}, functions: {}, statements: { 1: 1, 2: 1 } });18 test.done();19 },20 "should cover line and other branch": function (test) {21 verifier.verify(test, [ 1 ], "undef", { lines: { 1: 1, 2: 1 }, branches: { 1: [ 0, 1 ]}, functions: {}, statements: { 1: 1, 2: 1 } });22 test.done();23 }24 },25 "with no filename": {26 setUp: function (cb) {27 code = [28 'output = args[0];'29 ];30 verifier = helper.verifier(null, code, { debug: true, walkDebug: true });31 cb();32 },33 "should not barf in setup": function (test) {34 verifier.verify(test, [ 1 ], 1, { lines: { 1: 1 }, branches: {}, functions: {}, statements: { 1: 1 } });35 test.done();36 }37 },38 "with a windows style file path": {39 setUp: function (cb) {40 code = [41 'var x = args[0] > 5 ? args[0] : "undef";',42 'output = x;'43 ];44 verifier = helper.verifier("c:\\a\\b\\c\\d\\e.js", code);45 cb();46 },47 "should have correct key in coverage variable": function (test) {48 verifier.verify(test, [ 1 ], "undef", { lines: { 1: 1, 2: 1 }, branches: { 1: [ 0, 1 ]}, functions: {}, statements: { 1: 1, 2: 1 } });49 var coverage = verifier.getCoverage(),50 key = Object.keys(coverage)[0];51 test.equals("c:\\a\\b\\c\\d\\e.js", key);52 test.done();53 }54 },55 "with junk code": {56 setUp: function (cb) {57 code = [58 'output = args[0] : 1 : 2;'59 ];60 verifier = helper.verifier(null, code, { debug: true, walkDebug: true });61 cb();62 },63 "should have verification errors": function (test) {64 verifier.verifyError(test);65 test.done();66 }67 },68 "with code that is not a string": {69 "should have verification errors": function (test) {70 test.throws(function () {71 var instrumenter = new Instrumenter();72 instrumenter.instrumentSync({}, 'foo.js');73 }, Error, 'Code must be a string');74 test.done();75 }76 },77 "with shebang code": {78 setUp: function (cb) {79 code = [80 '#!/usr/bin/env node',81 'var x = args[0] > 5 ? args[0] : "undef";',82 'output = x;'83 ];84 verifier = helper.verifier(__filename, code);85 cb();86 },87 "should cover line and one branch": function (test) {88 verifier.verify(test, [ 10 ], 10, { lines: { 2: 1, 3: 1 }, branches: { 1: [1, 0 ]}, functions: {}, statements: { 1: 1, 2: 1 } });89 test.done();90 },91 "should cover line and other branch": function (test) {92 verifier.verify(test, [ 1 ], "undef", { lines: { 2: 1, 3: 1 }, branches: { 1: [ 0, 1 ]}, functions: {}, statements: { 1: 1, 2: 1 } });93 test.done();94 }95 },96 "with source code packed in": {97 setUp: function (cb) {98 code = [99 'var x = args[0] > 5 ? args[0] : "undef";',100 'output = x;'101 ];102 verifier = helper.verifier(__filename, code, { embedSource: true, coverageVariable: null });103 cb();104 },105 "coverage should have code packed in": function (test) {106 verifier.verifyNoError(test);107 verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 1 }, branches: { 1: [1, 0 ]}, functions: {}, statements: { 1: 1, 2: 1 } });108 var cov = verifier.getCoverage(),109 fileCov = cov[Object.keys(cov)[0]];110 test.ok(fileCov.code);111 test.done();112 }113 },114 "with code having a return statement on mainline": {115 setUp: function (cb) {116 code = [117 'return 10;'118 ];119 verifier = helper.verifier(__filename, code);120 cb();121 },122 "should pass coverage": function (test) {123 verifier.verifyNoError(test);124 test.done();125 }126 },127 "with code having a return statement on mainline and no autowrap": {128 setUp: function (cb) {129 code = [130 'return 10;'131 ];132 verifier = helper.verifier(__filename, code, { noAutoWrap: true });133 cb();134 },135 "should fail coverage": function (test) {136 verifier.verifyError(test);137 test.done();138 }139 },140 "with no mainline returns and no autowrap": {141 setUp: function (cb) {142 code = [143 '#!/usr/bin/env node',144 'var x = args[0] > 5 ? args[0] : "undef";',145 'output = x;'146 ];147 verifier = helper.verifier(__filename, code, { noAutoWrap: true });148 cb();149 },150 "should cover line and one branch": function (test) {151 verifier.verify(test, [ 10 ], 10, { lines: { 2: 1, 3: 1 }, branches: { 1: [1, 0 ]}, functions: {}, statements: { 1: 1, 2: 1 } });152 test.done();153 },154 "should cover line and other branch": function (test) {155 verifier.verify(test, [ 1 ], "undef", { lines: { 2: 1, 3: 1 }, branches: { 1: [ 0, 1 ]}, functions: {}, statements: { 1: 1, 2: 1 } });156 test.done();157 }158 }...
verifierdb.py
Source:verifierdb.py
1# Author: Trevor Perrin2# See the LICENSE file for legal information regarding use of this file.3"""Class for storing SRP password verifiers."""4from .utils.cryptomath import *5from .utils.compat import *6from tlslite import mathtls7from .basedb import BaseDB8class VerifierDB(BaseDB):9 """This class represent an in-memory or on-disk database of SRP10 password verifiers.11 A VerifierDB can be passed to a server handshake to authenticate12 a client based on one of the verifiers.13 This class is thread-safe.14 """15 def __init__(self, filename=None):16 """Create a new VerifierDB instance.17 @type filename: str18 @param filename: Filename for an on-disk database, or None for19 an in-memory database. If the filename already exists, follow20 this with a call to open(). To create a new on-disk database,21 follow this with a call to create().22 """23 BaseDB.__init__(self, filename, "verifier")24 def _getItem(self, username, valueStr):25 (N, g, salt, verifier) = valueStr.split(" ")26 N = bytesToNumber(a2b_base64(N))27 g = bytesToNumber(a2b_base64(g))28 salt = a2b_base64(salt)29 verifier = bytesToNumber(a2b_base64(verifier))30 return (N, g, salt, verifier)31 def __setitem__(self, username, verifierEntry):32 """Add a verifier entry to the database.33 @type username: str34 @param username: The username to associate the verifier with.35 Must be less than 256 characters in length. Must not already36 be in the database.37 @type verifierEntry: tuple38 @param verifierEntry: The verifier entry to add. Use39 L{tlslite.verifierdb.VerifierDB.makeVerifier} to create a40 verifier entry.41 """42 BaseDB.__setitem__(self, username, verifierEntry)43 def _setItem(self, username, value):44 if len(username)>=256:45 raise ValueError("username too long")46 N, g, salt, verifier = value47 N = b2a_base64(numberToByteArray(N))48 g = b2a_base64(numberToByteArray(g))49 salt = b2a_base64(salt)50 verifier = b2a_base64(numberToByteArray(verifier))51 valueStr = " ".join( (N, g, salt, verifier) )52 return valueStr53 def _checkItem(self, value, username, param):54 (N, g, salt, verifier) = value55 x = mathtls.makeX(salt, username, param)56 v = powMod(g, x, N)57 return (verifier == v)58 def makeVerifier(username, password, bits):59 """Create a verifier entry which can be stored in a VerifierDB.60 @type username: str61 @param username: The username for this verifier. Must be less62 than 256 characters in length.63 @type password: str64 @param password: The password for this verifier.65 @type bits: int66 @param bits: This values specifies which SRP group parameters67 to use. It must be one of (1024, 1536, 2048, 3072, 4096, 6144,68 8192). Larger values are more secure but slower. 2048 is a69 good compromise between safety and speed.70 @rtype: tuple71 @return: A tuple which may be stored in a VerifierDB.72 """73 usernameBytes = bytearray(username, "utf-8")74 passwordBytes = bytearray(password, "utf-8")75 return mathtls.makeVerifier(usernameBytes, passwordBytes, bits)...
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!!