Best Python code snippet using slash
test_paddlerec_models.py
Source:test_paddlerec_models.py
...18 """test contentunderstanding.tagspace."""19 self.yaml_config_name = 'models/contentunderstanding/tagspace/config.yaml'20 self.run_yaml(generate=False)21 built_in.equals(self.pro.returncode, 0, self.err_msg)22 built_in.not_contains(self.err, 'Traceback', self.err_msg)23 def test_tagspace_gpu(self):24 """test contentunderstanding.tagspace with gpu."""25 self.yaml_config_name = "models/contentunderstanding/tagspace/config.yaml"26 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)27 utils.cmd_shell(sed_gpu_cmd)28 self.run_yaml(generate=False, cuda_devices="0")29 built_in.equals(self.pro.returncode, 0, self.err_msg)30 built_in.not_contains(self.err, 'Traceback', self.err_msg)31 def test_dssm(self):32 """test match.dssm."""33 self.yaml_config_name = 'models/match/dssm/config.yaml'34 self.run_yaml(generate=False)35 built_in.equals(self.pro.returncode, 0, self.err_msg)36 built_in.not_contains(self.err, 'Traceback', self.err_msg)37 def test_dssm_gpu(self):38 """test match.dssm with gpu."""39 self.yaml_config_name = "models/match/dssm/config.yaml"40 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)41 utils.cmd_shell(sed_gpu_cmd)42 self.run_yaml(generate=False, cuda_devices="0")43 built_in.equals(self.pro.returncode, 0, self.err_msg)44 built_in.not_contains(self.err, 'Traceback', self.err_msg)45 def test_multiview_simnet(self):46 """test match.multiview_simnet."""47 self.yaml_config_name = 'models/match/multiview-simnet/config.yaml'48 self.run_yaml(generate=False)49 built_in.equals(self.pro.returncode, 0, self.err_msg)50 built_in.not_contains(self.err, 'Traceback', self.err_msg)51 def test_multiview_simnet_gpu(self):52 """test match.multiview_simnet with gpu."""53 self.yaml_config_name = "models/match/multiview-simnet/config.yaml"54 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)55 utils.cmd_shell(sed_gpu_cmd)56 self.run_yaml(generate=False, cuda_devices="0")57 built_in.equals(self.pro.returncode, 0, self.err_msg)58 built_in.not_contains(self.err, 'Traceback', self.err_msg)59 def test_esmm(self):60 """test multitask.esmm."""61 self.yaml_config_name = 'models/multitask/esmm/config.yaml'62 self.run_yaml(generate=False)63 built_in.equals(self.pro.returncode, 0, self.err_msg)64 built_in.not_contains(self.err, 'Traceback', self.err_msg)65 def test_esmm_gpu(self):66 """test multitask.esmm with gpu."""67 self.yaml_config_name = "models/multitask/esmm/config.yaml"68 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)69 utils.cmd_shell(sed_gpu_cmd)70 self.run_yaml(generate=False, cuda_devices="0")71 built_in.equals(self.pro.returncode, 0, self.err_msg)72 built_in.not_contains(self.err, 'Traceback', self.err_msg)73 def test_mmoe(self):74 """test multitask.mmoe."""75 self.yaml_config_name = 'models/multitask/mmoe/config.yaml'76 self.run_yaml(generate=False)77 built_in.equals(self.pro.returncode, 0, self.err_msg)78 built_in.not_contains(self.err, 'Traceback', self.err_msg)79 def test_mmoe_gpu(self):80 """test multitask.mmoe with gpu."""81 self.yaml_config_name = "models/multitask/mmoe/config.yaml"82 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)83 utils.cmd_shell(sed_gpu_cmd)84 self.run_yaml(generate=False, cuda_devices="0")85 built_in.equals(self.pro.returncode, 0, self.err_msg)86 built_in.not_contains(self.err, 'Traceback', self.err_msg)87 def test_share_bottom(self):88 """test multitask.share-bottom."""89 self.yaml_config_name = 'models/multitask/share-bottom/config.yaml'90 self.run_yaml(generate=False)91 built_in.equals(self.pro.returncode, 0, self.err_msg)92 built_in.not_contains(self.err, 'Traceback', self.err_msg)93 def test_share_bottom_gpu(self):94 """test multitask.share-bottom with gpu."""95 self.yaml_config_name = "models/multitask/share-bottom/config.yaml"96 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)97 utils.cmd_shell(sed_gpu_cmd)98 self.run_yaml(generate=False, cuda_devices="0")99 built_in.equals(self.pro.returncode, 0, self.err_msg)100 built_in.not_contains(self.err, 'Traceback', self.err_msg)101 def test_afm(self):102 """test ran.afm."""103 self.yaml_config_name = 'models/rank/afm/config.yaml'104 self.run_yaml(generate=False)105 built_in.equals(self.pro.returncode, 0, self.err_msg)106 built_in.not_contains(self.err, 'Traceback', self.err_msg)107 def test_afm_gpu(self):108 """test rank.afm with gpu."""109 self.yaml_config_name = "models/rank/afm/config.yaml"110 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)111 utils.cmd_shell(sed_gpu_cmd)112 self.run_yaml(generate=False, cuda_devices="0")113 built_in.equals(self.pro.returncode, 0, self.err_msg)114 built_in.not_contains(self.err, 'Traceback', self.err_msg)115 def test_dcn(self):116 """test ran.dcn."""117 self.yaml_config_name = 'models/rank/dcn/config.yaml'118 self.run_yaml(generate=False)119 built_in.equals(self.pro.returncode, 0, self.err_msg)120 built_in.not_contains(self.err, 'Traceback', self.err_msg)121 def test_dcn_gpu(self):122 """test rank.afm with gpu."""123 self.yaml_config_name = "models/rank/dcn/config.yaml"124 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)125 utils.cmd_shell(sed_gpu_cmd)126 self.run_yaml(generate=False, cuda_devices="0")127 built_in.equals(self.pro.returncode, 0, self.err_msg)128 built_in.not_contains(self.err, 'Traceback', self.err_msg)129 def test_deep_crossing(self):130 """test ran.deep_crossing."""131 self.yaml_config_name = 'models/rank/deep_crossing/config.yaml'132 self.run_yaml(generate=False)133 built_in.equals(self.pro.returncode, 0, self.err_msg)134 built_in.not_contains(self.err, 'Traceback', self.err_msg)135 def test_deep_crossing_gpu(self):136 """test rank.deep_crossing with gpu."""137 self.yaml_config_name = "models/rank/deep_crossing/config.yaml"138 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)139 utils.cmd_shell(sed_gpu_cmd)140 self.run_yaml(generate=False, cuda_devices="0")141 built_in.equals(self.pro.returncode, 0, self.err_msg)142 built_in.not_contains(self.err, 'Traceback', self.err_msg)143 def test_deepfm(self):144 """test ran.deepfm."""145 self.yaml_config_name = 'models/rank/deepfm/config.yaml'146 self.run_yaml(generate=False)147 built_in.equals(self.pro.returncode, 0, self.err_msg)148 built_in.not_contains(self.err, 'Traceback', self.err_msg)149 def test_deepfm_gpu(self):150 """test rank.deepfm with gpu."""151 self.yaml_config_name = "models/rank/deepfm/config.yaml"152 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)153 utils.cmd_shell(sed_gpu_cmd)154 self.run_yaml(generate=False, cuda_devices="0")155 built_in.equals(self.pro.returncode, 0, self.err_msg)156 built_in.not_contains(self.err, 'Traceback', self.err_msg)157 def test_din(self):158 """test ran.din."""159 self.yaml_config_name = 'models/rank/din/config.yaml'160 self.run_yaml(generate=False)161 built_in.equals(self.pro.returncode, 0, self.err_msg)162 built_in.not_contains(self.err, 'Traceback', self.err_msg)163 def test_din_gpu(self):164 """test rank.din with gpu."""165 self.yaml_config_name = "models/rank/din/config.yaml"166 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)167 utils.cmd_shell(sed_gpu_cmd)168 self.run_yaml(generate=False, cuda_devices="0")169 built_in.equals(self.pro.returncode, 0, self.err_msg)170 built_in.not_contains(self.err, 'Traceback', self.err_msg)171 def test_dnn(self):172 """test ran.dnn."""173 self.yaml_config_name = 'models/rank/dnn/config.yaml'174 self.run_yaml(generate=False)175 built_in.equals(self.pro.returncode, 0, self.err_msg)176 built_in.not_contains(self.err, 'Traceback', self.err_msg)177 def test_dnn_gpu(self):178 """test rank.dnn with gpu."""179 self.yaml_config_name = "models/rank/dnn/config.yaml"180 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)181 utils.cmd_shell(sed_gpu_cmd)182 self.run_yaml(generate=False, cuda_devices="0")183 built_in.equals(self.pro.returncode, 0, self.err_msg)184 built_in.not_contains(self.err, 'Traceback', self.err_msg)185 def test_ffm(self):186 """test ran.ffm."""187 self.yaml_config_name = 'models/rank/ffm/config.yaml'188 self.run_yaml(generate=False)189 built_in.equals(self.pro.returncode, 0, self.err_msg)190 built_in.not_contains(self.err, 'Traceback', self.err_msg)191 def test_ffm_gpu(self):192 """test rank.ffm with gpu."""193 self.yaml_config_name = "models/rank/ffm/config.yaml"194 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)195 utils.cmd_shell(sed_gpu_cmd)196 self.run_yaml(generate=False, cuda_devices="0")197 built_in.equals(self.pro.returncode, 0, self.err_msg)198 built_in.not_contains(self.err, 'Traceback', self.err_msg)199 # è¿ä¸ªcase ç°å¨ä¼hang200 # def test_fgcnn(self):201 # """test ran.fgcnn."""202 # self.yaml_config_name = 'models/rank/fgcnn'203 # self.run_yaml(generate=False)204 # built_in.equals(self.pro.returncode, 0, self.err_msg)205 # built_in.not_contains(self.err, 'Traceback', self.err_msg)206 #207 # def test_fgcnn_gpu(self):208 # """test rank.fgcnn with gpu."""209 # self.yaml_config_name = "models/rank/fgcnn/config.yaml"210 # sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)211 # utils.sed_file(sed_gpu_cmd)212 # self.run_yaml(generate=False, cuda_devices="0")213 # built_in.equals(self.pro.returncode, 0, self.err_msg)214 # built_in.not_contains(self.err, 'Traceback', self.err_msg)215 def test_fm(self):216 """test ran.fm."""217 self.yaml_config_name = 'models/rank/fm/config.yaml'218 self.run_yaml(generate=False)219 built_in.equals(self.pro.returncode, 0, self.err_msg)220 built_in.not_contains(self.err, 'Traceback', self.err_msg)221 def test_fm_gpu(self):222 """test rank.fm with gpu."""223 self.yaml_config_name = "models/rank/fm/config.yaml"224 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)225 utils.cmd_shell(sed_gpu_cmd)226 self.run_yaml(generate=False, cuda_devices="0")227 built_in.equals(self.pro.returncode, 0, self.err_msg)228 built_in.not_contains(self.err, 'Traceback', self.err_msg)229 def test_fnn(self):230 """test ran.fnn."""231 self.yaml_config_name = 'models/rank/fnn/config.yaml'232 self.run_yaml(generate=False)233 built_in.equals(self.pro.returncode, 0, self.err_msg)234 built_in.not_contains(self.err, 'Traceback', self.err_msg)235 def test_fnn_gpu(self):236 """test rank.fnn with gpu."""237 self.yaml_config_name = "models/rank/fnn/config.yaml"238 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)239 utils.cmd_shell(sed_gpu_cmd)240 self.run_yaml(generate=False, cuda_devices="0")241 built_in.equals(self.pro.returncode, 0, self.err_msg)242 built_in.not_contains(self.err, 'Traceback', self.err_msg)243 def test_logistic_regression(self):244 """test ran.logistic_regression."""245 self.yaml_config_name = 'models/rank/logistic_regression/config.yaml'246 self.run_yaml(generate=False)247 built_in.equals(self.pro.returncode, 0, self.err_msg)248 built_in.not_contains(self.err, 'Traceback', self.err_msg)249 def test_logistic_regression_gpu(self):250 """test rank.logistic_regression with gpu."""251 self.yaml_config_name = "models/rank/logistic_regression/config.yaml"252 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)253 utils.cmd_shell(sed_gpu_cmd)254 self.run_yaml(generate=False, cuda_devices="0")255 built_in.equals(self.pro.returncode, 0, self.err_msg)256 built_in.not_contains(self.err, 'Traceback', self.err_msg)257 def test_nfm(self):258 """test ran.nfm."""259 self.yaml_config_name = 'models/rank/nfm/config.yaml'260 self.run_yaml(generate=False)261 built_in.equals(self.pro.returncode, 0, self.err_msg)262 built_in.not_contains(self.err, 'Traceback', self.err_msg)263 def test_nfm_gpu(self):264 """test rank.nfm with gpu."""265 self.yaml_config_name = "models/rank/nfm/config.yaml"266 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)267 utils.cmd_shell(sed_gpu_cmd)268 self.run_yaml(generate=False, cuda_devices="0")269 built_in.equals(self.pro.returncode, 0, self.err_msg)270 built_in.not_contains(self.err, 'Traceback', self.err_msg)271 # éè¦paddle>=2.0272 # def test_pnn(self):273 # """test ran.pnn."""274 # self.yaml_config_name = 'PaddleRec.models.rank.pnn'275 # self.run_yaml(generate=False)276 # built_in.equals(self.pro.returncode, 0, self.err_msg)277 # built_in.not_contains(self.err, 'Traceback', self.err_msg)278 #279 # def test_pnn_gpu(self):280 # """test rank.pnn with gpu."""281 # self.yaml_config_name = "models/rank/pnn/config.yaml"282 # sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)283 # utils.cmd_shell(sed_gpu_cmd)284 # self.run_yaml(generate=False, cuda_devices="0")285 # built_in.equals(self.pro.returncode, 0, self.err_msg)286 # built_in.not_contains(self.err, 'Traceback', self.err_msg)287 def test_wide_deep(self):288 """test ran.wide_deep."""289 self.yaml_config_name = 'models/rank/wide_deep/config.yaml'290 self.run_yaml(generate=False)291 built_in.equals(self.pro.returncode, 0, self.err_msg)292 built_in.not_contains(self.err, 'Traceback', self.err_msg)293 def test_wide_deep_gpu(self):294 """test rank.wide_deep with gpu."""295 self.yaml_config_name = "models/rank/wide_deep/config.yaml"296 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)297 utils.cmd_shell(sed_gpu_cmd)298 self.run_yaml(generate=False, cuda_devices="0")299 built_in.equals(self.pro.returncode, 0, self.err_msg)300 built_in.not_contains(self.err, 'Traceback', self.err_msg)301 def test_xdeepfm(self):302 """test ran.xdeepfm."""303 self.yaml_config_name = 'models/rank/xdeepfm/config.yaml'304 self.run_yaml(generate=False)305 built_in.equals(self.pro.returncode, 0, self.err_msg)306 built_in.not_contains(self.err, 'Traceback', self.err_msg)307 def test_xdeepfm_gpu(self):308 """test rank.xdeepfm with gpu."""309 self.yaml_config_name = "models/rank/xdeepfm/config.yaml"310 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)311 utils.cmd_shell(sed_gpu_cmd)312 self.run_yaml(generate=False, cuda_devices="0")313 built_in.equals(self.pro.returncode, 0, self.err_msg)314 built_in.not_contains(self.err, 'Traceback', self.err_msg)315 # def test_fibinet(self):316 # """test rank.fibinet"""317 # self.yaml_config_name = "models/rank/fibinet/config.yaml"318 # verify_epochs = "sed -i 's/epochs:.*4/epochs: 1/g' {}".format(self.yaml_config_name)319 # utils.cmd_shell(verify_epochs)320 # self.run_yaml(generate=False)321 # built_in.equals(self.pro.returncode, 0, self.err_msg)322 # built_in.not_contains(self.err, 'Traceback', self.err_msg)323 # def test_fibinet_gpu(self):324 # """test rank.fibinet"""325 # self.yaml_config_name = "models/rank/fibinet/config.yaml"326 # verify_epochs = "sed -i 's/epochs:.*4/epochs: 1/g' {}".format(self.yaml_config_name)327 # sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)328 # utils.cmd_shell(sed_gpu_cmd)329 # utils.cmd_shell(verify_epochs)330 # self.run_yaml(generate=False, cuda_devices="0")331 # built_in.equals(self.pro.returncode, 0, self.err_msg)332 # built_in.not_contains(self.err, 'Traceback', self.err_msg)333 def test_AutoInt(self):334 """test rank.fibinet"""335 self.yaml_config_name = "models/rank/AutoInt/config.yaml"336 verify_epochs = "sed -i 's/epochs:.*2/epochs: 1/g' {}".format(self.yaml_config_name)337 utils.cmd_shell(verify_epochs)338 self.run_yaml(generate=False)339 built_in.equals(self.pro.returncode, 0, self.err_msg)340 built_in.not_contains(self.err, 'Traceback', self.err_msg)341 def test_AutoInt_gpu(self):342 """test rank.fibinet"""343 self.yaml_config_name = "models/rank/AutoInt/config.yaml"344 verify_epochs = "sed -i 's/epochs:.*2/epochs: 1/g' {}".format(self.yaml_config_name)345 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)346 utils.cmd_shell(sed_gpu_cmd)347 utils.cmd_shell(verify_epochs)348 self.run_yaml(generate=False, cuda_devices="0")349 built_in.equals(self.pro.returncode, 0, self.err_msg)350 built_in.not_contains(self.err, 'Traceback', self.err_msg)351 def test_fasttext(self):352 """test recall.fasttext."""353 self.yaml_config_name = 'models/recall/fasttext/config.yaml'354 self.run_yaml(generate=False)355 built_in.equals(self.pro.returncode, 0, self.err_msg)356 built_in.not_contains(self.err, 'Traceback', self.err_msg)357 def test_fasttext_gpu(self):358 """test recall.fasttext with gpu."""359 self.yaml_config_name = "models/recall/fasttext/config.yaml"360 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)361 utils.cmd_shell(sed_gpu_cmd)362 self.run_yaml(generate=False, cuda_devices="0")363 built_in.equals(self.pro.returncode, 0, self.err_msg)364 built_in.not_contains(self.err, 'Traceback', self.err_msg)365 def test_gnn(self):366 """test recall.gnn."""367 self.yaml_config_name = 'models/recall/gnn/config.yaml'368 self.run_yaml(generate=False)369 built_in.equals(self.pro.returncode, 0, self.err_msg)370 built_in.not_contains(self.err, 'Traceback', self.err_msg)371 def test_gnn_gpu(self):372 """test recall.gnn with gpu."""373 self.yaml_config_name = "models/recall/gnn/config.yaml"374 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)375 utils.cmd_shell(sed_gpu_cmd)376 self.run_yaml(generate=False, cuda_devices="0")377 built_in.equals(self.pro.returncode, 0, self.err_msg)378 built_in.not_contains(self.err, 'Traceback', self.err_msg)379# def test_gru4rec(self):380# """test recall.gru4rec."""381# self.yaml_config_name = 'models/recall/gru4rec/config.yaml'382# self.run_yaml(generate=False)383# built_in.equals(self.pro.returncode, 0, self.err_msg)384# built_in.not_contains(self.err, 'Traceback', self.err_msg)385# def test_gru4rec_gpu(self):386# """test recall.gru4rec with gpu."""387# self.yaml_config_name = "models/recall/gru4rec/config.yaml"388# sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)389# utils.cmd_shell(sed_gpu_cmd)390# self.run_yaml(generate=False, cuda_devices="0")391# built_in.equals(self.pro.returncode, 0, self.err_msg)392# built_in.not_contains(self.err, 'Traceback', self.err_msg)393 def test_ncf(self):394 """test recall.ncf."""395 self.yaml_config_name = 'models/recall/ncf/config.yaml'396 self.run_yaml(generate=False)397 built_in.equals(self.pro.returncode, 0, self.err_msg)398 built_in.not_contains(self.err, 'Traceback', self.err_msg)399# def test_ncf_gpu(self):400# """test recall.ncf with gpu."""401# self.yaml_config_name = "models/recall/ncf/config.yaml"402# sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)403# utils.cmd_shell(sed_gpu_cmd)404# self.run_yaml(generate=False, cuda_devices="0")405# built_in.equals(self.pro.returncode, 0, self.err_msg)406# built_in.not_contains(self.err, 'Traceback', self.err_msg)407 def test_ssr(self):408 """test recall.ssr."""409 self.yaml_config_name = 'models/recall/ssr/config.yaml'410 self.run_yaml(generate=False)411 built_in.equals(self.pro.returncode, 0, self.err_msg)412 built_in.not_contains(self.err, 'Traceback', self.err_msg)413 def test_ssr_gpu(self):414 """test recall.ssr with gpu."""415 self.yaml_config_name = "models/recall/ssr/config.yaml"416 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)417 utils.cmd_shell(sed_gpu_cmd)418 self.run_yaml(generate=False, cuda_devices="0")419 built_in.equals(self.pro.returncode, 0, self.err_msg)420 built_in.not_contains(self.err, 'Traceback', self.err_msg)421 def test_word2vec(self):422 """test recall.word2vec."""423 self.yaml_config_name = 'models/recall/word2vec/config.yaml'424 self.run_yaml(generate=False)425 built_in.equals(self.pro.returncode, 0, self.err_msg)426 built_in.not_contains(self.err, 'Traceback', self.err_msg)427 def test_word2vec_gpu(self):428 """test recall.word2vec with gpu."""429 self.yaml_config_name = "models/recall/word2vec/config.yaml"430 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)431 utils.cmd_shell(sed_gpu_cmd)432 self.run_yaml(generate=False, cuda_devices="0")433 built_in.equals(self.pro.returncode, 0, self.err_msg)434 built_in.not_contains(self.err, 'Traceback', self.err_msg)435 def test_youtube_dnn(self):436 """test recall.youtube_dnn."""437 self.yaml_config_name = 'models/recall/youtube_dnn/config.yaml'438 self.run_yaml(generate=False)439 built_in.equals(self.pro.returncode, 0, self.err_msg)440 built_in.not_contains(self.err, 'Traceback', self.err_msg)441 def test_youtube_dnn_gpu(self):442 """test recall.youtube_dnn with gpu."""443 self.yaml_config_name = "models/recall/youtube_dnn/config.yaml"444 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)445 utils.cmd_shell(sed_gpu_cmd)446 self.run_yaml(generate=False, cuda_devices="0")447 built_in.equals(self.pro.returncode, 0, self.err_msg)448 built_in.not_contains(self.err, 'Traceback', self.err_msg)449 def test_listwise(self):450 """test rerank.listwise."""451 self.yaml_config_name = 'models/rerank/listwise/config.yaml'452 self.run_yaml(generate=False)453 built_in.equals(self.pro.returncode, 0, self.err_msg)454 built_in.not_contains(self.err, 'Traceback', self.err_msg)455 def test_listwise_gpu(self):456 """test rerank.listwise with gpu."""457 self.yaml_config_name = "models/rerank/listwise/config.yaml"458 sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)459 utils.cmd_shell(sed_gpu_cmd)460 self.run_yaml(generate=False, cuda_devices="0")461 built_in.equals(self.pro.returncode, 0, self.err_msg)462 built_in.not_contains(self.err, 'Traceback', self.err_msg)463 def test_tdm(self):464 """test treebased.tdm."""465 self.yaml_config_name = 'models/treebased/tdm/config.yaml'466 self.run_yaml(generate=False)467 built_in.equals(self.pro.returncode, 0, self.err_msg)468 built_in.not_contains(self.err, 'Traceback', self.err_msg)469 # ä¸æ¯ægpuï¼éè¦paddleçæ¬>=1.8.0470 # def test_tdm_gpu(self):471 # """test treebased.tdm with gpu."""472 # self.yaml_config_name = "models/treebased/tdm/config.yaml"473 # sed_gpu_cmd = "sed -i 's/device:.*cpu/device: gpu/g' {}".format(self.yaml_config_name)474 # utils.cmd_shell(sed_gpu_cmd)475 # self.run_yaml(generate=False, cuda_devices="0")476 # built_in.equals(self.pro.returncode, 0, self.err_msg)...
common_heuristics.py
Source:common_heuristics.py
1import random2import time3from selenium.common.exceptions import WebDriverException4from selenium.webdriver.common.action_chains import ActionChains5import tracing.nlp as nlp6from tracing.selenium_utils.common import *7from tracing.selenium_utils.controls import *8from tracing.utils.logger import *9def get_label_text_with_attribute(driver, elem):10 label_text = ""11 element_attribute = get_element_attribute(elem)12 try:13 if element_attribute:14 if element_attribute[0] == "id":15 label = driver.find_elements_by_css_selector("label[for='%s']" % element_attribute[1])16 if label:17 label_text = nlp.remove_letters(label[0].get_attribute("innerHTML").strip(), ["/", "*", "-", "_", ":", " "]).lower()18 return label_text19 label_text = nlp.remove_letters(20 elem.get_attribute("outerHTML").strip(),21 ["*", "-", "_", ":", " "]22 ).lower()23 except:24 label_text = ""25 return label_text26def find_radio_or_checkbox_buttons(driver,27 contains=None,28 not_contains=None):29 radiobtns = driver.find_elements_by_css_selector("input[type='radio']")30 checkbtns = driver.find_elements_by_css_selector("input[type='checkbox']")31 result = []32 for elem in radiobtns + checkbtns:33 text = elem.get_attribute("outerHTML")34 if nlp.check_text(text, contains, not_contains):35 result.append(elem)36 else:37 l_text = get_label_text_with_attribute(driver, elem)38 if l_text and nlp.check_text(l_text, contains, not_contains):39 result.append(elem)40 41 return result42def get_no_href_buttons(driver, contains, not_contains=None, get_type = 1):43 '''44 Find no href link or button based on contains and not_contains parameters.45 '''46 result = []47 if get_type == 1:48 elements = find_buttons_or_links(driver, contains, not_contains)49 else:50 elements = find_buttons(driver, contains, not_contains)51 for btn in elements:52 if btn.get_attribute('href') == normalize_url(get_url(driver)):53 continue54 result.append(btn)55 return result56def find_elements_with_attribute(driver,57 attr_tagname,58 attr_type,59 attr_content):60 return driver.find_elements_by_css_selector("{}[{}='{}']".format(attr_tagname, attr_type, attr_content))61def check_filling_fields_required(driver):62 '''63 Check if filling any fields is required in checkout page64 '''65 inputs = driver.find_elements_by_css_selector("input[type='text']")66 inputs += driver.find_elements_by_css_selector("input[type='tel']")67 inputs += driver.find_elements_by_css_selector("textarea")68 user_result = False69 payment_result = False70 for element in inputs:71 if can_click(element):72 label_text = get_label_text_with_attribute(driver, element)73 if not user_result and nlp.check_text(label_text, ["street", "address"], ["shipping address", "email"]):74 user_result = True75 elif not payment_result and nlp.check_text(label_text, ["cardholder", "card number", "expire"]):76 payment_result = True77 elif user_result and payment_result:78 return 379 if user_result:80 return 181 elif payment_result:82 return 283 return 084def find_links(driver, contains=None, not_contains=None):85 result = []86 for link in get_links(driver):87 if not can_click(link):88 continue89 90 if get_url(driver) == link.get_attribute("href"):91 continue92 text = link.get_attribute("outerHTML")93 if nlp.check_text(text, contains, not_contains):94 result.append(link)95 return result96def find_error_elements(driver, contains=None, not_contains=None):97 divs = driver.find_elements_by_css_selector("div")98 spans = driver.find_elements_by_css_selector("span")99 label = driver.find_elements_by_css_selector("label")100 p = driver.find_elements_by_css_selector("p")101 ul = driver.find_elements_by_css_selector("ul")102 # Yield isn't good because context can change103 result = []104 try:105 for div in divs + spans + label + p + ul:106 if div.is_displayed():107 div_class = div.get_attribute("class")108 if nlp.check_text(div_class, contains, not_contains) and \109 (div.get_attribute("innerHTML").strip() and not "error hide" in div.get_attribute("innerHTML").strip().lower()):110 result.append(div)111 except:112 result = []113 pass114 return result115def find_sub_elements(driver, element, contains=None, not_contains=None):116 links = [elem for elem in element.find_elements_by_tag_name("a") if not is_link(driver, elem)]117 buttons = element.find_elements_by_tag_name("button")118 inputs = element.find_elements_by_css_selector('input[type="button"]')119 submits = element.find_elements_by_css_selector('input[type="submit"]')120 imgs = element.find_elements_by_css_selector('input[type="image"]')121 # Yield isn't good because context can change122 result = []123 for elem in links + buttons + inputs + submits + links + imgs:124 if not can_click(elem):125 continue126 text = elem.get_attribute("outerHTML")127 if nlp.check_text(text, contains, not_contains):128 result.append(elem)129 return result130def find_buttons(driver, contains=None, not_contains=None):131 132 # Yield isn't good because context can change133 result = []134 for elem in get_buttons(driver):135 if not can_click(elem):136 continue137 text = elem.get_attribute("innerHTML").strip() + \138 elem.text + " " + \139 (elem.get_attribute("value") if elem.get_attribute("value") else "")140 if nlp.check_text(text, contains, not_contains):141 result.append(elem)142 return result143def find_buttons_or_links(driver, contains=None, not_contains=None):144 return find_links(driver, contains, not_contains) + \145 find_buttons(driver, contains, not_contains)146def try_handle_popups(driver):147 contains = ["i (.* |)over", "i (.* |)age", "i (.* |)year", "agree", "accept", "enter "]148 not_contains = ["not ", "under ", "leave", "login", "log in", "cancel"]149 150 btns = find_buttons_or_links(driver, contains, not_contains)151 if len(btns):152 checkbtns = find_radio_or_checkbox_buttons(driver, contains, not_contains)153 click_first(driver, checkbtns, None)154 155 156 result = click_first(driver, btns, None)157 if result:158 time.sleep(2)159 160 return result161def click_first(driver, elements, on_error=try_handle_popups, randomize = False):162 def process(element):163 try:164 # process links by opening url165 href = element.get_attribute("href")166 if is_link(element):167 driver.get(href)168 return True169 ActionChains(driver).move_to_element(element).perform()170 old_windows = len(driver.window_handles)171 element.click()172 new_windows = len(driver.window_handles)173 if new_windows > old_windows:174 driver.switch_to_window(driver.window_handles[-1])175 return True176 177 except WebDriverException:178 logger = get_logger()179 logger.debug('Unexpected exception during clicking element {}'.format(traceback.format_exc()))180 return False181 logger = get_logger()182 183 if randomize:184 random.shuffle(elements)185 186 for element in elements:187 logger.debug('clicking element: {}'.format(to_string(element)))188 clicked = process(element)189 logger.debug('result: {}'.format(clicked))190 191 if clicked:192 return True193 if on_error:194 logger.debug('processing erorr')195 error_processed = on_error(driver)196 logger.debug('error process result: {}'.format(error_processed))197 198 logger.debug('clicking again')199 clicked = process(element)200 logger.debug('result: {}'.format(clicked))201 if clicked:202 return True203 return False204def find_text_element(driver, contains=None, not_contains=None):205 label = driver.find_elements_by_tag_name('label')206 h_elements = driver.find_elements_by_tag_name('h')207 span = driver.find_elements_by_tag_name('span')208 p = driver.find_elements_by_tag_name('p')209 td = driver.find_elements_by_tag_name('td')210 li = driver.find_elements_by_css_selector('li')211 for ind in range(1,6):212 h_elements += driver.find_elements_by_tag_name('h%s' % str(ind))213 result = None214 for elem in label + h_elements + span + p + td + li:215 text = elem.get_attribute("outerHTML")216 if nlp.check_text(text, contains, not_contains):217 result = elem218 return result219def is_empty_cart(driver):220 text = get_page_text(driver)221 return nlp.check_if_empty_cart(text)222def is_domain_for_sale(driver, domain):223 text = get_page_text(driver)224 return nlp.check_if_domain_for_sale(text, domain)225def search_for_add_to_cart(driver):226 contains = ["addtocart", "addtobag", "add to cart", "add to bag"]227 not_contains = ["where", "about us"]...
list_files.py
Source:list_files.py
1__author__ = 'jwely'2import os3from exists import exists4from enf_list import enf_list5def list_files(recursive, directory, contains = None, not_contains = None):6 """7 Simple file listing function with more versatility than python builtins or arcpy.List8 This function sifts through a directory and returns a list of filepaths for all files9 meeting the input criteria. Useful for discriminatory iteration or recursive searches.10 Could be used to find all tiles with a given datestring such as 'MOD11A1.A2012', or11 perhaps all Band 4 tiles from a directory containing landsat 8 data.12 :param recursive: 'True' if search should search subfolders within the directory13 'False' if search should ignore files in subfolders.14 :param directory: The directory in which to search for files meeting the criteria15 :param contains: search criteria to limit returned file list. File names must16 contain parameters listed here. If no criteria exists use 'False'17 :param not_contains: search criteria to limit returned file list. File names must not18 contain parameters listed here. If no criteria exists use 'False'19 :return filelist: An array of full filepaths meeting the criteria.20 """21 # import modules and set up empty lists22 filelist = []23 templist = []24 # ensure input directory actually exists25 if not exists(directory):26 raise Exception("{0} is not a valid file or folder!".format(directory))27 # Ensure single strings are in list format for the loops below28 if contains:29 contains = enf_list(contains)30 if not_contains:31 not_contains = enf_list(not_contains)32 not_contains.append('sr.lock') # make sure lock files don't get counted33 else:34 not_contains = ['sr.lock'] # make sure lock files don't get counted35 # use os.walk commands to search through whole directory if recursive36 if recursive:37 for root, dirs, files in os.walk(directory):38 for basename in files:39 filename = os.path.join(root, basename)40 # if both conditions exist, add items which meet contains criteria41 if contains and not_contains:42 for i in contains:43 if i in basename:44 templist.append(filename)45 # if the entire array of 'contains' terms were found, add to list46 if len(templist) == len(contains):47 filelist.append(filename)48 templist = []49 # remove items which do not meet the DoesNotcontain criteria50 for j in not_contains:51 if j in basename:52 try: filelist.remove(filename)53 except: pass54 # If both conditions do not exist (one is false)55 else:56 # determine if a file is good. if it is, add it to the list.57 if contains:58 for i in contains:59 if i in basename:60 templist.append(filename)61 # if the entire array of 'contains' terms were found, add to list62 if len(templist) == len(contains):63 filelist.append(filename)64 templist = []65 # add all files to the list, then remove the bad ones.66 elif not_contains:67 filelist.append(filename)68 for j in not_contains:69 if j in basename:70 try: filelist.remove(filename)71 except: pass72 else:73 filelist.append(filename)74 # if neither conditionexists75 if not contains and not not_contains:76 filelist.append(filename)77 # use a simple listdir if recursive is False78 else:79 # list only files in current directory, not subdir and check criteria80 try:81 for basename in os.listdir(directory):82 filename = os.path.join(directory, basename)83 if os.path.isfile(filename):84 if contains:85 for i in contains:86 if i in basename:87 templist.append(filename)88 # if the entire array of 'contains' terms were found, add to list89 if len(templist) == len(contains):90 filelist.append(filename)91 templist = []92 else:93 filelist.append(filename)94 # Remove any files from the filelist that fail not_contains criteria95 if not_contains:96 for j in not_contains:97 if j in basename:98 try: filelist.remove(filename)99 except: pass100 except: pass101 print('Files found which meet all input criteria: {0}'.format(len(filelist)))102 return filelist103if __name__ == "__main__":...
test_xss_protection.py
Source:test_xss_protection.py
...19 actual = render('Example <script>alert(1);</script>')20 expected = '<p>Example alert(1);</p>\n'21 ok(actual).diff(expected)22 html = render('<sc<script>ript>xss</sc</script>ript>')23 ok(html).not_contains('<sc')24 ok(html).not_contains('ript>')25 actual = render('<span><a href="javascript:xss">foo</a></span>')26 expected = '<p>foo</p>\n'27 ok(actual).diff(expected)28 def test_html_escape(self):29 supplied = 'Example <script>alert(1);</script>'30 expected = '<p>%s</p>\n' % escape_html(supplied)31 ok(render_escape(supplied)).diff(expected)32 html = render_escape('<sc<script>ript>xss</sc</script>ript>')33 ok(html).not_contains('<sc')34 ok(html).not_contains('ript>')35 supplied = '<span><a href="javascript:xss">foo</a></span>'36 expected = '<p>%s</p>\n' % escape_html(supplied)37 ok(render_escape(supplied)).diff(expected)38 def test_autolink_filtering_with_nice_data(self):39 for url in ('http://a', "https://b?x&y"):40 actual = render('<%s>' % url)41 expected = '<p><a href="{0}">{0}</a></p>\n'.format(escape_html(url))42 ok(actual).diff(expected)43 supplied = "<alice@example.net>"44 expected = '<p>%s</p>\n' % escape_html(supplied)45 ok(render_escape(supplied)).diff(expected)46 def test_autolink_filtering_with_naughty_data(self):47 actual = render('<javascript:foo>')48 expected = '<p><javascript:foo></p>\n'49 ok(actual).diff(expected)50 url = 'javascript:0'51 encoded_url = ''.join('&x{0:x};'.format(ord(c)) for c in url)52 html = render('<%s>' % encoded_url)53 ok(html).not_contains(url)54 def test_link_filtering_with_nice_data(self):55 for url in ('http://a', 'https://b'):56 actual = render("['foo](%s \"bar'\")" % url)57 expected = '<p><a href="{0}" title="bar'">'foo</a></p>\n'.format(url)58 ok(actual).diff(expected)59 def test_link_filtering_with_naughty_data(self):60 supplied = '[foo](javascript:xss)'61 expected = '<p>%s</p>\n' % escape_html(supplied)62 ok(render(supplied)).diff(expected)63 html = render('[foo](unknown:bar)')64 expected = '<p>%s</p>\n' % escape_html(supplied)65 ok(render(supplied)).diff(expected)66 html = render('[" xss><xss>]("><xss>)')67 ok(html).not_contains('<xss>')68 ok(html).not_contains('" xss')69 html = render('[" xss><xss>](https:"><xss>)')70 ok(html).not_contains('<xss>')71 ok(html).not_contains('" xss')72 def test_image_src_filtering_with_nice_data(self):73 actual = render('![](http:"foo")')74 expected = '<p><img src="http:"foo"" /></p>\n'75 ok(actual).diff(expected)76 actual = render('!["bar"](https://example.org/ "\'title\'")')77 expected = '<p><img src="https://example.org/" alt=""bar"" title="'title'" /></p>\n'78 ok(actual).diff(expected)79 def test_image_src_filtering_with_naughty_data(self):80 actual = render('![foo](javascript:foo)')81 expected = '<p>![foo](javascript:foo)</p>\n'82 ok(actual).diff(expected)83 def test_autolink_rewriting(self):84 for url in ('http://a', 'https://b?x&y'):85 actual = render_rewrite('<%s>' % url)...
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!!