Best Python code snippet using tox_python
baseClosedLib.js
Source:baseClosedLib.js
1function __eqeqInt2([env, y]){2 return env["x"] == y;3}4function __noteqInt2([env, y]){5 return env["x"] != y;6}7const eqInt = {8 "==": mkClosure(function([_,x]) { return setEnv("x", x, mkClosure(__eqeqInt2))}),9 "/=": mkClosure(function([_,x]) { return setEnv("x", x, mkClosure(__noteqInt2))})10 }11const eqDouble = {12 "==": mkClosure(function([_,x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] == y; }))}),13 "/=": mkClosure(function([_,x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] != y; }))})14 }15function __eqeqChar2([env, y]){16 return env["x"] == y;17}18function __noteqChar2([env, y]){19 return env["x"] != y;20}21const eqChar = {22 "==": mkClosure(function([_,x]) { return setEnv("x", x, mkClosure(__eqeqChar2))}),23 "/=": mkClosure(function([_,x]) { return setEnv("x", x, mkClosure(__noteqChar2))})24 }25const ordChar = {26 ">": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] > y }))}),27 "<": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] < y }))}),28 ">=": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] >= y }))}),29 "<=": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] <= y }))}),30 "==": eqChar["=="],31 "/=": eqChar["/="]32 }33function __plusInt2([env, y]){34 return env["x"] + y; 35}36function __mulInt2([env, y]){37 return env["x"] * y; 38}39function __subInt2([env, y]){40 return env["x"] - y; 41}42const ordDouble = {43 ">": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] > y }))}),44 "<": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] < y }))}),45 ">=": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] >= y }))}),46 "<=": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] <= y }))}),47 "==": eqDouble["=="],48 "/=": eqDouble["/="]49}50const ordInt = {51 ">": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] > y }))}),52 "<": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] < y }))}),53 ">=": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] >= y }))}),54 "<=": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] <= y }))}),55 "==": eqInt["=="],56 "/=": eqInt["/="]57}58const numInt = {59 "+": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(__plusInt2))}),60 "*": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(__mulInt2))}),61 "-": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(__subInt2))}),62 "fromInteger": mkClosure(function([_, x]) { return x; })63 }64 const fractionalInt = {65 "+": numInt["+"],66 "*": numInt["*"],67 "-": numInt["-"],68 "/": mkClosure(function([_,x]) { return setEnv("x", x, mkClosure(function([env, y]) { return ~~(env["x"]/y); }))}),69 "fromInteger": numInt["fromInteger"],70 "fromRational": mkClosure(function([_, x]) { return Math.floor(x); })71 }72 const integralInt = {73 "+": numInt["+"],74 "*": numInt["*"],75 "-": numInt["-"],76 "fromInteger": numInt["fromInteger"],77 "mod": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] % y; }))}),78 }79 const numDouble = {80 "+": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] + y; }))}),81 "*": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] * y; }))}),82 "-": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] - y; }))}),83 "fromInteger": mkClosure(function([_, x]) { return x; })84 }85 const floatingDouble = {86 "cos": mkClosure(function([_, x]){ return Math.cos(x) }),87 "sin": mkClosure(function([_, x]){ return Math.sin(x) }),88 "sqrt": mkClosure(function([_, x]){ return Math.sqrt(x) }),89 "log": mkClosure(function([_, x]){ return Math.log(x) }),90 "exp": mkClosure(function([_, x]){ return Math.exp(x) })91 }92 const numTuple2 = mkClosure(function([_, instA]) {93 return mkClosure(function([_, instB]) {94 const addA = instA["+"];95 const addB = instB["+"];96 const subA = instA["-"];97 const subB = instB["-"];98 const mulA = instA["*"];99 return {100 "fromInteger": mkClosure(function([_, x]) { return [x, x]; }),101 "+": mkClosure(function([_, [x1, y1]]){ 102 return setEnv("x1y1", [x1, y1], mkClosure(function([env, [x2, y2]]) { 103 return [applyClosure(applyClosure(addA, env["x1y1"][0]), x2), 104 applyClosure(applyClosure(addB, env["x1y1"][1]), y2)] })) }),105 "-": mkClosure(function([_, [x1, y1]]){ 106 return setEnv("x1y1", [x1, y1], mkClosure(function([env, [x2, y2]]) { 107 return [applyClosure(applyClosure(subA, env["x1y1"][0]), x2), 108 applyClosure(applyClosure(subB, env["x1y1"][1]), y2)] })) }),109 "*": mkClosure(function([_, [x1, y1]]){ 110 return setEnv("x1y1", [x1, y1], mkClosure(function([env, [x2, y2]]) { 111 112 let ret1 = applyClosure(mulA, env["x1y1"][0])113 let ret2 = applyClosure(ret1, x2)114 let ret3 = applyClosure(subA, ret2)115 let ret4 = applyClosure(mulA, env["x1y1"][1])116 let ret5 = applyClosure(ret4, y2)117 let ret6 = applyClosure(ret3, ret5)118 let ret7 = applyClosure(mulA, env["x1y1"][0])119 let ret8 = applyClosure(ret7, y2)120 let ret9 = applyClosure(addA, ret8)121 let ret10 = applyClosure(mulA, env["x1y1"][1])122 let ret11 = applyClosure(ret10, x2)123 let ret12 = applyClosure(ret9, ret11)124 return [ret6, ret12];125 } ))126 })127 }128 })129 })130 131 const fractionalDouble = {132 "+": numDouble["+"],133 "*": numDouble["*"],134 "-": numDouble["-"],135 "/": mkClosure(function([_, x]) { return setEnv("x", x, mkClosure(function([env, y]) { return env["x"] / y; }))}),136 "fromInteger": numDouble["fromInteger"],137 "fromRational": mkClosure(function([_, x]) { return x; })138 }139const __liftA2 = mkClosure(function([_, inst]) { return inst["<*>"]; }) 140const __eqeq = mkClosure(function([_, inst]) { return inst["=="]; })141const __noteq = mkClosure(function([_, inst]) { return inst["/="]; })142const __lt = mkClosure(function([_, inst]) { return inst["<"]; })143const __lteq = mkClosure(function([_, inst]) { return inst["<="]; })144const __gt = mkClosure(function([_, inst]) { return inst[">"]; })145const __gteq = mkClosure(function([_, inst]) { return inst[">="]; })146const fromInteger = mkClosure(function([_, inst]) { return inst["fromInteger"]; })147const fromRational = mkClosure(function([_, inst]) { return inst["fromRational"]; })148const __mod = mkClosure(function([_, inst]) { return inst["mod"]; });149const __add = mkClosure(function([_, inst]) { return inst["+"]; });150const __sub = mkClosure(function([_, inst]) { return inst["-"]; });151const __mul = mkClosure(function([_, inst]) { return inst["*"]; });152const __div = mkClosure(function([_, inst]) { return inst["/"]; });153const __pow = mkClosure(function([_, instA]) {154 return mkClosure(function([_, instB]){155 return mkClosure(function([_, x]){156 return setEnv("x", x, mkClosure(function([env, y]){157 return Math.pow(env["x"], y);158 }))159 })160 })161})162const toDouble = mkClosure(function([_, x]) { return x + 0.0; })163const truncate = mkClosure(function([_, instA]) { 164 return mkClosure(function([_, instB]){ 165 return mkClosure(function([_, x]) { return Math.floor(x); }); }); });166const sin = mkClosure(function([_, inst]) { return inst["sin"]; })167const cos = mkClosure(function([_, inst]) { return inst["cos"]; })168const log = mkClosure(function([_, inst]) { return inst["log"]; })169const sqrt = mkClosure(function([_, inst]) { return inst["sqrt"]; })170const exp = mkClosure(function([_, inst]) { return inst["exp"]; })171function range_3([env, end]) {172 return Array(end - env["start"] + 1).fill(env["start"]).map((x, y) => applyClosure(env["f"], (x + y)))173}174function range_2([env, start]) {175 return setEnv("f", env["f"], setEnv("start", start, mkClosure(range_3)))176}177function range_1([_, f]) {178 return setEnv("f", f, mkClosure(range_2))179}180const range = mkClosure(range_1)181const isEmptyList = mkClosure(function([_, xs]) {182 return xs.length == 0;183 })184const head = mkClosure(function([_, xs]) {185 return xs[0];186 })187const tail = mkClosure(function([_, xs]) {188 return xs.slice(1);189 })190const ord = mkClosure(function([_, ch]) {191 return ch.charCodeAt(0);192 })193const toCharList = mkClosure(function([_, s]) {194 return Array.from(s);195 })196const fromCharList = mkClosure(function([_, xs]) {197 return xs.join("");198 })199const unlines = mkClosure(function([_, xs]) {200 return xs.join("\n");201 })202const mkParser = mkClosure(function([_, f]) {203 return f;204 })205const runParser = mkClosure(function([_, m]) {206 return m;207 })208const functorParser = {209 "fmap": mkClosure(function ([_, f]) {210 return setEnv("f", f, mkClosure(function([env1, m]){211 return setEnv("m", m, setEnv("f", env1["f"], mkClosure(function([env2, inp]){212 return applyClosure(env2["m"], inp).map(([x,rest]) => [applyClosure(env2["f"], x), rest]);213 })))214 }))215 })216}217const applicativeParser = {218 "fmap" : functorParser["fmap"],219 "pure": mkClosure(function([_, x]) {220 return setEnv("x", x, mkClosure(function([env, inp]) {221 return [[env["x"], inp]];222 }))223 }),224 // data Parser a = String -> [(a, String)]225 "<*>": mkClosure(function([_, mf]) {226 return setEnv("mf", mf, mkClosure(function([env, mx]){227 return setEnv("mf", env["mf"], setEnv("mx", mx, mkClosure(function([env2, inp]){228 return Array.prototype.concat.apply([],229 applyClosure(env2["mf"], inp).map(([f, rest]) => 230 applyClosure(applyClosure(applyClosure(functorParser["fmap"], f), env2["mx"]), rest) ))231 })))232 }))233 })234}235const monadParser = {236 "pure": applicativeParser["pure"],237 ">>=": mkClosure(function([_, m]) {238 return setEnv("m", m, mkClosure(function([env1, f]){239 return setEnv("f", f, setEnv("m", env1["m"], mkClosure(function([env2, inp]){240 return Array.prototype.concat.apply([], applyClosure(env2["m"], inp).map(([x,rest]) => applyClosure(applyClosure(env2["f"], x), rest)));241 })))242 }))243 })244 }245const functorList = {246 "fmap": mkClosure(function ([_, f]) {247 return setEnv("f", f, mkClosure(function ([env, m]) {248 return m.map(x => applyClosure(env["f"], x))249 }))250 })251}252const applicativeList = {253 "fmap": functorList["fmap"],254 "pure": mkClosure(function([_, x]) { return [x]; }),255 "<*>": mkClosure(function([_, mf]) {256 return setEnv("mf", mf, mkClosure(function([env, mx]){257 return Array.prototype.concat.apply([], env["mf"].map(f => mx.map(x => applyClosure(f, x))))258 }))259 })260 }261const monadList = {262 "pure": applicativeList["pure"],263 ">>=": mkClosure(function([_, xs]) {264 return setEnv("xs", xs, mkClosure(function([env, f]){265 return Array.prototype.concat.apply([], env["xs"].map(x => applyClosure(f, x)));266 }))267 })268 }269const __bind = mkClosure(function([_, inst]) { return inst[">>="]; })270const pure = mkClosure(function([_, inst]) { return inst["pure"]; })271const fmap = mkClosure(function([_, inst]) { return inst["fmap"]; })272const __colon = mkClosure(function([_, x]) {273 return setEnv("x", x, mkClosure(function([env, xs]) {274 const ys = xs.slice();275 ys.unshift(env["x"]);276 return ys;277 }))278 })279const split = mkClosure(function ([_, size]) {280 return setEnv("size", size, mkClosure(function ([env, array]) {281 let result = []282 if (env["size"] > 0 && array.length > 0) { 283 for (let i = 0; i < array.length; i += env["size"]) {284 let chunk = array.slice(i, i + env["size"])285 result.push(chunk)286 }287 }288 return result289 }))290})291const __and = mkClosure(function([_, x]) {292 return setEnv("x", x, mkClosure(function([env, y]) {293 return env["x"] && y;294 }))295})296const __or = mkClosure(function([_, x]) {297 return setEnv("x", x, mkClosure(function([env, y]) {298 return env["x"] || y;299 }))300})301const display = mkClosure(function([_, imageData]) {302 return new Promise((resolve, reject) => {303 clearPanels();304 const canvas = document.getElementById('canvas');305 const ctx = canvas.getContext('2d');306 ctx.clearRect(0, 0, canvas.width, canvas.height);307 canvas.width = imageData.length;308 canvas.height = imageData.length; 309 canvas.style.display = "block";310 const buffer = ctx.createImageData(imageData.length - 1, imageData.length - 1);311 var index = 0;312 for(let y = 0; y < imageData.length; y++){313 for(let x = 0; x < imageData[y].length; x++){314 buffer.data[index++] = imageData[y][x][0];315 buffer.data[index++] = imageData[y][x][1];316 buffer.data[index++] = imageData[y][x][2];317 buffer.data[index++] = 255;318 }319 }320 try { 321 ctx.putImageData(buffer, 0, 0);322 } catch(e) {323 console.log(e);324 }325 resolve({});326 })327});328const renderPlot = mkClosure(function([_, z1]) {329 return new Promise((resolve, reject) => {330 clearPanels();331 plotChart = document.getElementById("plotlyChart");332 plotChart.style.display = "block"333 Plotly.newPlot("plotlyChart", [{z: z1, type: 'surface'}]);334 resolve({});335 });336});337const renderTimeSeries = mkClosure(function([_, vs]) {338 return new Promise((resolve, reject) => {339 clearPanels();340 plotChart = document.getElementById("plotlyChart");341 plotChart.style.display = "block"342 Plotly.newPlot("plotlyChart", vs.map(([s, xs, ys]) => {343 const ys1 = ys.map(x => x == 0 ? null : x)344 return {x: xs, y: ys1, name: s, type: 'scatter'}345 }), {showlegend: true});346 resolve({});347 });348});349const renderBarChart = mkClosure(function([_, vs]) {350 return new Promise((resolve, reject) => {351 clearPanels();352 plotChart = document.getElementById("plotlyChart");353 plotChart.style.display = "block"354 Plotly.newPlot("plotlyChart", vs.map(([s, xs, ys]) => {355 const ys1 = ys.map(x => x == 0 ? null : x)356 return {x: xs, y: ys1, name: s, type: 'bar'}357 }), {showlegend: true});358 resolve({});359 });360});361const renderDataGrid = mkClosure(function([_, gridOptions]) {362 return new Promise((resolve, reject) => {363 clearPanels();364 document.getElementById("myGrid").style.display = "block"365 const gridDiv = document.querySelector('#myGrid');366 new agGrid.Grid(gridDiv, gridOptions);367 resolve({});368 });369});370const timeStampToDate = mkClosure(function([_, x]){371 var date = new Date(x*1000);372 return date.toISOString();373})374function getFunction(e) {375 return e.fun;376}377function mkClosure(f) {378 return {379 fun: f,380 env: {}381 };382}383function applyClosure(c, arg) {384 return c.fun([c.env, arg]);385}386function setEnv(name, value, c) {387 c.env[name] = value;388 return c;389}390function getEnv(name, env) {391 return (env[name])();392}393const nativeMulInt = mkClosure(function([_, x]) {394 return setEnv("x", x, mkClosure(function([env, y]) {395 return env["x"] * y;396 }))397})398const nativeMulDouble = mkClosure(function([_, x]) {399 return setEnv("x", x, mkClosure(function([env, y]) {400 return env["x"] * y;401 }))402})403const nativeAddInt = mkClosure(function([_, x]) {404 return setEnv("x", x, mkClosure(function([env, y]) {405 return env["x"] + y;406 }))407})408const nativeAddDouble = mkClosure(function([_, x]) {409 return setEnv("x", x, mkClosure(function([env, y]) {410 return env["x"] + y;411 }))412})413const nativeSubInt = mkClosure(function([_, x]) {414 return setEnv("x", x, mkClosure(function([env, y]) {415 return env["x"] - y;416 }))417})418const nativeSubDouble = mkClosure(function([_, x]) {419 return setEnv("x", x, mkClosure(function([env, y]) {420 return env["x"] - y;421 }))422})423const nativeDivDouble = mkClosure(function([_, x]) {424 return setEnv("x", x, mkClosure(function([env, y]) {425 return env["x"] / y;426 }))427})428function div(x, y) {429 return ~~(x / y)430}431//************** Type Level Fixed Point **************/432class InClass {433 constructor(value0) {434 this.value0 = value0;435 }436}437const In = mkClosure(function([_, x]) {438 return new InClass(x);439})440const out = mkClosure(function([_, x]) {441 return x.value0;442})443const httpGet = mkClosure(function([_, url]) {444 return fetch("/fetch", {445 method: "POST",446 headers: {447 'Content-Type': 'application/json'448 },449 body: JSON.stringify({450 'url': url451 })452 }).then(response => response.text())453})454function _base64ToArrayBuffer(base64) {455 var binary_string = window.atob(base64);456 var len = binary_string.length;457 var bytes = new Uint8Array(len);458 for (var i = 0; i < len; i++) {459 bytes[i] = binary_string.charCodeAt(i);460 }461 return bytes.buffer;462}463const decompress = mkClosure(function([_, strData]) {464 const buffer = _base64ToArrayBuffer(strData);465 console.log("Decompressing...")466 const data = pako.ungzip(buffer);467 console.log("Decompressed")468 return data;469})470const bufferToIntList = mkClosure(function([_, buffer]){471 return Array.from(buffer);472})473const functorAsync = {474 "fmap": mkClosure(function ([_, f]) {475 return setEnv("f", f, mkClosure(function ([env, m]) {476 return new Promise((resolve, reject) => {477 m.then(x => resolve(applyClosure(env["f"], x))).catch(r => reject(r))478 })479 })); 480 })481}482const traversableAsync = {483 "fmap": functorAsync["fmap"],484 "traverse": mkClosure(function([_, inst]){485 return setEnv("inst", inst, mkClosure(function([env, f]) {486 return setEnv("inst", env["inst"], setEnv("f", f, mkClosure(function([env2, xs]){487 return xs.then(x => applyClosure(applyClosure(env2["inst"]["fmap"], mkAsync), applyClosure(env2["f"], x)));488 })))489 }))490 })491}492const trace = mkClosure(function([_, x]){493 console.log(x)494 return x;495})496const mkAsync = mkClosure(function([_, x]){497 return Promise.resolve(x);498})499const applicativeAsync = {500 "fmap": functorAsync["fmap"],501 "pure": mkAsync,502 "<*>": mkClosure(function([_, mf]) {503 return setEnv("mf", mf, mkClosure(function([env, mx]){504 return env["mf"].then(f => mx.then(x => applyClosure(f, x)))505 }))506 })507}508const monadAsync = {509 "pure": applicativeAsync["pure"],510 ">>=": mkClosure(function([_, m]) {511 return setEnv("m", m, mkClosure(function([env, f]){512 return env["m"].then(x => applyClosure(f, x))513 }))514 })515}516const JsonValue = mkClosure(function([_, x]){517 return x;518})519const JsonNode = mkClosure(function([_, xs]){520 return xs.map(([k, v]) => JSON.parse(`{ "${k}":${JSON.stringify(v)} }`))521 .reduce((x, y) => Object.assign(x, y))522})523class __Just {524 constructor(value) {525 this.value = value526 }527}528class __Nothing {529 constructor() {530 }531}532const Just = mkClosure(function([_, x]) {533 return new __Just(x);534})535const Nothing = new __Nothing();536const isJust = mkClosure(function([_, m]) {537 return m instanceof __Just538})539const fromJust = mkClosure(function([_, m]){540 if (m instanceof __Just) {541 return m.value;542 } else {543 throw "Maybe is empty"544 }545})546const functorMaybe = {547 "fmap": mkClosure(function ([_, f]) {548 return setEnv("f", f, mkClosure(function ([env, m]) {549 if (m instanceof __Nothing) {550 return Nothing;551 };552 if (m instanceof __Just) {553 return new __Just(applyClosure(env["f"], m.value));554 };555 throw new Error("Failed pattern match");556 })); 557 })558}559const applicativeMaybe = {560 "fmap": functorMaybe["fmap"],561 "pure": mkClosure(function([_, x]) { return new __Just(x); }),562 "<*>": mkClosure(function([_, mf]) {563 return setEnv("mf", mf, mkClosure(function([env, mx]){564 if (env["mf"] instanceof __Nothing || mx instanceof __Nothing) {565 return Nothing;566 };567 if (env["mf"] instanceof __Just || mx instanceof __Just) {568 return new __Just(applyClosure(env["mf"].value, mx.value));569 };570 throw new Error("Failed pattern match");571 }))572 })573}574const monadMaybe = {575 "pure": applicativeMaybe["pure"],576 ">>=": mkClosure(function([_, m]) {577 return setEnv("m", m, mkClosure(function([env, f]){578 if (env["m"] instanceof __Nothing) {579 return Nothing;580 };581 if (env["m"] instanceof __Just) {582 return applyClosure(f, m.value);583 };584 throw new Error("Failed pattern match");585 }))586 })587}588const parseJson = mkClosure(function([_, s]){589 try {590 return applyClosure(Just, JSON.parse(s));591 } catch (e) {592 console.log(`Error while parsing JSON ${e}`)593 return Nothing;594 }595})596const getJsonValue = mkClosure(function([_, x]) {597 return setEnv("x", x, mkClosure(function([env, y]){598 const z = y[env["x"]];599 if (z) { return applyClosure(Just, z) }600 else { return Nothing; }601 }))602})603const getJsonList = mkClosure(function([_, x]) {604 return setEnv("x", x, mkClosure(function([env, y]){605 const z = y[env["x"]];606 if (z && Array.isArray(z)) { return applyClosure(Just, z) }607 else { return Nothing; }608 }))609})610const jsonToString = mkClosure(function([_, x]){611 if (typeof x === 'string' || x instanceof String) {612 return applyClosure(Just, x);613 } else { return Nothing; }614})615const jsonToInt = mkClosure(function([_, x]){616 if (Number.isInteger(x)) {617 return applyClosure(Just, x);618 } else { return Nothing; }619})620const jsonToDouble = mkClosure(function([_, x]){621 if (x == null) {622 return applyClosure(Just, 0);623 }624 try {625 const v = Number.parseFloat(x);626 return applyClosure(Just, v);627 } catch(e) { return Nothing; }628})629const stringToJson = mkClosure(function([_, x]){630 return x;631})632const intToJson = mkClosure(function([_, x]){633 return x;634})635const traversableMaybe = {636 "fmap": functorMaybe["fmap"],637 "traverse": mkClosure(function([_, inst]){638 return setEnv("inst", inst, mkClosure(function([env, f]) {639 return setEnv("inst", env["inst"], setEnv("f", f, mkClosure(function([env2, xs]){640 if (xs instanceof __Nothing) {641 return env2["inst"]["pure"](Nothing);642 };643 if (xs instanceof __Just) {644 return applyClosure(applyClosure(env2["inst"]["fmap"], Just), applyClosure(env2["f"], xs.value));645 };646 throw new Error("Failed pattern match");647 })))648 }))649 })650}651function cons_f(inst, g, x, ys){652 const fmap = inst["fmap"]653 const ap = inst["<*>"]654 const liftA2 = mkClosure(function([_, f]){655 return setEnv("f", f, mkClosure(function([env, x]){ 656 return setEnv("f", env["f"], setEnv("x", x, mkClosure(function([_, y]){657 return applyClosure(applyClosure(ap, applyClosure(applyClosure(fmap, env["f"]), x)), y)658 })))659 }))660 })661 return applyClosure(applyClosure(applyClosure(liftA2, __colon), applyClosure(g, x)), ys)662}663const traversableList = {664 "fmap": functorList["fmap"],665 "traverse": mkClosure(function([_, inst]){666 return setEnv("inst", inst, mkClosure(function([env, f]) {667 return setEnv("inst", env["inst"], setEnv("f", f, mkClosure(function([env2, xs]){668 return xs.reduceRight(function(acc, cur){669 return cons_f(env2["inst"], f, cur, acc);670 }, applyClosure(env2["inst"]["pure"], []));671 })))672 }))673 })674}675const traverse = mkClosure(function([_, inst]) { 676 return setEnv("inst", inst, mkClosure(function([env, inst2]) {677 return applyClosure(inst2["traverse"], env["inst"])678 }))679})680const foldableList = {681 "foldr": mkClosure(function([_, f]){682 return setEnv("f", f, mkClosure(function([env, v]){683 return setEnv("f", env["f"],684 setEnv("v", v, mkClosure(function([env2, xs]){685 return xs.reduceRight(function(acc, cur){686 return applyClosure(applyClosure(env2["f"], cur), acc);687 }, env2["v"]);688 })))689 }))690 }),691 "foldl": mkClosure(function([_, f]){692 return setEnv("f", f, mkClosure(function([env, v]){693 return setEnv("f", env["f"],694 setEnv("v", v, mkClosure(function([env2, xs]){695 return xs.reduce(function(acc, cur){696 return applyClosure(applyClosure(env2["f"], acc), cur);697 }, env2["v"]);698 })))699 }))700 })701}702const foldableMaybe = {703 "foldr": mkClosure(function([_, f]){704 return setEnv("f", f, mkClosure(function([env, v]){705 return setEnv("f", env["f"],706 setEnv("v", v, mkClosure(function([env2, xs]){707 if (xs instanceof __Nothing) {708 return env2["v"];709 };710 if (xs instanceof __Just) {711 return applyClosure(applyClosure(env2["f"], xs.value), env2["v"]);712 };713 })))714 }))715 })716}717const foldr = mkClosure(function([_, inst]) { return inst["foldr"]; })718const foldl = mkClosure(function([_, inst]) { return inst["foldl"]; })719const semigroupString = {720 "<>" : mkClosure(function([_, xs]){721 return setEnv("xs", xs, mkClosure(function([env, ys]){722 return env["xs"] + ys;723 }))724 })725}726const semigroupList = {727 "<>" : mkClosure(function([_, xs]){728 return setEnv("xs", xs, mkClosure(function([env, ys]){729 return env["xs"].concat(ys);730 }))731 })732}733const mappend = mkClosure(function([_, inst]) { return inst["<>"]; })734const fromMaybe = mkClosure(function([_, x]){735 return setEnv("x", x, mkClosure(function([env, mx]){736 if (mx instanceof __Nothing) {737 return env["x"];738 };739 if (mx instanceof __Just) {740 return mx.value;741 };742 }))743})744const fromMaybeLazy = mkClosure(function([_, x]){745 return setEnv("x", x, mkClosure(function([env, mx]){746 if (mx instanceof __Nothing) {747 return applyClosure(env["x"], null);748 };749 if (mx instanceof __Just) {750 return mx.value;751 };752 }))753})754const error = mkClosure(function([_, x]){755 return mkClosure(function([_, _2]){ throw x; });756})757const showInt = {758 "show" : mkClosure(function([_, x]) {759 return `${x}`760 })761}762const showList = mkClosure(function([_, inst]) {763 return {764 "show" : mkClosure(function([_, xs]){765 return xs.map(x => applyClosure(inst["show"], x))766 })767 }768})769const show = mkClosure(function([_, inst]) { return inst["show"]})770const fromListToMap = mkClosure(function([_, xs]){771 return Object.fromEntries(xs);772})773const mapToJson = mkClosure(function([_, xs]){774 return xs;775})776const listToJson = mkClosure(function([_, xs]){777 return xs;778})779const jsonToList = mkClosure(function([_, xs]){780 return xs;781})782const nullStr = mkClosure(function([_, xs]){783 return xs.length == 0;784})785const headStr = mkClosure(function([_, xs]){786 return xs[0];787})788const tailStr = mkClosure(function([_, xs]){789 return xs.slice(1);790})791const charToStr = mkClosure(function([_, x]){792 return `${x}`793})794const __exclexcl = mkClosure(function([_, xs]){795 return setEnv("xs", xs, mkClosure(function([env, n]){796 const vs = env["xs"]797 if (n < 0) throw "Exception: Prelude.!!: negative index"798 if (n >= vs.length) throw "Exception: Prelude.!!: index too large"799 return env["xs"][n];800 }))801})802const length = mkClosure(function([_, xs]){803 return xs.length;804})805const take = mkClosure(function([_, n]){806 return setEnv("n", n, mkClosure(function([env, xs]){807 return xs.slice(0, env["n"]);808 }))809})810const drop = mkClosure(function([_, n]){811 return setEnv("n", n, mkClosure(function([env, xs]){812 return xs.slice(env["n"]);813 }))814})815async function runCode(fn, x, retries) {816 try {817 const response = await fetch("/eval", {818 method: "POST",819 headers: {820 'Content-Type': 'application/json'821 },822 body: JSON.stringify({823 'code': codeBase64,824 'fn': fn,825 'arg': JSON.stringify(x)826 })827 });828 return await response.json();829 } catch (e) {830 console.log(e)831 if (retries > 0) {832 return await runCode(fn, x, retries - 1)833 }834 }835}836const remote = mkClosure(function([_, f]){837 return setEnv("f", f, mkClosure(async function([env, x]){838 if (typeof codeBase64 != 'undefined') {839 try {840 return await runCode(env["f"], x, 3)841 } catch (e) {842 console.log(e)843 }844 }845 }))846 })847const quote = mkClosure(function([_, s]){848 return s849})850const serializableInt = {}851class IO {852 constructor(fn) {853 this.fn = fn854 }855 run(world) {856 return applyClosure(this.fn, world);857 }858}859const randomIO = new IO(mkClosure(function([_, world]) { return Promise.resolve([1 - Math.random(), world + 1]) }))860const functorIO = {861 "fmap": mkClosure(function ([_, f]) {862 return setEnv("f", f, mkClosure(function([env1, m]){863 return new IO (setEnv("m", m, setEnv("f", env1["f"], mkClosure(function([env2, world]){864 return env2["m"].run(world).then(([x, _]) => [applyClosure(env2["f"], x), world]);865 }))))866 }))867 })868}869const applicativeIO = {870 "fmap" : functorIO["fmap"],871 "pure": mkClosure(function([_, x]) {872 return new IO(setEnv("x", x, mkClosure(function([env, world]) { return Promise.resolve([env["x"], world]) })))873 }),874 "<*>": mkClosure(function([_, mf]) {875 return setEnv("mf", mf, mkClosure(function([env, mx]){876 return new IO(setEnv("mf", env["mf"], setEnv("mx", mx, mkClosure(function([env2, world]){877 return env2["mf"].run(world).then(([f, world2]) =>878 env2["mx"].run(world2).then(([x, world3]) =>879 [applyClosure(f, x), world3]))880 }))))881 }))882 })883}884const monadIO = {885 "pure": applicativeIO["pure"],886 ">>=": mkClosure(function([_, m]) {887 return setEnv("m", m, mkClosure(function([env1, f]){888 return new IO(setEnv("f", f, setEnv("m", env1["m"], mkClosure(function([env2, world]){889 return env2["m"].run(world).then(([x, world2]) => applyClosure(env2["f"], x).run(world2))890 }))))891 }))892 })...
env.ts
Source:env.ts
1import { setEnv } from './utils';2/** enum representing the keycloak roles */3export enum Roles {4 ROLE_EDIT_KEYCLOAK_USERS = 'ROLE_EDIT_KEYCLOAK_USERS',5 ROLE_VIEW_KEYCLOAK_USERS = 'ROLE_VIEW_KEYCLOAK_USERS',6}7const defaultRoles = {8 USERS: `${Roles.ROLE_EDIT_KEYCLOAK_USERS},${Roles.ROLE_VIEW_KEYCLOAK_USERS}`,9 PLANS: Roles.ROLE_VIEW_KEYCLOAK_USERS,10 LOCATIONS: Roles.ROLE_VIEW_KEYCLOAK_USERS,11 CARD_SUPPORT: Roles.ROLE_VIEW_KEYCLOAK_USERS,12 INVENTORY: Roles.ROLE_VIEW_KEYCLOAK_USERS,13 HEALTHCARE_SERVICE: Roles.ROLE_VIEW_KEYCLOAK_USERS,14 TEAMS: Roles.ROLE_VIEW_KEYCLOAK_USERS,15 PRODUCT_CATALOGUE: Roles.ROLE_VIEW_KEYCLOAK_USERS,16 GROUP: Roles.ROLE_VIEW_KEYCLOAK_USERS,17 FORM_CONFIGURATION: Roles.ROLE_VIEW_KEYCLOAK_USERS,18 ORG_AFFILIATION: Roles.ROLE_VIEW_KEYCLOAK_USERS,19 CARE_TEAM: Roles.ROLE_VIEW_KEYCLOAK_USERS,20 SERVER_SETTINGS: Roles.ROLE_VIEW_KEYCLOAK_USERS,21 QUEST: Roles.ROLE_VIEW_KEYCLOAK_USERS,22};23const rawOpenSrpRoles = setEnv('REACT_APP_OPENSRP_ROLES', JSON.stringify(defaultRoles))24export const OPENSRP_ROLES = JSON.parse(rawOpenSrpRoles)25export const WEBSITE_NAME = setEnv('REACT_APP_WEBSITE_NAME', 'OpenSRP Web');26export const ENABLE_CARD_SUPPORT = setEnv('REACT_APP_ENABLE_CARD_SUPPORT', 'false') === 'true';27export const ENABLE_PLANS = setEnv('REACT_APP_ENABLE_PLANS', 'false') === 'true';28/** Activate the teams menu */29export const ENABLE_TEAMS = setEnv('REACT_APP_ENABLE_TEAMS', 'false') === 'true';30/** Activate the healthcare menu */31export const ENABLE_HEALTHCARE_SERVICES =32 setEnv('REACT_APP_ENABLE_FHIR_HEALTHCARE_SERVICES', 'false') === 'true';33/** Activate the plans menu */34export const ENABLE_LOCATIONS = setEnv('REACT_APP_ENABLE_LOCATIONS', 'false') === 'true';35export const OPENSRP_OAUTH_SCOPES = setEnv('REACT_APP_OPENSRP_OAUTH_SCOPES', 'profile').split(',');36/** Activate the teams menu */37export const ENABLE_FHIR_GROUP = setEnv('REACT_APP_ENABLE_FHIR_GROUP', 'false') === 'true';38export const DEFAULT_ACTIVITY_DURATION_DAYS = Number(39 setEnv('REACT_APP_DEFAULT_ACTIVITY_DURATION_DAYS', 7)40);41export const PLAN_UUID_NAMESPACE = setEnv('REACT_APP_PLAN_UUID_NAMESPACE', '');42export const ACTION_UUID_NAMESPACE = setEnv('REACT_APP_ACTION_UUID_NAMESPACE', '');43export const DEFAULT_PLAN_VERSION = setEnv('REACT_APP_DEFAULT_PLAN_VERSION', '1');44export const TASK_GENERATION_STATUS = setEnv('REACT_APP_TASK_GENERATION_STATUS', 'False');45export const PLAN_ASSIGNMENT_AT_GEO_LEVEL = Number(46 setEnv('REACT_APP_PLAN_ASSIGNMENT_AT_GEO_LEVEL', 0)47);48export const MAIN_LOGO_SRC = setEnv(49 'REACT_APP_MAIN_LOGO_SRC',50 'https://github.com/OpenSRP/web/raw/master/app/src/assets/images/opensrp-logo-color.png'51);52export const DATE_FORMAT = setEnv('REACT_APP_DATE_FORMAT', 'yyyy-MM-DD');53export const DEFAULT_TIME = setEnv('REACT_APP_DEFAULT_TIME', 'T00:00:00+00:00');54export const DEFAULT_PLAN_DURATION_DAYS = Number(55 setEnv('REACT_APP_DEFAULT_PLAN_DURATION_DAYS', 20)56);57export const ENABLE_FHIR_TEAMS = setEnv('REACT_APP_ENABLE_FHIR_TEAMS', 'false') === 'true';58/** Default plan id */59export const DEFAULT_PLAN_ID = setEnv(60 'REACT_APP_DEFAULT_PLAN_ID',61 '27362060-0309-411a-910c-64f55ede3758'62);63/** Activate patients menu */64export const ENABLE_PATIENTS_MODULE = setEnv('REACT_APP_ENABLE_FHIR_PATIENTS', 'false') === 'true';65export const BACKEND_ACTIVE = setEnv('REACT_APP_BACKEND_ACTIVE', 'false') === 'true';66export const OPENSRP_LOGOUT_URL = setEnv(67 'REACT_APP_OPENSRP_LOGOUT_URL',68 'https://opensrp-stage.smartregister.org/opensrp/logout.do'69);70export const OPENSRP_OAUTH_STATE = setEnv('REACT_APP_OPENSRP_OAUTH_STATE', 'opensrp');71export const ENABLE_OPENSRP_OAUTH = setEnv('REACT_APP_ENABLE_OPENSRP_OAUTH', 'false') === 'true';72// notice the ending is NOT / here73export const OPENSRP_ACCESS_TOKEN_URL = setEnv(74 'REACT_APP_OPENSRP_ACCESS_TOKEN_URL',75 'https://opensrp-stage.smartregister.org/opensrp/oauth/token'76);77// notice the ending is NOT / here78export const OPENSRP_AUTHORIZATION_URL = setEnv(79 'REACT_APP_OPENSRP_AUTHORIZATION_URL',80 'https://opensrp-stage.smartregister.org/opensrp/oauth/authorize'81);82export const OPENSRP_CLIENT_ID = setEnv('REACT_APP_OPENSRP_CLIENT_ID', '');83/** The domain name */84export const DOMAIN_NAME = setEnv('REACT_APP_DOMAIN_NAME', 'http://localhost:3000');85export const OPENSRP_USER_URL = setEnv(86 'REACT_APP_OPENSRP_USER_URL',87 'https://opensrp-stage.smartregister.org/opensrp/user-details'88);89export const NAVBAR_BRAND_IMG_SRC = setEnv(90 'REACT_APP_NAVBAR_BRAND_IMG_SRC',91 'https://github.com/OpenSRP/opensrp-web/raw/master/clients/core/src/assets/images/logo.png'92);93export const KEYCLOAK_LOGOUT_URL = setEnv(94 'REACT_APP_KEYCLOAK_LOGOUT_URL',95 'https://keycloak-stage.smartregister.org/auth/realms/opensrp-web-stage/protocol/openid-connect/logout'96);97export const OPENSRP_API_BASE_URL = setEnv(98 'REACT_APP_OPENSRP_API_BASE_URL',99 'https://opensrp-stage.smartregister.org/opensrp/rest/'100);101export const OPENSRP_API_V2_BASE_URL = setEnv(102 'REACT_APP_OPENSRP_API_V2_BASE_URL',103 'https://opensrp-stage.smartregister.org/opensrp/rest/v2/'104);105export const KEYCLOAK_API_BASE_URL = setEnv(106 'REACT_APP_KEYCLOAK_API_BASE_URL',107 'https://keycloak-stage.smartregister.org/auth/admin/realms/opensrp-web-stage'108);109/** Express server settings */110export const EXPRESS_OAUTH_GET_STATE_URL = setEnv(111 'REACT_APP_EXPRESS_OAUTH_GET_STATE_URL',112 'http://localhost:3000/oauth/state'113);114export const EXPRESS_OAUTH_LOGOUT_URL = setEnv(115 'REACT_APP_EXPRESS_OAUTH_LOGOUT_URL',116 'http://localhost:3000/logout'117);118/** Do you want to disable login protection? */119export const DISABLE_LOGIN_PROTECTION =120 setEnv('REACT_APP_DISABLE_LOGIN_PROTECTION', 'false') === 'true';121/** Activate the product-catalogue menu */122export const ENABLE_PRODUCT_CATALOGUE =123 setEnv('REACT_APP_ENABLE_PRODUCT_CATALOGUE', 'false') === 'true';124/** Activate the FHIR Care Team menu */125export const ENABLE_FHIR_CARE_TEAM = setEnv('REACT_APP_ENABLE_FHIR_CARE_TEAM', 'false') === 'true';126/** Activate form configuration */127export const ENABLE_FORM_CONFIGURATION =128 setEnv('REACT_APP_ENABLE_FORM_CONFIGURATION', 'false') === 'true';129export const LANGUAGE_CODE = setEnv('REACT_APP_LANGUAGE_CODE', 'en');130export const PROJECT_CODE = setEnv('REACT_APP_PROJECT_CODE', 'eusm');131export const ENABLE_INVENTORY = setEnv('REACT_APP_ENABLE_INVENTORY', 'false') === 'true';132export const SUPPORTED_LANGUAGES = setEnv('REACT_APP_SUPPORTED_LANGUAGES', '').split(',');133export const ENABLE_LANGUAGE_SWITCHER =134 setEnv('REACT_APP_ENABLE_LANGUAGE_SWITCHER', 'false') === 'true';135export const ENABLE_FHIR_LOCATIONS = setEnv('REACT_APP_ENABLE_FHIR_LOCATIONS', 'false') === 'true';136export const FILTER_BY_PARENT_ID = setEnv('REACT_APP_FILTER_BY_PARENT_ID', 'true') === 'true';137export const DEFAULT_HOME_MODE = setEnv('REACT_APP_DEFAULT_HOME_MODE', 'default');138export const ENABLE_USER_MANAGEMENT = setEnv('REACT_APP_ENABLE_USER_MANAGEMENT', 'false') === 'true';139export const ENABLE_FHIR_USER_MANAGEMENT = setEnv('REACT_APP_ENABLE_FHIR_USER_MANAGEMENT', 'false') === 'true';140export const FHIR_API_BASE_URL = setEnv(141 'REACT_APP_FHIR_API_BASE_URL',142 'https://fhir-auth.labs.smartregister.org/fhir'143);144export const ENABLE_TEAMS_ASSIGNMENT_MODULE =145 setEnv('REACT_APP_ENABLE_TEAMS_ASSIGNMENT_MODULE', 'false') === 'true';146export const KEYCLOAK_USERS_PAGE_SIZE = Number(setEnv('REACT_APP_KEYCLOAK_USERS_PAGE_SIZE', 20));147export const DISABLE_TEAM_MEMBER_REASSIGNMENT =148 setEnv('REACT_APP_DISABLE_TEAM_MEMBER_REASSIGNMENT', 'true') === 'true';149export const USER_FORM_HIDDEN_FIELDS = setEnv('REACT_APP_USER_FORM_HIDDEN_FIELDS', '').split(',');150export const USER_FORM_RENDER_FIELDS = setEnv('REACT_APP_USER_FORM_RENDER_FIELDS', '').split(',');151export const PAGINATION_SIZE = Number(setEnv('REACT_APP_PAGINATION_SIZE', 1000));152export const DEFAULTS_TABLE_PAGE_SIZE = Number(setEnv('REACT_APP_DEFAULTS_TABLE_PAGE_SIZE', 5));153export const FHIR_PATIENT_SORT_FIELDS = setEnv(154 'REACT_APP_FHIR_PATIENT_SORT_FIELDS',155 '-_lastUpdated'156).split(',');157export const FHIR_PATIENT_BUNDLE_SIZE = Number(setEnv('REACT_APP_FHIR_PATIENT_BUNDLE_SIZE', 5000));158export const FHIR_ROOT_LOCATION_IDENTIFIER = setEnv(159 'REACT_APP_FHIR_ROOT_LOCATION_IDENTIFIER',160 ''161);162export const ENABLE_SERVER_SETTINGS = setEnv('REACT_APP_ENABLE_SERVER_SETTINGS', false) === 'true';163export const OPENSRP_WEB_VERSION = setEnv('REACT_APP_OPENSRP_WEB_VERSION', '');164export const SENTRY_CONFIGS = JSON.parse(setEnv('REACT_APP_SENTRY_CONFIG_JSON', '{}'));165export const ENABLE_QUEST = setEnv('REACT_APP_ENABLE_QUEST', 'false') === 'true';...
test_environ.py
Source:test_environ.py
...12 "__opts__": {"test": False},13 "__salt__": {"environ.setenv": envmodule.setenv},14 }15 return {envstate: loader_globals, envmodule: loader_globals}16def test_setenv():17 """18 test that a subsequent calls of setenv changes nothing19 """20 ret = envstate.setenv("test", "value")21 assert ret["changes"] == {"test": "value"}22 ret = envstate.setenv("test", "other")23 assert ret["changes"] == {"test": "other"}24 # once again with the same value25 ret = envstate.setenv("test", "other")26 assert ret["changes"] == {}27@pytest.mark.skip_unless_on_windows28def test_setenv_permanent():29 """30 test that we can set permanent environment variables (requires pywin32)31 """32 with patch.dict(33 envmodule.__utils__,34 {35 "reg.set_value": MagicMock(),36 "reg.delete_value": MagicMock(),37 "win_functions.broadcast_setting_change": MagicMock(),38 },39 ):40 ret = envstate.setenv("test", "value", permanent=True)41 assert ret["changes"] == {"test": "value"}42 envmodule.__utils__["reg.set_value"].assert_called_with(43 "HKCU", "Environment", "test", "value"44 )45 ret = envstate.setenv("test", False, false_unsets=True, permanent=True)46 assert ret["changes"] == {"test": None}47 envmodule.__utils__["reg.delete_value"].assert_called_with(48 "HKCU", "Environment", "test"49 )50def test_setenv_dict():51 """52 test that setenv can be invoked with dict53 """54 ret = envstate.setenv("notimportant", {"test": "value"})55 assert ret["changes"] == {"test": "value"}56def test_setenv_int():57 """58 test that setenv can not be invoked with int59 (actually it's anything other than strings and dict)60 """61 ret = envstate.setenv("test", 1)62 assert ret["result"] is False63def test_setenv_unset():64 """65 test that ``false_unsets`` option removes variable from environment66 """67 with patch.dict(os.environ, {"INITIAL": "initial"}, clear=True):68 ret = envstate.setenv("test", "value")69 assert ret["changes"] == {"test": "value"}70 ret = envstate.setenv("notimportant", {"test": False}, false_unsets=True)71 assert ret["changes"] == {"test": None}72 assert envstate.os.environ == {"INITIAL": "initial"}73def test_setenv_clearall():74 """75 test that ``clear_all`` option sets other values to ''76 """77 with patch.dict(os.environ, {"INITIAL": "initial"}, clear=True):78 ret = envstate.setenv("test", "value", clear_all=True)79 assert ret["changes"] == {"test": "value", "INITIAL": ""}80 if salt.utils.platform.is_windows():81 assert envstate.os.environ == {"TEST": "value", "INITIAL": ""}82 else:83 assert envstate.os.environ == {"test": "value", "INITIAL": ""}84def test_setenv_clearall_with_unset():85 """86 test that ``clear_all`` option combined with ``false_unsets``87 unsets other values from environment88 """89 with patch.dict(os.environ, {"INITIAL": "initial"}, clear=True):90 ret = envstate.setenv("test", "value", false_unsets=True, clear_all=True)91 assert ret["changes"] == {"test": "value", "INITIAL": None}92 if salt.utils.platform.is_windows():93 assert envstate.os.environ == {"TEST": "value"}94 else:95 assert envstate.os.environ == {"test": "value"}96def test_setenv_unset_multi():97 """98 test basically same things that above tests but with multiple values passed99 """100 with patch.dict(os.environ, {"INITIAL": "initial"}, clear=True):101 ret = envstate.setenv("notimportant", {"foo": "bar"})102 assert ret["changes"] == {"foo": "bar"}103 with patch.dict(envstate.__utils__, {"reg.read_value": MagicMock()}):104 ret = envstate.setenv(105 "notimportant", {"test": False, "foo": "baz"}, false_unsets=True106 )107 assert ret["changes"] == {"test": None, "foo": "baz"}108 if salt.utils.platform.is_windows():109 assert envstate.os.environ == {"INITIAL": "initial", "FOO": "baz"}110 else:111 assert envstate.os.environ == {"INITIAL": "initial", "foo": "baz"}112 with patch.dict(envstate.__utils__, {"reg.read_value": MagicMock()}):113 ret = envstate.setenv("notimportant", {"test": False, "foo": "bax"})114 assert ret["changes"] == {"test": "", "foo": "bax"}115 if salt.utils.platform.is_windows():116 assert envstate.os.environ == {117 "INITIAL": "initial",118 "FOO": "bax",119 "TEST": "",120 }121 else:122 assert envstate.os.environ == {123 "INITIAL": "initial",124 "foo": "bax",125 "test": "",126 }127def test_setenv_test_mode():128 """129 test that imitating action returns good values130 """131 with patch.dict(os.environ, {"INITIAL": "initial"}, clear=True):132 with patch.dict(envstate.__opts__, {"test": True}):133 ret = envstate.setenv("test", "value")134 assert ret["changes"] == {"test": "value"}135 ret = envstate.setenv("INITIAL", "initial")...
test_integration_halosqs_config_helper.py
Source:test_integration_halosqs_config_helper.py
...10halosqs = imp.load_module(module_name, fp, pathname, description)11class TestIntegrationConfigHelper(object):12 def test_integration_config_helper_instantiate_send_events(self,13 monkeypatch):14 monkeypatch.setenv("HALO_API_KEY", "abc123")15 monkeypatch.setenv("HALO_API_SECRET_KEY", "def456")16 monkeypatch.setenv("AWS_ACCESS_KEY_ID", "abc123")17 monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "abc123")18 monkeypatch.setenv("AWS_DEFAULT_REGION", "abc123")19 monkeypatch.setenv("SQS_QUEUE_URL", "abc123")20 monkeypatch.setenv("APPLICATION_MODE", "send")21 monkeypatch.setenv("HALO_MODULE", "events")22 monkeypatch.setenv("START_TIME", "2018-01-01")23 assert halosqs.ConfigHelper()24 def test_integration_config_helper_instantiate_send_scans(self,25 monkeypatch):26 monkeypatch.setenv("HALO_API_KEY", "abc123")27 monkeypatch.setenv("HALO_API_SECRET_KEY", "def456")28 monkeypatch.setenv("AWS_ACCESS_KEY_ID", "abc123")29 monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "abc123")30 monkeypatch.setenv("AWS_DEFAULT_REGION", "abc123")31 monkeypatch.setenv("SQS_QUEUE_URL", "abc123")32 monkeypatch.setenv("APPLICATION_MODE", "send")33 monkeypatch.setenv("HALO_MODULE", "events")34 monkeypatch.setenv("START_TIME", "2018-01-01")35 monkeypatch.setenv("SCAN_FILTER", "module:fim;status:completed_with_errors") # NOQA36 cfg_helper = halosqs.ConfigHelper()37 assert cfg_helper38 assert cfg_helper.search_params == {"module": "fim",39 "status": "completed_with_errors"}40 def test_integration_config_helper_instantiate_send_scans_fail(self, monkeypatch): # NOQA41 monkeypatch.setenv("HALO_API_KEY", "abc123")42 monkeypatch.setenv("HALO_API_SECRET_KEY", "def456")43 monkeypatch.setenv("AWS_ACCESS_KEY_ID", "abc123")44 monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "abc123")45 monkeypatch.setenv("AWS_DEFAULT_REGION", "abc123")46 monkeypatch.setenv("SQS_QUEUE_URL", "abc123")47 monkeypatch.setenv("APPLICATION_MODE", "send")48 monkeypatch.setenv("HALO_MODULE", "events")49 monkeypatch.setenv("START_TIME", "2018-01-01")50 monkeypatch.setenv("SCAN_FILTER", "module:../etc/passwd")51 with pytest.raises(ValueError):52 assert halosqs.ConfigHelper()53 def test_integration_config_helper_instantiate_send_fail(self,54 monkeypatch):55 monkeypatch.setenv("HALO_API_KEY", "abc123")56 monkeypatch.setenv("HALO_API_SECRET_KEY", "def456")57 monkeypatch.setenv("AWS_ACCESS_KEY_ID", "abc123")58 monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "abc123")59 monkeypatch.setenv("AWS_DEFAULT_REGION", "abc123")60 monkeypatch.setenv("SQS_QUEUE_URL", "abc123")61 monkeypatch.setenv("APPLICATION_MODE", "send")62 with pytest.raises(ValueError):63 assert halosqs.ConfigHelper()64 def test_integration_config_helper_instantiate_receive(self,65 monkeypatch):66 monkeypatch.setenv("AWS_ACCESS_KEY_ID", "abc123")67 monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "abc123")68 monkeypatch.setenv("AWS_DEFAULT_REGION", "abc123")69 monkeypatch.setenv("SQS_QUEUE_URL", "abc123")70 monkeypatch.setenv("APPLICATION_MODE", "receive")71 monkeypatch.setenv("HALO_MODULE", "events")72 assert halosqs.ConfigHelper()73 def test_integration_config_helper_instantiate_receive_fail(self,74 monkeypatch):75 monkeypatch.setenv("AWS_ACCESS_KEY_ID", "abc123")76 monkeypatch.setenv("APPLICATION_MODE", "receive")77 monkeypatch.setenv("HALO_MODULE", "events")78 monkeypatch.delenv("APPLICATION_MODE")79 with pytest.raises(ValueError):...
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!!