Best Python code snippet using molecule_python
SubstituteExtend.js
Source:SubstituteExtend.js
1//=============================================================================2// SubstituteExtend.js3// ----------------------------------------------------------------------------4// (C)2017 Triacontane5// This software is released under the MIT License.6// http://opensource.org/licenses/mit-license.php7// ----------------------------------------------------------------------------8// Version9// 1.1.0 2018/09/09 身代ãããç¡å¹ã«ããã¹ãã«ãã¢ã¤ãã ãç´æ¥æå®ã§ããæ©è½ã追å 10// 1.0.2 2017/08/22 身代ããæ¡ä»¶ãå¿
ä¸ä»¥å¤ããç¡å¹ã«ããå ´åã§ãå¿
ä¸æ»æã«å¯¾ãã身代ãããçºåããªãå ´åãããåé¡ãä¿®æ£11// 1.0.1 2017/02/07 端æ«ä¾åã®è¨è¿°ãåé¤12// 1.0.0 2017/02/05 åç13// ----------------------------------------------------------------------------14// [Blog] : https://triacontane.blogspot.jp/15// [Twitter]: https://twitter.com/triacontane/16// [GitHub] : https://github.com/triacontane/17//=============================================================================18/*:19 * @plugindesc SubstituteExtendPlugin20 * @author triacontane21 *22 * @param CondDying23 * @desc ããã©ã«ãã®èº«ä»£ããæ¡ä»¶ã§ãããçæ»ããæå¹ã«ãã¾ããOFFã«ããã¨ç¡å¹ã«ãªãã¾ãã(ON/OFF)24 * @default true25 * @type boolean26 *27 * @param CondNonCertainHit28 * @desc ããã©ã«ãã®èº«ä»£ããæ¡ä»¶ã§ãããå¿
ä¸ä»¥å¤ããæå¹ã«ãã¾ããOFFã«ããã¨ç¡å¹ã«ãªãã¾ãã(ON/OFF)29 * @default true30 * @type boolean31 *32 * @help 以ä¸ã®å
容ã«æ²¿ã£ã¦èº«ä»£ããã®ä»æ§ãæ¡å¼µãã¾ãã33 *34 * 1. ããã©ã«ãã®èº«ä»£ããæ¡ä»¶ã§ãã以ä¸ã®äºã¤ãç¡å¹åã§ãã¾ãã35 * ã»çæ»(æ®HP25%以ä¸)36 * ã»ã¹ãã«ã¿ã¤ããå¿
ä¸ã以å¤37 *38 * ãªããã¹ãã«ã¿ã¤ããå¿
ä¸ã以å¤ãã®æ¡ä»¶ãå¤ãã¨ãé²å¾¡ãªã©ç¡é¢ä¿ã®39 * ã¹ãã«ã«å¯¾ãã¦ãç¡å·®å¥ã«ã身代ããããçºåããããã«ãªãã¾ãã40 * 注æãã¦è¨å®ãã¦ãã ããã41 *42 * 2. 身代ããã®è©³ç´°ãªçºåæ¡ä»¶ãç´°ããè¨å®ã§ãã¾ãã43 * ç¹å¾´ãæãããã¼ã¿ãã¼ã¹ã®ã¡ã¢æ¬ã«ã以ä¸ã®éãè¨è¿°ãã¦ãã ããã44 * ã¡ã¢æ¬ã®ãå
¨ã¦ã®æ¡ä»¶ããæºãããå ´åã«èº«ä»£ãããçºåãã¾ãã45 * åºæ¬çã«ãç¹å¾´ãã®ã身代ãããã¨ã»ããã§è¨è¿°ãã¾ãã46 *47 * ãªããç¹å¾´ãæãããã¼ã¿ãã¼ã¹ã®ã¡ã¢æ¬ã¨ã¯48 * ã¢ã¯ã¿ã¼ãè·æ¥ãæ¦å¨ãé²å
·ãã¹ãã¼ããæµãã£ã©ã®ããããã®ã¡ã¢æ¬ã§ãã49 *50 * <SE_å®è¡è
HPç:50> # å®è¡è
ã®HPã50%以ä¸ã®ã¨ãã®ã¿çºåãã¾ãã51 * <SE_SubjectHPRate:50> # åä¸52 * <SE_対象è
HPç:50> # 対象è
ã®HPã50%以ä¸ã®ã¨ãã®ã¿çºåãã¾ãã(â»1)53 * <SE_TargetHPRate:50> # åä¸54 * <SE_身代ãã対象éå®:1> # 身代ããã®å¯¾è±¡è
ã[1]ã«éå®ãã¾ãã(â»2)55 * <SE_TargetRestriction:1> # åä¸56 * <SE_身代ããã¹ã¤ãã:4> # ã¹ã¤ãã[4]ãONã®ã¨ãã®ã¿çºåãã¾ãã57 * <SE_SubstituteSwitch:4> # åä¸58 * <SE_身代ããè¨ç®å¼:f> # è¨ç®å¼[f]ã®çµæãtrueã®ã¨ãã®ã¿çºåãã¾ãã(â»3)59 * <SE_SubstituteFormula:f> # åä¸60 *61 * â»1 ãã©ã¡ã¼ã¿ããããã©ã«ãã®èº«ä»£ããæ¡ä»¶ã§ãããçæ»ãã62 * ç¡å¹ã«ããå ´åã®ã¿å¤å®ãã¾ãã63 *64 * â»2 <SE_身代ãã対象éå®:n>ã®ã¿ã°ã®å¯¾è±¡è
ãè¨å®ãããå ´åã65 * ç¹å¾´ãæãããã¼ã¿ãã¼ã¹ã®ã¡ã¢æ¬ã«ä»¥ä¸ã®éãè¨è¿°ãã¾ãã66 *67 * <SE_身代ãã対象è
:1> # <SE_身代ãã対象éå®:1>ã®å¯¾è±¡ã«ãªãã¾ãã68 * <SE_SubstituteTarget:1> # åä¸69 *70 * ã身代ãã対象éå®ãã§æå®ãããã©ã¡ã¼ã¿ã¨ä¸è´ããå ´åã«èº«ä»£ãã対象ã«ãªãã¾ãã71 * ä¾ãã°ãã¡ã¢æ¬ã«<SE_身代ãã対象éå®:2>ã¨è¨å
¥ããå ´åãåããã¡ã¢æ¬ã«72 * <SE_身代ãã対象è
:2>ã¨è¨å
¥ããã¦ããç¹å¾´ãæã¤ã¢ã¯ã¿ã¼ã«å¯¾ãã¦ã®ã¿73 * 身代ãããå®è¡ãã¾ãã74 *75 * â»3 ä¸ç´è
åãæ©è½ã§ãã76 * ã¾ããè¨ç®å¼ä¸ã§ä¸çå·ã使ãããå ´åã以ä¸ã®ããã«è¨è¿°ãã¦ãã ããã77 * < â <78 * > â >79 *80 * ä¾ï¼<SE_身代ããè¨ç®å¼:\v[2] > 3> # å¤æ°[2]ã[3]ãã大ããå ´åãçºåãã¾ãã81 *82 * è¨ç®å¼ä¸ã§ã¯ãactionãã§å¯¾è±¡ã¹ãã«ã®Actionãªãã¸ã§ã¯ããåç
§ã§ãã¾ãã83 * ãã¾ãå©ç¨ããã°èº«ä»£ãããçºåããã¹ãã«ãç´°ããéå®ã§ãã¾ãã84 *85 * 以ä¸ãè¨å
¥ä¾ã§ãã86 * <SE_身代ããè¨ç®å¼:action.isAttack()> # é常æ»æã®ã¿èº«ä»£ããçºå87 * <SE_身代ããè¨ç®å¼:action.isPhysical()> # ç©çæ»æã®ã¿èº«ä»£ããçºå88 * <SE_身代ããè¨ç®å¼:action.isForOne()> # åä½å¯¾è±¡ã®ã¿èº«ä»£ããçºå89 *90 * 3. 身代ããçºåæã«ãæå®ããIDã®ã¹ãã«å¹æã身代ããå®è¡è
ã«91 * é©ç¨ããããã¨ãã§ãã¾ãã92 * <SE_身代ããã¹ãã«ID:5> # 身代ããçºåæã«ã¹ãã«[5]ãå®è¡è
ã«é©ç¨ã(â»1)93 * <SE_SubstituteSkillId:5> # åä¸94 *95 * â»1 ãã¡ã¼ã¸ãããã¢ãããã¢ãã¡ã¼ã·ã§ã³çã®æ¼åºã¯è¡¨ç¤ºããã¾ããã96 *97 * 4. 身代ãããç¡å¹ã«ããã¹ãã«ãåå¥æå®ã§ãã¾ãã98 * ã¹ãã«ãããã¯ã¢ã¤ãã ã®ã¡ã¢æ¬ã«ä»¥ä¸ã®éãæå®ãã¦ãã ããã99 * <SE_身代ããç¡å¹>100 * <SE_SubstituteInvalid>101 *102 * ãã®ãã©ã°ã¤ã³ã«ã¯ãã©ã°ã¤ã³ã³ãã³ãã¯ããã¾ããã103 *104 * å©ç¨è¦ç´ï¼105 * ä½è
ã«ç¡æã§æ¹å¤ãåé
å¸ãå¯è½ã§ãå©ç¨å½¢æ
ï¼åç¨ã18ç¦å©ç¨çï¼106 * ã«ã¤ãã¦ãå¶éã¯ããã¾ããã107 * ãã®ãã©ã°ã¤ã³ã¯ããããªãã®ãã®ã§ãã108 *109 * This plugin is released under the MIT License.110 */111/*:ja112 * @plugindesc 身代ããæ¡å¼µãã©ã°ã¤ã³113 * @author ããªã¢ã³ã³ã¿ã³114 *115 * @param 身代ããæ¡ä»¶_çæ»116 * @desc ããã©ã«ãã®èº«ä»£ããæ¡ä»¶ã§ãããçæ»ããæå¹ã«ãã¾ããOFFã«ããã¨ç¡å¹ã«ãªãã¾ãã(ON/OFF)117 * @default true118 * @type boolean119 *120 * @param 身代ããæ¡ä»¶_å¿
ä¸ä»¥å¤121 * @desc ããã©ã«ãã®èº«ä»£ããæ¡ä»¶ã§ãããå¿
ä¸ä»¥å¤ããæå¹ã«ãã¾ããOFFã«ããã¨ç¡å¹ã«ãªãã¾ãã(ON/OFF)122 * @default true123 * @type boolean124 *125 * @help 以ä¸ã®å
容ã«æ²¿ã£ã¦èº«ä»£ããã®ä»æ§ãæ¡å¼µãã¾ãã126 *127 * 1. ããã©ã«ãã®èº«ä»£ããæ¡ä»¶ã§ãã以ä¸ã®äºã¤ãç¡å¹åã§ãã¾ãã128 * ã»çæ»(æ®HP25%以ä¸)129 * ã»ã¹ãã«ã¿ã¤ããå¿
ä¸ã以å¤130 *131 * ãªããã¹ãã«ã¿ã¤ããå¿
ä¸ã以å¤ãã®æ¡ä»¶ãå¤ãã¨ãé²å¾¡ãªã©ç¡é¢ä¿ã®132 * ã¹ãã«ã«å¯¾ãã¦ãç¡å·®å¥ã«ã身代ããããçºåããããã«ãªãã¾ãã133 * 注æãã¦è¨å®ãã¦ãã ããã134 *135 * 2. 身代ããã®è©³ç´°ãªçºåæ¡ä»¶ãç´°ããè¨å®ã§ãã¾ãã136 * ç¹å¾´ãæãããã¼ã¿ãã¼ã¹ã®ã¡ã¢æ¬ã«ã以ä¸ã®éãè¨è¿°ãã¦ãã ããã137 * ã¡ã¢æ¬ã®ãå
¨ã¦ã®æ¡ä»¶ããæºãããå ´åã«èº«ä»£ãããçºåãã¾ãã138 * åºæ¬çã«ãç¹å¾´ãã®ã身代ãããã¨ã»ããã§è¨è¿°ãã¾ãã139 *140 * ãªããç¹å¾´ãæãããã¼ã¿ãã¼ã¹ã®ã¡ã¢æ¬ã¨ã¯141 * ã¢ã¯ã¿ã¼ãè·æ¥ãæ¦å¨ãé²å
·ãã¹ãã¼ããæµãã£ã©ã®ããããã®ã¡ã¢æ¬ã§ãã142 *143 * <SE_å®è¡è
HPç:50> # å®è¡è
ã®HPã50%以ä¸ã®ã¨ãã®ã¿çºåãã¾ãã144 * <SE_SubjectHPRate:50> # åä¸145 * <SE_対象è
HPç:50> # 対象è
ã®HPã50%以ä¸ã®ã¨ãã®ã¿çºåãã¾ãã(â»1)146 * <SE_TargetHPRate:50> # åä¸147 * <SE_身代ãã対象éå®:1> # 身代ããã®å¯¾è±¡è
ã[1]ã«éå®ãã¾ãã(â»2)148 * <SE_TargetRestriction:1> # åä¸149 * <SE_身代ããã¹ã¤ãã:4> # ã¹ã¤ãã[4]ãONã®ã¨ãã®ã¿çºåãã¾ãã150 * <SE_SubstituteSwitch:4> # åä¸151 * <SE_身代ããè¨ç®å¼:f> # è¨ç®å¼[f]ã®çµæãtrueã®ã¨ãã®ã¿çºåãã¾ãã(â»3)152 * <SE_SubstituteFormula:f> # åä¸153 *154 * â»1 ãã©ã¡ã¼ã¿ããããã©ã«ãã®èº«ä»£ããæ¡ä»¶ã§ãããçæ»ãã155 * ç¡å¹ã«ããå ´åã®ã¿å¤å®ãã¾ãã156 *157 * â»2 <SE_身代ãã対象éå®:n>ã®ã¿ã°ã®å¯¾è±¡è
ãè¨å®ãããå ´åã158 * ç¹å¾´ãæãããã¼ã¿ãã¼ã¹ã®ã¡ã¢æ¬ã«ä»¥ä¸ã®éãè¨è¿°ãã¾ãã159 *160 * <SE_身代ãã対象è
:1> # <SE_身代ãã対象éå®:1>ã®å¯¾è±¡ã«ãªãã¾ãã161 * <SE_SubstituteTarget:1> # åä¸162 *163 * ã身代ãã対象éå®ãã§æå®ãããã©ã¡ã¼ã¿ã¨ä¸è´ããå ´åã«èº«ä»£ãã対象ã«ãªãã¾ãã164 * ä¾ãã°ãã¡ã¢æ¬ã«<SE_身代ãã対象éå®:2>ã¨è¨å
¥ããå ´åãåããã¡ã¢æ¬ã«165 * <SE_身代ãã対象è
:2>ã¨è¨å
¥ããã¦ããç¹å¾´ãæã¤ã¢ã¯ã¿ã¼ã«å¯¾ãã¦ã®ã¿166 * 身代ãããå®è¡ãã¾ãã167 *168 * â»3 ä¸ç´è
åãæ©è½ã§ãã169 * ã¾ããè¨ç®å¼ä¸ã§ä¸çå·ã使ãããå ´åã以ä¸ã®ããã«è¨è¿°ãã¦ãã ããã170 * < â <171 * > â >172 *173 * ä¾ï¼<SE_身代ããè¨ç®å¼:\v[2] > 3> # å¤æ°[2]ã[3]ãã大ããå ´åãçºåãã¾ãã174 *175 * è¨ç®å¼ä¸ã§ã¯ãactionãã§å¯¾è±¡ã¹ãã«ã®Actionãªãã¸ã§ã¯ããåç
§ã§ãã¾ãã176 * ãã¾ãå©ç¨ããã°èº«ä»£ãããçºåããã¹ãã«ãç´°ããéå®ã§ãã¾ãã177 *178 * 以ä¸ãè¨å
¥ä¾ã§ãã179 * <SE_身代ããè¨ç®å¼:action.isAttack()> # é常æ»æã®ã¿èº«ä»£ããçºå180 * <SE_身代ããè¨ç®å¼:action.isPhysical()> # ç©çæ»æã®ã¿èº«ä»£ããçºå181 * <SE_身代ããè¨ç®å¼:action.isForOne()> # åä½å¯¾è±¡ã®ã¿èº«ä»£ããçºå182 *183 * 3. 身代ããçºåæã«ãæå®ããIDã®ã¹ãã«å¹æã身代ããå®è¡è
ã«184 * é©ç¨ããããã¨ãã§ãã¾ãã185 * <SE_身代ããã¹ãã«ID:5> # 身代ããçºåæã«ã¹ãã«[5]ãå®è¡è
ã«é©ç¨ã(â»1)186 * <SE_SubstituteSkillId:5> # åä¸187 *188 * â»1 ãã¡ã¼ã¸ãããã¢ãããã¢ãã¡ã¼ã·ã§ã³çã®æ¼åºã¯è¡¨ç¤ºããã¾ããã189 *190 * 4. 身代ãããç¡å¹ã«ããã¹ãã«ãåå¥æå®ã§ãã¾ãã191 * ã¹ãã«ãããã¯ã¢ã¤ãã ã®ã¡ã¢æ¬ã«ä»¥ä¸ã®éãæå®ãã¦ãã ããã192 * <SE_身代ããç¡å¹>193 * <SE_SubstituteInvalid>194 *195 * ãã®ãã©ã°ã¤ã³ã«ã¯ãã©ã°ã¤ã³ã³ãã³ãã¯ããã¾ããã196 *197 * å©ç¨è¦ç´ï¼198 * ä½è
ã«ç¡æã§æ¹å¤ãåé
å¸ãå¯è½ã§ãå©ç¨å½¢æ
ï¼åç¨ã18ç¦å©ç¨çï¼199 * ã«ã¤ãã¦ãå¶éã¯ããã¾ããã200 * ãã®ãã©ã°ã¤ã³ã¯ããããªãã®ãã®ã§ãã201 */202(function() {203 'use strict';204 var pluginName = 'SubstituteExtend';205 var metaTagPrefix = 'SE_';206 //=============================================================================207 // ãã¼ã«ã«é¢æ°208 // ãã©ã°ã¤ã³ãã©ã¡ã¼ã¿ããã©ã°ã¤ã³ã³ãã³ããã©ã¡ã¼ã¿ã®æ´å½¢ããã§ãã¯ããã¾ã209 //=============================================================================210 var getParamString = function(paramNames) {211 if (!Array.isArray(paramNames)) paramNames = [paramNames];212 for (var i = 0; i < paramNames.length; i++) {213 var name = PluginManager.parameters(pluginName)[paramNames[i]];214 if (name) return name;215 }216 return '';217 };218 var getParamBoolean = function(paramNames) {219 var value = getParamString(paramNames);220 return value.toUpperCase() === 'ON' || value.toUpperCase() === 'TRUE';221 };222 var getMetaValue = function(object, name) {223 var metaTagName = metaTagPrefix + name;224 return object.meta.hasOwnProperty(metaTagName) ? convertEscapeCharacters(object.meta[metaTagName]) : undefined;225 };226 var getMetaValues = function(object, names) {227 for (var i = 0, n = names.length; i < n; i++) {228 var value = getMetaValue(object, names[i]);229 if (value !== undefined) return value;230 }231 return undefined;232 };233 var convertEscapeCharacters = function(text) {234 if (text == null) {235 text = '';236 }237 if (text === true) {238 return text;239 }240 var windowLayer = SceneManager._scene._windowLayer;241 return windowLayer ? windowLayer.children[0].convertEscapeCharacters(text) : text;242 };243 var convertEscapeTags = function(text) {244 if (text == null || text === true) text = '';245 text = text.replace(/>?/gi, '>');246 text = text.replace(/<?/gi, '<');247 return text;248 };249 //=============================================================================250 // ãã©ã¡ã¼ã¿ã®åå¾ã¨æ´å½¢251 //=============================================================================252 var param = {};253 param.condDying = getParamBoolean(['CondDying', '身代ããæ¡ä»¶_çæ»']);254 param.condNonCertainHit = getParamBoolean(['CondNonCertainHit', '身代ããæ¡ä»¶_å¿
ä¸ä»¥å¤']);255 //=============================================================================256 // Game_BattlerBase257 // 身代ãããå®è¡ãããã©ããã®å¤å®ãæ¡å¼µãã¾ãã258 //=============================================================================259 var _Game_BattlerBase_isSubstitute = Game_BattlerBase.prototype.isSubstitute;260 Game_BattlerBase.prototype.isSubstitute = function() {261 return _Game_BattlerBase_isSubstitute.apply(this, arguments) && this.isSubstituteExtend();262 };263 Game_BattlerBase.prototype.isSubstituteExtend = function() {264 return this.isValidSubstituteHpRate() &&265 (param.condDying || this.isValidSubstituteTargetHpRate()) &&266 this.isValidSubstituteSwitch() &&267 this.isValidSubstituteRestriction() &&268 this.isValidSubstituteFormula() &&269 this.isValidSubstituteSkill();270 };271 Game_BattlerBase.prototype.isValidSubstituteHpRate = function() {272 var subjectHpRate = this.getSubstituteMetaInfo(['SubjectHPRate', 'å®è¡è
HPç'], true);273 if (subjectHpRate) {274 return this.hpRate() >= subjectHpRate / 100;275 }276 return true;277 };278 Game_BattlerBase.prototype.isValidSubstituteTargetHpRate = function() {279 var targetHpRate = this.getSubstituteMetaInfo(['TargetHPRate', '対象è
HPç'], true);280 if (targetHpRate) {281 return BattleManager.checkSubstituteTargetHpRate(targetHpRate);282 }283 return true;284 };285 Game_BattlerBase.prototype.isValidSubstituteRestriction = function() {286 var restrictionId = this.getSubstituteMetaInfo(['TargetRestriction', '身代ãã対象éå®'], true);287 if (restrictionId) {288 return BattleManager.checkSubstituteRestriction(restrictionId);289 }290 return true;291 };292 Game_BattlerBase.prototype.isValidSubstituteSwitch = function() {293 var switchId = this.getSubstituteMetaInfo(['SubstituteSwitch', '身代ããã¹ã¤ãã'], true);294 if (switchId) {295 return $gameSwitches.value(switchId);296 }297 return true;298 };299 Game_BattlerBase.prototype.isValidSubstituteFormula = function() {300 var formula = this.getSubstituteMetaInfo(['SubstituteFormula', '身代ããè¨ç®å¼'], false);301 if (formula) {302 var action = BattleManager.getSubstituteAction();303 return eval(convertEscapeTags(formula));304 }305 return true;306 };307 Game_BattlerBase.prototype.isValidSubstituteSkill = function() {308 return !getMetaValues(BattleManager.getSubstituteAction().item(), ['SubstituteInvalid', '身代ããç¡å¹']);309 };310 Game_BattlerBase.prototype.isEqualSubstituteRestrictionId = function(restrictionId) {311 var restrictionTargetId = this.getSubstituteMetaInfo(['SubstituteTarget', '身代ãã対象è
'], true);312 return restrictionTargetId === restrictionId;313 };314 Game_BattlerBase.prototype.getSubstituteSkillId = function() {315 return this.getSubstituteMetaInfo(['SubstituteSkillId', '身代ããã¹ãã«ID'], true);316 };317 Game_BattlerBase.prototype.getSubstituteMetaInfo = function(tagNames, isNumber) {318 var metaValue;319 this.traitObjects().some(function(traitObject) {320 metaValue = getMetaValues(traitObject, tagNames);321 return !!metaValue;322 });323 return (metaValue && isNumber) ? parseInt(metaValue) : metaValue;324 };325 //=============================================================================326 // BattleManager327 // 身代ãã対象è
ã®æ
å ±ãä¿æãã¦å¿
è¦ã«å¿ãã¦è©ä¾¡ãã¾ãã328 //=============================================================================329 var _BattleManager_applySubstitute = BattleManager.applySubstitute;330 BattleManager.applySubstitute = function(target) {331 this._substituteTarget = target;332 var substitute = _BattleManager_applySubstitute.apply(this, arguments);333 this._substituteTarget = null;334 if (substitute !== target) {335 this.applySubstituteEffect(substitute);336 }337 return substitute;338 };339 BattleManager.applySubstituteEffect = function(substitute) {340 var skillId = substitute.getSubstituteSkillId();341 if (!skillId) return;342 var action = new Game_Action(substitute);343 action.setSkill(skillId);344 action.apply(substitute);345 };346 BattleManager.checkSubstituteTargetHpRate = function(hpRate) {347 return this._substituteTarget ? this._substituteTarget.hpRate() <= hpRate / 100 : true;348 };349 BattleManager.checkSubstituteRestriction = function(restrictionId) {350 return this._substituteTarget ? this._substituteTarget.isEqualSubstituteRestrictionId(restrictionId) : true;351 };352 BattleManager.getSubstituteAction = function() {353 return this._action;354 };355 var _BattleManager_checkSubstitute = BattleManager.checkSubstitute;356 BattleManager.checkSubstitute = function(target) {357 var resultSubstitute = _BattleManager_checkSubstitute.apply(this, arguments);358 if (!resultSubstitute) {359 return this.checkSubstituteDefault(target);360 }361 return resultSubstitute;362 };363 BattleManager.checkSubstituteDefault = function(target) {364 return this.isValidSubstituteDying(target) && this.isValidSubstituteCertainHit();365 };366 BattleManager.isValidSubstituteDying = function(target) {367 return !param.condDying || target.isDying();368 };369 BattleManager.isValidSubstituteCertainHit = function() {370 return !param.condNonCertainHit || !this._action.isCertainHit();371 };...
substitute-coverage.js
Source:substitute-coverage.js
...31 calledFunctions: 0,32 path: "build/substitute/substitute.js",33 code: []34};35_yuitest_coverage["build/substitute/substitute.js"].code=["YUI.add('substitute', function (Y, NAME) {","","/**"," * String variable substitution and string formatting."," * If included, the substitute method is added to the YUI instance."," *"," * @module substitute"," */",""," var L = Y.Lang, DUMP = 'dump', SPACE = ' ', LBRACE = '{', RBRACE = '}',"," savedRegExp = /(~-(\\d+)-~)/g, lBraceRegExp = /\\{LBRACE\\}/g, rBraceRegExp = /\\{RBRACE\\}/g,",""," /**"," * The following methods are added to the YUI instance"," * @class YUI~substitute"," */",""," /**"," Does {placeholder} substitution on a string. The object passed as the"," second parameter provides values to replace the {placeholder}s."," {placeholder} token names must match property names of the object. For"," example",""," `var greeting = Y.substitute(\"Hello, {who}!\", { who: \"World\" });`",""," {placeholder} tokens that are undefined on the object map will be left in"," tact (leaving unsightly \"{placeholder}\"s in the output string). If your"," replacement strings *should* include curly braces, use `{LBRACE}` and"," `{RBRACE}` in your object map string value.",""," If a function is passed as a third argument, it will be called for each"," {placeholder} found. The {placeholder} name is passed as the first value"," and the value from the object map is passed as the second. If the"," {placeholder} contains a space, the first token will be used to identify"," the object map property and the remainder will be passed as a third"," argument to the function. See below for an example."," "," If the value in the object map for a given {placeholder} is an object and"," the `dump` module is loaded, the replacement value will be the string"," result of calling `Y.dump(...)` with the object as input. Include a"," numeric second token in the {placeholder} to configure the depth of the call"," to `Y.dump(...)`, e.g. \"{someObject 2}\". See the"," <a href=\"../classes/YUI.html#method_dump\">`dump`</a> method for details.",""," @method substitute"," @param {string} s The string that will be modified."," @param {object} o An object containing the replacement values."," @param {function} f An optional function that can be used to"," process each match. It receives the key,"," value, and any extra metadata included with"," the key inside of the braces."," @param {boolean} recurse if true, the replacement will be recursive,"," letting you have replacement tokens in replacement text."," The default is false."," @return {string} the substituted string.",""," @example",""," function getAttrVal(key, value, name) {"," // Return a string describing the named attribute and its value if"," // the first token is @. Otherwise, return the value from the"," // replacement object."," if (key === \"@\") {"," value += name + \" Value: \" + myObject.get(name);"," }"," return value;"," }",""," // Assuming myObject.set('foo', 'flowers'),"," // => \"Attr: foo Value: flowers\""," var attrVal = Y.substitute(\"{@ foo}\", { \"@\": \"Attr: \" }, getAttrVal);"," **/",""," substitute = function(s, o, f, recurse) {"," var i, j, k, key, v, meta, saved = [], token, dump,"," lidx = s.length;",""," for (;;) {"," i = s.lastIndexOf(LBRACE, lidx);"," if (i < 0) {"," break;"," }"," j = s.indexOf(RBRACE, i);"," if (i + 1 >= j) {"," break;"," }",""," //Extract key and meta info"," token = s.substring(i + 1, j);"," key = token;"," meta = null;"," k = key.indexOf(SPACE);"," if (k > -1) {"," meta = key.substring(k + 1);"," key = key.substring(0, k);"," }",""," // lookup the value"," v = o[key];",""," // if a substitution function was provided, execute it"," if (f) {"," v = f(key, v, meta);"," }",""," if (L.isObject(v)) {"," if (!Y.dump) {"," v = v.toString();"," } else {"," if (L.isArray(v)) {"," v = Y.dump(v, parseInt(meta, 10));"," } else {"," meta = meta || '';",""," // look for the keyword 'dump', if found force obj dump"," dump = meta.indexOf(DUMP);"," if (dump > -1) {"," meta = meta.substring(4);"," }",""," // use the toString if it is not the Object toString"," // and the 'dump' meta info was not found"," if (v.toString === Object.prototype.toString ||"," dump > -1) {"," v = Y.dump(v, parseInt(meta, 10));"," } else {"," v = v.toString();"," }"," }"," }"," } else if (L.isUndefined(v)) {"," // This {block} has no replace string. Save it for later."," v = '~-' + saved.length + '-~';"," saved.push(token);",""," // break;"," }",""," s = s.substring(0, i) + v + s.substring(j + 1);",""," if (!recurse) {"," lidx = i - 1;"," } "," }"," // restore saved {block}s and escaped braces",""," return s"," .replace(savedRegExp, function (str, p1, p2) {"," return LBRACE + saved[parseInt(p2,10)] + RBRACE;"," })"," .replace(lBraceRegExp, LBRACE)"," .replace(rBraceRegExp, RBRACE)"," ;"," };",""," Y.substitute = substitute;"," L.substitute = substitute;","","","","}, '3.7.3', {\"requires\": [\"yui-base\"], \"optional\": [\"dump\"]});"];36_yuitest_coverage["build/substitute/substitute.js"].lines = {"1":0,"10":0,"75":0,"78":0,"79":0,"80":0,"81":0,"83":0,"84":0,"85":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"99":0,"102":0,"103":0,"106":0,"107":0,"108":0,"110":0,"111":0,"113":0,"116":0,"117":0,"118":0,"123":0,"125":0,"127":0,"131":0,"133":0,"134":0,"139":0,"141":0,"142":0,"147":0,"149":0,"156":0,"157":0};37_yuitest_coverage["build/substitute/substitute.js"].functions = {"(anonymous 2):148":0,"substitute:74":0,"(anonymous 1):1":0};38_yuitest_coverage["build/substitute/substitute.js"].coveredLines = 42;39_yuitest_coverage["build/substitute/substitute.js"].coveredFunctions = 3;40_yuitest_coverline("build/substitute/substitute.js", 1);41YUI.add('substitute', function (Y, NAME) {42/**43 * String variable substitution and string formatting.44 * If included, the substitute method is added to the YUI instance.45 *46 * @module substitute47 */48 _yuitest_coverfunc("build/substitute/substitute.js", "(anonymous 1)", 1);49_yuitest_coverline("build/substitute/substitute.js", 10);50var L = Y.Lang, DUMP = 'dump', SPACE = ' ', LBRACE = '{', RBRACE = '}',51 savedRegExp = /(~-(\d+)-~)/g, lBraceRegExp = /\{LBRACE\}/g, rBraceRegExp = /\{RBRACE\}/g,52 /**53 * The following methods are added to the YUI instance54 * @class YUI~substitute55 */56 /**57 Does {placeholder} substitution on a string. The object passed as the58 second parameter provides values to replace the {placeholder}s.59 {placeholder} token names must match property names of the object. For60 example61 `var greeting = Y.substitute("Hello, {who}!", { who: "World" });`62 {placeholder} tokens that are undefined on the object map will be left in63 tact (leaving unsightly "{placeholder}"s in the output string). If your64 replacement strings *should* include curly braces, use `{LBRACE}` and65 `{RBRACE}` in your object map string value.66 If a function is passed as a third argument, it will be called for each67 {placeholder} found. The {placeholder} name is passed as the first value68 and the value from the object map is passed as the second. If the69 {placeholder} contains a space, the first token will be used to identify70 the object map property and the remainder will be passed as a third71 argument to the function. See below for an example.72 73 If the value in the object map for a given {placeholder} is an object and74 the `dump` module is loaded, the replacement value will be the string75 result of calling `Y.dump(...)` with the object as input. Include a76 numeric second token in the {placeholder} to configure the depth of the call77 to `Y.dump(...)`, e.g. "{someObject 2}". See the78 <a href="../classes/YUI.html#method_dump">`dump`</a> method for details.79 @method substitute80 @param {string} s The string that will be modified.81 @param {object} o An object containing the replacement values.82 @param {function} f An optional function that can be used to83 process each match. It receives the key,84 value, and any extra metadata included with85 the key inside of the braces.86 @param {boolean} recurse if true, the replacement will be recursive,87 letting you have replacement tokens in replacement text.88 The default is false.89 @return {string} the substituted string.90 @example91 function getAttrVal(key, value, name) {92 // Return a string describing the named attribute and its value if93 // the first token is @. Otherwise, return the value from the94 // replacement object.95 if (key === "@") {96 value += name + " Value: " + myObject.get(name);97 }98 return value;99 }100 // Assuming myObject.set('foo', 'flowers'),101 // => "Attr: foo Value: flowers"102 var attrVal = Y.substitute("{@ foo}", { "@": "Attr: " }, getAttrVal);103 **/104 substitute = function(s, o, f, recurse) {105 _yuitest_coverfunc("build/substitute/substitute.js", "substitute", 74);106_yuitest_coverline("build/substitute/substitute.js", 75);107var i, j, k, key, v, meta, saved = [], token, dump,108 lidx = s.length;109 _yuitest_coverline("build/substitute/substitute.js", 78);110for (;;) {111 _yuitest_coverline("build/substitute/substitute.js", 79);112i = s.lastIndexOf(LBRACE, lidx);113 _yuitest_coverline("build/substitute/substitute.js", 80);114if (i < 0) {115 _yuitest_coverline("build/substitute/substitute.js", 81);116break;...
table-overview-example.ts
Source:table-overview-example.ts
1import {Component, OnInit, ViewChild} from '@angular/core';2import {MatPaginator, MatSort, MatTableDataSource} from '@angular/material';34export interface UserData {5 version: string;6 position: number;7 code: string;8 codeType: string;9 Description:string10}1112const users=[13 {"version":"1.0", "position": 1, "code": "0SRC0LA", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Unicondylar Synthetic Substitute- Uncemented- Open Approach"},14 {"version":"1.0", "position": 2, "code": "0SRC0LZ", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Unicondylar Synthetic Substitute- Open Approach"},15 {"version":"1.0", "position": 3, "code": "0SRC0L9", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Unicondylar Synthetic Substitute- Cemented- Open Approach"},16 {"version":"1.0", "position": 4, "code": "0SRC0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Synthetic Substitute- Uncemented- Open Approach"},17 {"version":"1.0", "position": 5, "code": "0SRC0JZ", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Synthetic Substitute- Open Approach"},18 {"version":"1.0", "position": 6, "code": "0SRC0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Synthetic Substitute- Cemented- Open Approach"},19 {"version":"1.0", "position": 7, "code": "0SRC0KZ", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Nonautologous Tissue Substitute- Open Approach"},20 {"version":"1.0", "position": 7, "code": "0SRC07Z", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Autologous Tissue Substitute- Open Approach"},21 {"version":"1.0", "position": 8, "code": "0SRD0LA", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Unicondylar Synthetic Substitute- Uncemented- Open Approach"},22 {"version":"1.0", "position": 9, "code": "0SRD0LZ", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Unicondylar Synthetic Substitute- Open Approach"},23 {"version":"1.0", "position": 10, "code": "0SRD0L9", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Unicondylar Synthetic Substitute- Cemented- Open Approach"},24 {"version":"1.0", "position": 11, "code": "0SRD0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Synthetic Substitute- Uncemented- Open Approach"},25 {"version":"1.0", "position": 12, "code": "0SRD0JZ", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Synthetic Substitute- Open Approach"},26 {"version":"1.0", "position": 13, "code": "0SRD0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Synthetic Substitute- Cemented- Open Approach"},27 {"version":"1.0", "position": 14, "code": "0SRD0KZ", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Nonautologous Tissue Substitute- Open Approach"},28 {"version":"1.0", "position": 15, "code": "0SRD07Z", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Autologous Tissue Substitute- Open Approach"},29 {"version":"1.0", "position": 16, "code": "0SRT0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint, Femoral Surface with Synthetic Substitute, Cemented, Open Approach"},30 {"version":"1.0", "position": 17, "code": "0SRT0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint, Femoral Surface with Synthetic Substitute, Uncemented, Open Approach"},31 {"version":"1.0", "position": 18, "code": "0SRU0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint, Femoral Surface with Synthetic Substitute, Cemented, Open Approach"},32 {"version":"1.0", "position": 19, "code": "0SRU0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint, Femoral Surface with Synthetic Substitute, Uncemented, Open Approach"},33 {"version":"1.0", "position": 20, "code": "0SRV0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint, Tibial Surface with Synthetic Substitute, Cemented, Open Approach"},34 {"version":"1.0", "position": 21, "code": "0SRV0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint, Tibial Surface with Synthetic Substitute, Uncemented, Open Approach"},35 {"version":"1.0", "position": 22, "code": "0SRW0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint, Tibial Surface with Synthetic Substitute, Cemented, Open Approach"},36 {"version":"1.0", "position": 23, "code": "0SRW0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint, Tibial Surface with Synthetic Substitute, Uncemented, Open Approach"},37 {"version":"1.0", "position": 24, "code": "27447", "codeType": "CPT", "Description": "Total knee replacement"},38 {"version":"1.0", "position": 24, "code": "81.54", "codeType": "ICD9-Procedure", "Description": "Total knee replacement"}39 ,40 {"version":"2.0", "position": 1, "code": "0SRC0LAv2", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Unicondylar Synthetic Substitute- Uncemented- Open Approach"},41 {"version":"2.0", "position": 2, "code": "0SRC0LZ", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Unicondylar Synthetic Substitute- Open Approach"},42 {"version":"2.0", "position": 3, "code": "0SRC0L9", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Unicondylar Synthetic Substitute- Cemented- Open Approach"},43 {"version":"2.0", "position": 4, "code": "0SRC0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Synthetic Substitute- Uncemented- Open Approach"},44 {"version":"2.0", "position": 5, "code": "0SRC0JZ", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Synthetic Substitute- Open Approach"},45 {"version":"2.0", "position": 6, "code": "0SRC0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Synthetic Substitute- Cemented- Open Approach"},46 {"version":"2.0", "position": 7, "code": "0SRC0KZ", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Nonautologous Tissue Substitute- Open Approach"},47 {"version":"2.0", "position": 7, "code": "0SRC07Z", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint with Autologous Tissue Substitute- Open Approach"},48 {"version":"2.0", "position": 8, "code": "0SRD0LA", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Unicondylar Synthetic Substitute- Uncemented- Open Approach"},49 {"version":"2.0", "position": 9, "code": "0SRD0LZ", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Unicondylar Synthetic Substitute- Open Approach"},50 {"version":"2.0", "position": 10, "code": "0SRD0L9", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Unicondylar Synthetic Substitute- Cemented- Open Approach"},51 {"version":"2.0", "position": 11, "code": "0SRD0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Synthetic Substitute- Uncemented- Open Approach"},52 {"version":"2.0", "position": 12, "code": "0SRD0JZ", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Synthetic Substitute- Open Approach"},53 {"version":"2.0", "position": 13, "code": "0SRD0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Synthetic Substitute- Cemented- Open Approach"},54 {"version":"2.0", "position": 14, "code": "0SRD0KZ", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Nonautologous Tissue Substitute- Open Approach"},55 {"version":"2.0", "position": 15, "code": "0SRD07Z", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint with Autologous Tissue Substitute- Open Approach"},56 {"version":"2.0", "position": 16, "code": "0SRT0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint, Femoral Surface with Synthetic Substitute, Cemented, Open Approach"},57 {"version":"2.0", "position": 17, "code": "0SRT0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint, Femoral Surface with Synthetic Substitute, Uncemented, Open Approach"},58 {"version":"2.0", "position": 18, "code": "0SRU0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint, Femoral Surface with Synthetic Substitute, Cemented, Open Approach"},59 {"version":"2.0", "position": 19, "code": "0SRU0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint, Femoral Surface with Synthetic Substitute, Uncemented, Open Approach"},60 {"version":"2.0", "position": 20, "code": "0SRV0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint, Tibial Surface with Synthetic Substitute, Cemented, Open Approach"},61 {"version":"2.0", "position": 21, "code": "0SRV0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Right Knee Joint, Tibial Surface with Synthetic Substitute, Uncemented, Open Approach"},62 {"version":"2.0", "position": 22, "code": "0SRW0J9", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint, Tibial Surface with Synthetic Substitute, Cemented, Open Approach"},63 {"version":"2.0", "position": 23, "code": "0SRW0JA", "codeType": "ICD10-PCS", "Description": "Replacement of Left Knee Joint, Tibial Surface with Synthetic Substitute, Uncemented, Open Approach"},64 {"version":"2.0", "position": 24, "code": "27447", "codeType": "CPT", "Description": "Total knee replacement"},65 {"version":"2.0", "position": 24, "code": "81.54", "codeType": "ICD9-Procedure", "Description": "Total knee replacement"}]6667/**68 * @title Data table with sorting, pagination, and filtering.69 */70@Component({71 selector: 'table-overview-example',72 styleUrls: ['table-overview-example.css'],73 templateUrl: 'table-overview-example.html',74})75export class TableOverviewExample implements OnInit {76 versions=["1.0","2.0"]77 displayedColumns: string[] = ['position', 'code', 'codeType', 'Description'];78 columnsToDisplay: string[] = this.displayedColumns.slice();7980 dataSource: MatTableDataSource<UserData>;8182 @ViewChild(MatPaginator) paginator: MatPaginator;83 @ViewChild(MatSort) sort: MatSort;8485 constructor() {86 // Create 100 users87 8889 // Assign the data to the data source for the table to render90 this.dataSource = new MatTableDataSource(users);91 }9293 ngOnInit() {94 this.dataSource.paginator = this.paginator;95 this.dataSource.sort = this.sort;96 }9798 applyFilter(filterValue: string) {99 console.log(filterValue);100 this.dataSource.filter = filterValue.trim().toLowerCase();101102 if (this.dataSource.paginator) {103 this.dataSource.paginator.firstPage();104 }105 }106}107108109110111/** Copyright 2018 Google Inc. All Rights Reserved.112 Use of this source code is governed by an MIT-style license that
...
test_pep292.py
Source:test_pep292.py
...16 return obj17class TestTemplate(unittest.TestCase):18 def test_regular_templates(self):19 s = Template('$who likes to eat a bag of $what worth $$100')20 self.assertEqual(s.substitute(dict(who='tim', what='ham')),21 'tim likes to eat a bag of ham worth $100')22 self.assertRaises(KeyError, s.substitute, dict(who='tim'))23 def test_regular_templates_with_braces(self):24 s = Template('$who likes ${what} for ${meal}')25 d = dict(who='tim', what='ham', meal='dinner')26 self.assertEqual(s.substitute(d), 'tim likes ham for dinner')27 self.assertRaises(KeyError, s.substitute,28 dict(who='tim', what='ham'))29 def test_escapes(self):30 eq = self.assertEqual31 s = Template('$who likes to eat a bag of $$what worth $$100')32 eq(s.substitute(dict(who='tim', what='ham')),33 'tim likes to eat a bag of $what worth $100')34 s = Template('$who likes $$')35 eq(s.substitute(dict(who='tim', what='ham')), 'tim likes $')36 def test_percents(self):37 eq = self.assertEqual38 s = Template('%(foo)s $foo ${foo}')39 d = dict(foo='baz')40 eq(s.substitute(d), '%(foo)s baz baz')41 eq(s.safe_substitute(d), '%(foo)s baz baz')42 def test_stringification(self):43 eq = self.assertEqual44 s = Template('tim has eaten $count bags of ham today')45 d = dict(count=7)46 eq(s.substitute(d), 'tim has eaten 7 bags of ham today')47 eq(s.safe_substitute(d), 'tim has eaten 7 bags of ham today')48 s = Template('tim has eaten ${count} bags of ham today')49 eq(s.substitute(d), 'tim has eaten 7 bags of ham today')50 def test_tupleargs(self):51 eq = self.assertEqual52 s = Template('$who ate ${meal}')53 d = dict(who=('tim', 'fred'), meal=('ham', 'kung pao'))54 eq(s.substitute(d), "('tim', 'fred') ate ('ham', 'kung pao')")55 eq(s.safe_substitute(d), "('tim', 'fred') ate ('ham', 'kung pao')")56 def test_SafeTemplate(self):57 eq = self.assertEqual58 s = Template('$who likes ${what} for ${meal}')59 eq(s.safe_substitute(dict(who='tim')), 'tim likes ${what} for ${meal}')60 eq(s.safe_substitute(dict(what='ham')), '$who likes ham for ${meal}')61 eq(s.safe_substitute(dict(what='ham', meal='dinner')),62 '$who likes ham for dinner')63 eq(s.safe_substitute(dict(who='tim', what='ham')),64 'tim likes ham for ${meal}')65 eq(s.safe_substitute(dict(who='tim', what='ham', meal='dinner')),66 'tim likes ham for dinner')67 def test_invalid_placeholders(self):68 raises = self.assertRaises69 s = Template('$who likes $')70 raises(ValueError, s.substitute, dict(who='tim'))71 s = Template('$who likes ${what)')72 raises(ValueError, s.substitute, dict(who='tim'))73 s = Template('$who likes $100')74 raises(ValueError, s.substitute, dict(who='tim'))75 def test_idpattern_override(self):76 class PathPattern(Template):77 idpattern = r'[_a-z][._a-z0-9]*'78 m = Mapping()79 m.bag = Bag()80 m.bag.foo = Bag()81 m.bag.foo.who = 'tim'82 m.bag.what = 'ham'83 s = PathPattern('$bag.foo.who likes to eat a bag of $bag.what')84 self.assertEqual(s.substitute(m), 'tim likes to eat a bag of ham')85 def test_pattern_override(self):86 class MyPattern(Template):87 pattern = r"""88 (?P<escaped>@{2}) |89 @(?P<named>[_a-z][._a-z0-9]*) |90 @{(?P<braced>[_a-z][._a-z0-9]*)} |91 (?P<invalid>@)92 """93 m = Mapping()94 m.bag = Bag()95 m.bag.foo = Bag()96 m.bag.foo.who = 'tim'97 m.bag.what = 'ham'98 s = MyPattern('@bag.foo.who likes to eat a bag of @bag.what')99 self.assertEqual(s.substitute(m), 'tim likes to eat a bag of ham')100 class BadPattern(Template):101 pattern = r"""102 (?P<badname>.*) |103 (?P<escaped>@{2}) |104 @(?P<named>[_a-z][._a-z0-9]*) |105 @{(?P<braced>[_a-z][._a-z0-9]*)} |106 (?P<invalid>@) |107 """108 s = BadPattern('@bag.foo.who likes to eat a bag of @bag.what')109 self.assertRaises(ValueError, s.substitute, {})110 self.assertRaises(ValueError, s.safe_substitute, {})111 def test_unicode_values(self):112 s = Template('$who likes $what')113 d = dict(who=u't\xffm', what=u'f\xfe\fed')114 self.assertEqual(s.substitute(d), u't\xffm likes f\xfe\x0ced')115 def test_keyword_arguments(self):116 eq = self.assertEqual117 s = Template('$who likes $what')118 eq(s.substitute(who='tim', what='ham'), 'tim likes ham')119 eq(s.substitute(dict(who='tim'), what='ham'), 'tim likes ham')120 eq(s.substitute(dict(who='fred', what='kung pao'),121 who='tim', what='ham'),122 'tim likes ham')123 s = Template('the mapping is $mapping')124 eq(s.substitute(dict(foo='none'), mapping='bozo'),125 'the mapping is bozo')126 eq(s.substitute(dict(mapping='one'), mapping='two'),127 'the mapping is two')128 def test_keyword_arguments_safe(self):129 eq = self.assertEqual130 raises = self.assertRaises131 s = Template('$who likes $what')132 eq(s.safe_substitute(who='tim', what='ham'), 'tim likes ham')133 eq(s.safe_substitute(dict(who='tim'), what='ham'), 'tim likes ham')134 eq(s.safe_substitute(dict(who='fred', what='kung pao'),135 who='tim', what='ham'),136 'tim likes ham')137 s = Template('the mapping is $mapping')138 eq(s.safe_substitute(dict(foo='none'), mapping='bozo'),139 'the mapping is bozo')140 eq(s.safe_substitute(dict(mapping='one'), mapping='two'),141 'the mapping is two')142 d = dict(mapping='one')143 raises(TypeError, s.substitute, d, {})144 raises(TypeError, s.safe_substitute, d, {})145 def test_delimiter_override(self):146 eq = self.assertEqual147 raises = self.assertRaises148 class AmpersandTemplate(Template):149 delimiter = '&'150 s = AmpersandTemplate('this &gift is for &{who} &&')151 eq(s.substitute(gift='bud', who='you'), 'this bud is for you &')152 raises(KeyError, s.substitute)153 eq(s.safe_substitute(gift='bud', who='you'), 'this bud is for you &')154 eq(s.safe_substitute(), 'this &gift is for &{who} &')155 s = AmpersandTemplate('this &gift is for &{who} &')156 raises(ValueError, s.substitute, dict(gift='bud', who='you'))157 eq(s.safe_substitute(), 'this &gift is for &{who} &')158 class PieDelims(Template):159 delimiter = '@'160 s = PieDelims('@who likes to eat a bag of @{what} worth $100')161 self.assertEqual(s.substitute(dict(who='tim', what='ham')),162 'tim likes to eat a bag of ham worth $100')163def test_main():164 from test import test_support165 test_classes = [TestTemplate,]166 test_support.run_unittest(*test_classes)167if __name__ == '__main__':...
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!!