Best Python code snippet using playwright-python
test_manager.py
Source:test_manager.py
...123 in_file.touch()124 (src_dir / "chapter.adoc").touch()125 (src_dir / "other").mkdir()126 (src_dir / "other" / "another.adoc").touch()127 package_manager.set_input_files(in_file, src_dir)128 doc = package_manager.prepare_work_directory(in_file)129 assert doc.work_file.is_file()130 assert doc.work_file.name == "index.adoc"131 assert doc.package is not None132 assert doc.package.is_input_package is True133 assert (doc.work_dir / "index.adoc").is_file()134 assert (doc.work_dir / "chapter.adoc").is_file()135 assert (doc.work_dir / "other").is_dir()136 assert (doc.work_dir / "other" / "another.adoc").is_file()137 assert (doc.work_dir / "a.adoc").is_file()138 assert (doc.work_dir / "b.adoc").is_file()139 assert (doc.work_dir / "images").is_dir()140 assert (doc.work_dir / "images" / "a.png").is_file()141 assert (doc.work_dir / "images" / "b.png").is_file()142def test_prepare_work_directory__no_include_dir(package_manager, tmp_path, build_dir):143 create_package_dir(tmp_path, "a")144 create_package_dir(tmp_path, "b")145 spec_file = create_package_spec(tmp_path, "a", "b")146 package_manager.collect(spec_file)147 src_dir = tmp_path / "src"148 src_dir.mkdir()149 in_file = src_dir / "index.adoc"150 in_file.touch()151 (src_dir / "chapter.adoc").touch()152 (src_dir / "other").mkdir()153 (src_dir / "other" / "another.adoc").touch()154 package_manager.set_input_files(in_file)155 doc = package_manager.prepare_work_directory(in_file)156 assert doc.work_file.is_file()157 assert doc.work_file.name == "index.adoc"158 assert doc.package is not None159 assert doc.package.is_input_package is True160 assert (doc.work_dir / "index.adoc").is_file()161 assert not (doc.work_dir / "chapter.adoc").is_file()162 assert not (doc.work_dir / "other").is_dir()163 assert not (doc.work_dir / "other" / "another.adoc").is_file()164 assert (doc.work_dir / "a.adoc").is_file()165 assert (doc.work_dir / "b.adoc").is_file()166 assert (doc.work_dir / "images").is_dir()167 assert (doc.work_dir / "images" / "a.png").is_file()168 assert (doc.work_dir / "images" / "b.png").is_file()169def test_prepare_work_directory__explicit_images(package_manager, tmp_path, build_dir):170 create_package_dir(tmp_path, "a")171 create_package_dir(tmp_path, "b")172 spec_file = create_package_spec(tmp_path, "a", "b")173 package_manager.collect(spec_file)174 src_dir = tmp_path / "src"175 src_dir.mkdir()176 in_file = src_dir / "index.adoc"177 in_file.touch()178 (src_dir / "chapter.adoc").touch()179 (src_dir / "other").mkdir()180 (src_dir / "other" / "another.adoc").touch()181 image_dir = tmp_path / "images"182 image_dir.mkdir()183 (image_dir / "image.png").touch()184 package_manager.set_input_files(in_file, None, image_dir)185 doc = package_manager.prepare_work_directory(in_file)186 assert doc.work_file.is_file()187 assert doc.work_file.name == "index.adoc"188 assert doc.package is not None189 assert doc.package.is_input_package is True190 assert (doc.work_dir / "index.adoc").is_file()191 assert not (doc.work_dir / "chapter.adoc").is_file()192 assert not (doc.work_dir / "other").is_dir()193 assert not (doc.work_dir / "other" / "another.adoc").is_file()194 assert (doc.work_dir / "images").is_dir()195 assert (doc.work_dir / "images" / "image.png").is_file()196 assert (doc.work_dir / "a.adoc").is_file()197 assert (doc.work_dir / "b.adoc").is_file()198 assert (doc.work_dir / "images" / "a.png").is_file()199 assert (doc.work_dir / "images" / "b.png").is_file()200def test_prepare_work_directory__implicit_images(package_manager, tmp_path, build_dir):201 create_package_dir(tmp_path, "a")202 create_package_dir(tmp_path, "b")203 spec_file = create_package_spec(tmp_path, "a", "b")204 package_manager.collect(spec_file)205 src_dir = tmp_path / "src"206 src_dir.mkdir()207 in_file = src_dir / "index.adoc"208 in_file.touch()209 (src_dir / "chapter.adoc").touch()210 (src_dir / "other").mkdir()211 (src_dir / "other" / "another.adoc").touch()212 image_dir = src_dir / "images"213 image_dir.mkdir()214 (image_dir / "image.png").touch()215 package_manager.set_input_files(in_file, None, None)216 doc = package_manager.prepare_work_directory(in_file)217 assert doc.work_file.is_file()218 assert doc.work_file.name == "index.adoc"219 assert doc.package is not None220 assert doc.package.is_input_package is True221 assert (doc.work_dir / "index.adoc").is_file()222 assert not (doc.work_dir / "chapter.adoc").is_file()223 assert not (doc.work_dir / "other").is_dir()224 assert not (doc.work_dir / "other" / "another.adoc").is_file()225 assert (doc.work_dir / "images").is_dir()226 assert (doc.work_dir / "images" / "image.png").is_file()227 assert (doc.work_dir / "a.adoc").is_file()228 assert (doc.work_dir / "b.adoc").is_file()229 assert (doc.work_dir / "images" / "a.png").is_file()230 assert (doc.work_dir / "images" / "b.png").is_file()231def test_prepare_work_directory__file_collision(package_manager, tmp_path, build_dir,232 warnings_are_and_are_not_errors):233 create_package_dir(tmp_path, "a")234 create_package_dir(tmp_path, "b")235 spec_file = create_package_spec(tmp_path, "a", "b")236 package_manager.collect(spec_file)237 src_dir = tmp_path / "src"238 src_dir.mkdir()239 in_file = src_dir / "index.adoc"240 in_file.touch()241 (src_dir / "a.adoc").touch()242 package_manager.set_input_files(in_file, src_dir)243 if warnings_are_and_are_not_errors:244 with pytest.raises(FileCollisionError) as excinfo:245 package_manager.prepare_work_directory(in_file)246 assert "File a.adoc from package INPUT already exists in package a." in str(excinfo.value)247 else:248 package_manager.prepare_work_directory(in_file)249def test_prepare_work_directory__dir_and_file_collision__file_overwrites_dir_from_input(250 package_manager, tmp_path, build_dir, warnings_are_and_are_not_errors):251 create_package_dir(tmp_path, "a")252 create_package_dir(tmp_path, "b")253 spec_file = create_package_spec(tmp_path, "a", "b")254 package_manager.collect(spec_file)255 src_dir = tmp_path / "src"256 src_dir.mkdir()257 in_file = src_dir / "index.adoc"258 in_file.touch()259 (src_dir / "a.adoc").mkdir()260 package_manager.set_input_files(in_file, src_dir)261 with pytest.raises(FileCollisionError) as excinfo:262 package_manager.prepare_work_directory(in_file)263 assert ("Package a contains file a.adoc, which is also a directory in package INPUT."264 in str(excinfo.value))265def test_prepare_work_directory__dir_and_file_collision__dir_overwrites_file(266 package_manager, tmp_path, build_dir, warnings_are_and_are_not_errors):267 create_package_dir(tmp_path, "a")268 pkg_b_dir = create_package_dir(tmp_path, "b")269 spec_file = create_package_spec(tmp_path, "a", "b")270 package_manager.collect(spec_file)271 src_dir = tmp_path / "src"272 src_dir.mkdir()273 in_file = src_dir / "index.adoc"274 in_file.touch()275 (pkg_b_dir / "adoc" / "a.adoc").mkdir()276 package_manager.set_input_files(in_file, src_dir)277 with pytest.raises(FileCollisionError) as excinfo:278 package_manager.prepare_work_directory(in_file)279 assert ("Package a contains file a.adoc, which is also a directory in package b."280 in str(excinfo.value))281def test_prepare_work_directory__dir_and_file_collision__file_overwrites_dir(282 package_manager, tmp_path, build_dir, warnings_are_and_are_not_errors):283 pkg_a_dir = create_package_dir(tmp_path, "a")284 create_package_dir(tmp_path, "b")285 spec_file = create_package_spec(tmp_path, "a", "b")286 package_manager.collect(spec_file)287 src_dir = tmp_path / "src"288 src_dir.mkdir()289 in_file = src_dir / "index.adoc"290 in_file.touch()291 (pkg_a_dir / "adoc" / "b.adoc").mkdir()292 package_manager.set_input_files(in_file, src_dir)293 with pytest.raises(FileCollisionError) as excinfo:294 package_manager.prepare_work_directory(in_file)295 assert "File b.adoc from package b is also a directory in package a." in str(excinfo.value)296def test_prepare_work_directory__same_dir_in_multiple_packages(package_manager, tmp_path,297 build_dir):298 pkg_a_dir = create_package_dir(tmp_path, "a")299 pkg_b_dir = create_package_dir(tmp_path, "b")300 spec_file = create_package_spec(tmp_path, "a", "b")301 package_manager.collect(spec_file)302 src_dir = tmp_path / "src"303 src_dir.mkdir()304 in_file = src_dir / "index.adoc"305 in_file.touch()306 (src_dir / "other").mkdir()307 (src_dir / "other" / "another.adoc").touch()308 (pkg_a_dir / "adoc" / "other").mkdir()309 (pkg_a_dir / "adoc" / "other" / "a_another.adoc").touch()310 (pkg_b_dir / "adoc" / "other").mkdir()311 (pkg_b_dir / "adoc" / "other" / "b_another.adoc").touch()312 package_manager.set_input_files(in_file, src_dir)313 doc = package_manager.prepare_work_directory(in_file)314 assert doc.work_file.is_file()315 assert doc.work_file.name == "index.adoc"316 assert doc.package is not None317 assert doc.package.is_input_package is True318 assert (doc.work_dir / "other").is_dir()319 assert (doc.work_dir / "other" / "another.adoc").is_file()320 assert (doc.work_dir / "other" / "a_another.adoc").is_file()321 assert (doc.work_dir / "other" / "b_another.adoc").is_file()322@pytest.mark.parametrize("clear", [True, False])323def test_prepare_work_directory__clear_existing(clear, package_manager, tmp_path, build_dir,324 work_dir):325 src_dir = tmp_path / "src"326 src_dir.mkdir()327 in_file = src_dir / "index.adoc"328 in_file.touch()329 (src_dir / "chapter.adoc").touch()330 (src_dir / "other").mkdir()331 (src_dir / "other" / "another.adoc").touch()332 work_dir.mkdir(parents=True, exist_ok=True)333 (work_dir / "existing_file").touch()334 package_manager.set_input_files(in_file, src_dir)335 doc = package_manager.prepare_work_directory(in_file, clear)336 assert doc.work_file.is_file()337 assert doc.work_file.name == "index.adoc"338 assert doc.package is not None339 assert doc.package.is_input_package is True340 assert (doc.work_dir / "index.adoc").is_file()341 assert (doc.work_dir / "chapter.adoc").is_file()342 assert (doc.work_dir / "other").is_dir()343 assert (doc.work_dir / "other" / "another.adoc").is_file()344 assert work_dir == doc.work_dir345 assert (work_dir / "existing_file").exists() is not clear346def test_make_image_directory(package_manager, tmp_path, build_dir):347 create_package_dir(tmp_path, "a")348 create_package_dir(tmp_path, "b")349 spec_file = create_package_spec(tmp_path, "a", "b")350 package_manager.collect(spec_file)351 output_dir = tmp_path / "output"352 package_manager.make_image_directory(output_dir)353 assert (output_dir / "images").is_dir()354 assert (output_dir / "images" / "a.png").is_file()355 assert (output_dir / "images" / "b.png").is_file()356def test_make_image_directory__existing_output_dir(package_manager, tmp_path, build_dir):357 create_package_dir(tmp_path, "a")358 create_package_dir(tmp_path, "b")359 spec_file = create_package_spec(tmp_path, "a", "b")360 package_manager.collect(spec_file)361 output_dir = tmp_path / "output"362 package_manager.make_image_directory(output_dir)363 assert (output_dir / "images").is_dir()364 assert (output_dir / "images" / "a.png").is_file()365 assert (output_dir / "images" / "b.png").is_file()366 package_manager2 = PackageManager(build_dir)367 package_manager2.collect(spec_file)368 package_manager2.make_image_directory(output_dir)369 assert (output_dir / "images").is_dir()370 assert (output_dir / "images" / "a.png").is_file()371 assert (output_dir / "images" / "b.png").is_file()372def test_make_image_directory__from_input_files(package_manager, tmp_path, build_dir):373 create_package_dir(tmp_path, "a")374 create_package_dir(tmp_path, "b")375 spec_file = create_package_spec(tmp_path, "a", "b")376 src_dir = tmp_path / "src"377 src_dir.mkdir()378 in_file = src_dir / "index.adoc"379 in_file.touch()380 image_dir = tmp_path / "images"381 image_dir.mkdir()382 (image_dir / "image.png").touch()383 package_manager.set_input_files(in_file, None, image_dir)384 package_manager.collect(spec_file)385 output_dir = tmp_path / "output"386 package_manager.make_image_directory(output_dir)387 assert (output_dir / "images").is_dir()388 assert (output_dir / "images" / "image.png").is_file()389 assert (output_dir / "images" / "a.png").is_file()390 assert (output_dir / "images" / "b.png").is_file()391def test_make_image_directory__file_collision__file_overwrites_directory(392 package_manager, tmp_path, build_dir):393 create_package_dir(tmp_path, "a")394 create_package_dir(tmp_path, "b")395 spec_file = create_package_spec(tmp_path, "a", "b")396 package_manager.collect(spec_file)397 output_dir = tmp_path / "output"398 (output_dir / "images" / "a.png").mkdir(parents=True)399 with pytest.raises(FileCollisionError) as excinfo:400 package_manager.make_image_directory(output_dir)401 assert ("Unexpected directory a.png, blocking creation of a file from package a."402 in str(excinfo.value))403def test_make_image_directory__file_collision__directory_overwrites_file(404 package_manager, tmp_path, build_dir):405 pkg_a_dir = create_package_dir(tmp_path, "a")406 (pkg_a_dir / "images" / "a_subdir").mkdir(parents=True)407 (pkg_a_dir / "images" / "a_subdir" / "a_subdir_file.png").touch()408 create_package_dir(tmp_path, "b")409 spec_file = create_package_spec(tmp_path, "a", "b")410 package_manager.collect(spec_file)411 output_dir = tmp_path / "output"412 (output_dir / "images").mkdir(parents=True)413 (output_dir / "images" / "a_subdir").touch()414 with pytest.raises(FileCollisionError) as excinfo:415 package_manager.make_image_directory(output_dir)416 assert ("Unexpected file a_subdir, blocking creation of a directory from package a."417 in str(excinfo.value))418@pytest.mark.parametrize("package_hint", [None, "", "a", "b", Package.INPUT_PACKAGE_NAME])419def test_find_original_file__with_include_dir(package_hint, package_manager, tmp_path, build_dir):420 create_package_dir(tmp_path, "a")421 create_package_dir(tmp_path, "b")422 spec_file = create_package_spec(tmp_path, "a", "b")423 package_manager.collect(spec_file)424 src_dir = tmp_path / "src"425 src_dir.mkdir()426 in_file = src_dir / "index.adoc"427 in_file.touch()428 (src_dir / "chapter.adoc").touch()429 (src_dir / "other").mkdir()430 (src_dir / "other" / "another.adoc").touch()431 package_manager.set_input_files(in_file, src_dir)432 package_manager.prepare_work_directory(in_file)433 assert package_manager.find_original_file(package_manager.work_dir / "index.adoc",434 package_hint) == (Package.INPUT_PACKAGE_NAME,435 Path("index.adoc"))436 assert package_manager.find_original_file(package_manager.work_dir / "chapter.adoc",437 package_hint) == (Package.INPUT_PACKAGE_NAME,438 Path("chapter.adoc"))439 assert package_manager.find_original_file(package_manager.work_dir / "other/another.adoc",440 package_hint) == (Package.INPUT_PACKAGE_NAME,441 Path("other/another.adoc"))442 assert package_manager.find_original_file(package_manager.work_dir / "a.adoc",443 package_hint) == ("a", Path("a.adoc"))444 assert package_manager.find_original_file(package_manager.work_dir / "b.adoc",445 package_hint) == ("b", Path("b.adoc"))446@pytest.mark.parametrize("package_hint", [None, "", "a", "b", Package.INPUT_PACKAGE_NAME])447def test_find_original_file__without_include_dir(package_hint, package_manager, tmp_path,448 build_dir):449 create_package_dir(tmp_path, "a")450 create_package_dir(tmp_path, "b")451 spec_file = create_package_spec(tmp_path, "a", "b")452 package_manager.collect(spec_file)453 src_dir = tmp_path / "src"454 src_dir.mkdir()455 in_file = src_dir / "index.adoc"456 in_file.touch()457 package_manager.set_input_files(in_file)458 package_manager.prepare_work_directory(in_file)459 assert package_manager.find_original_file(package_manager.work_dir / "index.adoc",460 package_hint) == (Package.INPUT_PACKAGE_NAME,461 Path("index.adoc"))462 assert package_manager.find_original_file(package_manager.work_dir / "a.adoc",463 package_hint) == ("a", Path("a.adoc"))464 assert package_manager.find_original_file(package_manager.work_dir / "b.adoc",465 package_hint) == ("b", Path("b.adoc"))466def test_friendly_filename(package_manager, tmp_path):467 create_package_dir(tmp_path, "a")468 create_package_dir(tmp_path, "b")469 spec_file = create_package_spec(tmp_path, "a", "b")470 package_manager.collect(spec_file)471 src_dir = tmp_path / "src"472 src_dir.mkdir()473 in_file = src_dir / "index.adoc"474 in_file.touch()475 package_manager.set_input_files(in_file)476 assert package_manager.friendly_filename(str(tmp_path / "a/adoc/a.adoc")) == "a:/a.adoc"477 assert package_manager.friendly_filename(str(tmp_path / "b/adoc/b.adoc")) == "b:/b.adoc"478 assert package_manager.friendly_filename(str(in_file)) == "index.adoc"479 assert package_manager.friendly_filename("/other/file.adoc") == "/other/file.adoc"480def test_make_document__input_dir(package_manager, tmp_path, build_dir):481 src_dir = tmp_path / "src"482 src_dir.mkdir()483 in_file = src_dir / "index.adoc"484 in_file.touch()485 package_manager.set_input_files(in_file)486 package_manager.prepare_work_directory(in_file)487 doc = package_manager.make_document(file_name="index.adoc")488 assert doc is not None489 assert doc.relative_path == Path("index.adoc")490 assert doc.package is not None491 assert doc.package.is_input_package is True492def test_make_document__input_dir__unknown_file(package_manager, tmp_path, build_dir):493 src_dir = tmp_path / "src"494 src_dir.mkdir()495 in_file = src_dir / "index.adoc"496 in_file.touch()497 package_manager.set_input_files(in_file)498 package_manager.prepare_work_directory(in_file)499 with pytest.raises(UnknownFileError):500 package_manager.make_document(file_name="unknown.adoc")501def test_make_document__input_file(package_manager, tmp_path, build_dir):502 src_dir = tmp_path / "src"503 src_dir.mkdir()504 in_file = src_dir / "index.adoc"505 in_file.touch()506 package_manager.set_input_files(in_file)507 package_manager.prepare_work_directory(in_file)508 doc = package_manager.make_document()509 assert doc is not None510 assert doc.relative_path == Path("index.adoc")511 assert doc.package is not None512 assert doc.package.is_input_package is True513def test_make_document__package_file(package_manager, tmp_path, build_dir):514 create_package_dir(tmp_path, "a")515 create_package_dir(tmp_path, "b")516 spec_file = create_package_spec(tmp_path, "a", "b")517 package_manager.collect(spec_file)518 src_dir = tmp_path / "src"519 src_dir.mkdir()520 in_file = src_dir / "index.adoc"521 in_file.touch()522 package_manager.set_input_files(in_file)523 package_manager.prepare_work_directory(in_file)524 doc = package_manager.make_document(package_name="a", file_name="a.adoc")525 assert doc is not None526 assert doc.relative_path == Path("a.adoc")527 assert doc.package is not None528 assert doc.package.name == "a"529 doc = package_manager.make_document(package_name="b", file_name="b.adoc")530 assert doc is not None531 assert doc.relative_path == Path("b.adoc")532 assert doc.package is not None533 assert doc.package.name == "b"534def test_make_document__unknown_package(package_manager, tmp_path, build_dir):535 create_package_dir(tmp_path, "a")536 create_package_dir(tmp_path, "b")537 spec_file = create_package_spec(tmp_path, "a", "b")538 package_manager.collect(spec_file)539 src_dir = tmp_path / "src"540 src_dir.mkdir()541 in_file = src_dir / "index.adoc"542 in_file.touch()543 package_manager.set_input_files(in_file)544 package_manager.prepare_work_directory(in_file)545 with pytest.raises(UnknownPackageError):546 package_manager.make_document(package_name="c", file_name="a.adoc")547def test_make_document__unknown_package_file(package_manager, tmp_path, build_dir):548 create_package_dir(tmp_path, "a")549 create_package_dir(tmp_path, "b")550 spec_file = create_package_spec(tmp_path, "a", "b")551 package_manager.collect(spec_file)552 src_dir = tmp_path / "src"553 src_dir.mkdir()554 in_file = src_dir / "index.adoc"555 in_file.touch()556 package_manager.set_input_files(in_file)557 package_manager.prepare_work_directory(in_file)558 with pytest.raises(UnknownFileError):559 package_manager.make_document(package_name="a", file_name="c.adoc")560 with pytest.raises(UnknownFileError):561 package_manager.make_document(package_name="b", file_name="c.adoc")562def test_make_document__wrong_package_file(package_manager, tmp_path, build_dir):563 create_package_dir(tmp_path, "a")564 create_package_dir(tmp_path, "b")565 spec_file = create_package_spec(tmp_path, "a", "b")566 package_manager.collect(spec_file)567 src_dir = tmp_path / "src"568 src_dir.mkdir()569 in_file = src_dir / "index.adoc"570 in_file.touch()571 package_manager.set_input_files(in_file)572 package_manager.prepare_work_directory(in_file)573 with pytest.raises(UnknownFileError):574 package_manager.make_document(package_name="a", file_name="b.adoc")575 with pytest.raises(UnknownFileError):...
product_admin.py
Source:product_admin.py
...20 page.locator("textarea").fill(admin_product_description)21 # Click span[role="button"]:has-text("åå»ä¸ä¼ ")22 # page.locator("span[role=\"button\"]:has-text(\"åå»ä¸ä¼ \")").click()23 # Upload /Users/michaelcheung/Project/Banana/pic.jpeg24 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/pic.jpeg")25 # Click .ant-select.ant-pro-filed-search-select.pro-field.pro-field-xl.ant-select-multiple .ant-select-selector26 page.locator("#root > div > section > div.ant-layout > main > div > div.ant-pro-grid-content > div > div > div > form > div:nth-child(6) > div.ant-space.ant-space-vertical.ant-space-align-start.ant-pro-form-group-container > div:nth-child(2) > div > div:nth-child(3) > div.ant-col.ant-form-item-control > div > div > div > div > div").click()27 # Click text=Ford28 page.locator("text=Ford").click()29 # Click text=Suitable vehicle brand30 page.locator("text=Suitable vehicle brand").click()31 # Fill text=PriceRM >> [placeholder="请è¾å
¥"]32 page.locator("text=PriceRM >> [placeholder=\"请è¾å
¥\"]").fill(admin_product_price)33 # Fill #stock34 page.locator("#stock").fill(admin_product_stock)35 # Fill text=Weightkg >> [placeholder="请è¾å
¥"]36 page.locator("text=Weightkg >> [placeholder=\"请è¾å
¥\"]").fill(admin_product_weight)37 # Fill text=Unified The FreightRM >> [placeholder="请è¾å
¥"]38 page.locator("text=Unified The FreightRM >> [placeholder=\"请è¾å
¥\"]").fill(admin_product_freight)39 # Click .ant-space div:nth-child(3) .ant-row .ant-col.ant-form-item-control .ant-form-item-control-input .ant-form-item-control-input-content .ant-select .ant-select-selector40 page.locator(".ant-space div:nth-child(3) .ant-row .ant-col.ant-form-item-control .ant-form-item-control-input .ant-form-item-control-input-content .ant-select .ant-select-selector").click()41 # Click .ant-select-dropdown.ant-select-dropdown-placement-topLeft div .rc-virtual-list .rc-virtual-list-holder div .rc-virtual-list-holder-inner .ant-select-item.ant-select-item-option.ant-pro-filed-search-select-option.ant-select-item-option-active42 page.locator("body > div:nth-child(6) > div > div > div > div.rc-virtual-list > div.rc-virtual-list-holder > div > div > div.ant-select-item.ant-select-item-option.ant-pro-filed-search-select-option.ant-select-item-option-active > div").click()43 # Click button:has-text("Save and Publish")44 # with page.expect_navigation(url="https://admin-banana-dev.chunsutech.com/commodity/list"):45 with page.expect_navigation():46 page.locator("button:has-text(\"Save and Publish\")").click()47 48def CreateProductAdvance(page, admin_productname, admin_product_description, admin_product_brand, admin_variation0,49 admin_option0, admin_variation1, admin_option3, admin_product_price,50 admin_product_stock, admin_product_weight, admin_product_sku, admin_product_barcode51 ):52 # Go to https://admin-banana-dev.chunsutech.com/commodity/list53 page.goto("https://admin-banana-dev.chunsutech.com/commodity/list")54 # Click button:has-text("Create")55 page.locator("button:has-text(\"Create\")").click()56 # assert page.url == "https://admin-banana-dev.chunsutech.com/commodity/list/create"57 # Fill text=Product Name0 / 120 >> [placeholder="请è¾å
¥"]58 page.locator("text=Product Name0 / 120 >> [placeholder=\"请è¾å
¥\"]").fill(admin_productname)59 # Click text=Product Category请éæ© >> input[role="combobox"]60 page.locator("text=Product Category请éæ© >> input[role=\"combobox\"]").click()61 # Click text=Accessories >> nth=062 page.locator("text=Accessories").first.click()63 # Click text=Screen Protectors64 page.locator("text=Screen Protectors").click()65 # Click textarea66 page.locator("textarea").click()67 # Fill textarea68 page.locator("textarea").fill(admin_product_description)69 # Upload /Users/michaelcheung/Project/Banana/pic.jpeg70 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0001.jpg")71 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0002.jpg")72 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0003.jpg")73 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0004.jpg")74 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0005.jpg")75 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0006.jpg")76 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0007.jpg")77 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0008.jpg")78 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0009.jpg")79 page.set_input_files("input#pic","/Users/michaelcheung/Project/Banana/Pictures/0010.jpg")80 # Click .ant-select-selection-overflow >> nth=081 page.locator(".ant-select-selection-overflow").first.click()82 # Click .ant-select-tree-checkbox-inner >> nth=083 page.locator(".ant-select-tree-checkbox-inner").first.click()84 # Fill text=åçWarranty Duration请éæ©Warranty Type请éæ©Suitable vehicle brand 请éæ© >> [placeholder="请è¾å
¥"]85 page.locator("text=åçWarranty Duration请éæ©Warranty Type请éæ©Suitable vehicle brand 请éæ© >> [placeholder=\"请è¾å
¥\"]").fill(admin_product_brand)86 # Click text=Warranty Duration请éæ© >> input[role="combobox"]87 page.locator("text=Warranty Duration请éæ© >> input[role=\"combobox\"]").click()88 # Click .ant-select-item >> nth=089 page.locator(".ant-select-item").first.click()90 # Click text=Warranty Type请éæ© >> input[role="combobox"]91 page.locator("text=Warranty Type请éæ© >> input[role=\"combobox\"]").click()92 # Click text=Supplier Warranty >> nth=193 page.locator("text=Supplier Warranty").nth(1).click()94 # Click .ant-select.ant-pro-filed-search-select.pro-field.pro-field-xl.ant-select-multiple .ant-select-selector95 page.locator("#root > div > section > div.ant-layout > main > div > div.ant-pro-grid-content > div > div > div > form > div:nth-child(6) > div.ant-space.ant-space-vertical.ant-space-align-start.ant-pro-form-group-container > div:nth-child(2) > div > div:nth-child(3) > div.ant-col.ant-form-item-control > div > div > div > div > div").click()96 # Click text=Ford97 page.locator("text=Ford").click()98 # Click text=Suitable vehicle brand99 page.locator("text=Suitable vehicle brand").click()100 # Click button:has-text("Enable Variation")101 page.locator("button:has-text(\"Enable Variation\")").click()102 # Click text=Variation >> nth=0103 page.locator("text=Variation").first.click()104 # Fill [placeholder="Enter\ Vairation\ Name\,eg\:colour\,etc\."]105 page.locator("[placeholder=\"Enter\\ Vairation\\ Name\\,eg\\:colour\\,etc\\.\"]").fill(admin_variation0)106 # Fill [placeholder="Enter\ Vairation\ Name\,eg\:Red\,etc\."] >> nth=0107 page.locator("[placeholder=\"Enter\\ Vairation\\ Name\\,eg\\:Red\\,etc\\.\"]").first.fill(admin_option0)108 page.set_input_files('input[id^="testpic_"]',"/Users/michaelcheung/Project/Banana/Pictures/0011.jpg")109 # Click button:has-text("Add Variation")110 page.locator("button:has-text(\"Add Variation\")").click()111 # Click span:has-text("Variation1")112 page.locator("span:has-text(\"Variation1\")").click()113 # Click text=Variation1OptionsAdd Options >> [placeholder="Enter\ Vairation\ Name\,eg\:colour\,etc\."]114 page.locator("#root > div > section > div.ant-layout > main > div > div.ant-pro-grid-content > div > div > div > form > div:nth-child(7) > div.ant-space.ant-space-vertical.ant-space-align-start.ant-pro-form-group-container > div > div > div > div:nth-child(2) > div.ant-row.ant-form-item > div > div > div > span > input").click()115 # Click text=Variation1OptionsAdd Options116 page.locator("#root > div > section > div.ant-layout > main > div > div.ant-pro-grid-content > div > div > div > form > div:nth-child(7) > div.ant-space.ant-space-vertical.ant-space-align-start.ant-pro-form-group-container > div > div > div > div:nth-child(2) > div.ant-row.ant-form-item > div > div > div > span > input").fill(admin_variation1)117 # Fill text=Variation1OptionsAdd Options >> [placeholder="Enter\ Vairation\ Name\,eg\:Red\,etc\."]118 page.locator("text=Variation1OptionsAdd Options >> [placeholder=\"Enter\\ Vairation\\ Name\\,eg\\:Red\\,etc\\.\"]").fill(admin_option3)119 # Fill [placeholder="Price"]120 page.locator("[placeholder=\"Price\"]").fill(admin_product_price)121 # Fill [placeholder="Stock"]122 page.locator("[placeholder=\"Stock\"]").fill(admin_product_stock)...
1_preprocessing_data_updated.py
Source:1_preprocessing_data_updated.py
1#!/usr/bin/env python2# coding: utf-83# In[330]:4#from google.colab import drive5#drive.mount('/content/drive')6# In[331]:7#!pip install wfdb8# In[332]:9import numpy as np, os, sys10from scipy.io import loadmat11import wfdb12import matplotlib.pyplot as pp13import pandas as pd14import csv15# In[333]:16def writetocsv(PATIENTSDATA,output_dir,csvfilename):17 #cols=['ptID','Num_Leads','Sample_Fs','Lead_Name_1','Gain_Lead_1','Lead_Name_2','Gain_Lead_2','Lead_Name_3','Gain_Lead_3','Lead_Name_4','Gain_Lead_4','Lead_Name_5','Gain_Lead_5','Lead_Name_6','Gain_Lead_6','Lead_Name_7','Gain_Lead_7','Lead_Name_8','Gain_Lead_8','Lead_Name_9','Gain_Lead_9','Lead_Name_10','Gain_Lead_10','Lead_Name_11','Gain_Lead_11','Lead_Name_12','Gain_Lead_12','Age','Sex','SNOMED_Label_ID','Label_Name','Label_Abbvreviated']18 19 #ptDATA_Df= pd.DataFrame(PATIENTSDATA, columns=cols).T20 21 22 with open(output_dir+"/../CSV/"+"/"+csvfilename,'a') as f1:23 writer=csv.writer(f1, delimiter=',',lineterminator='\n',)24 writer.writerow(PATIENTSDATA)25 f1.close()26# In[334]:27def returnlistofcsvfile(output_dir,csvfilename):28 savingto=output_dir+"/../CSV/"+"/"+csvfilename29 filelist=list()30 31 if not os.path.exists(savingto):32 return ""33 else:34 with open(savingto,'r') as f1:35 reader = csv.reader(f1, delimiter=',')36 included_cols = [1]37 for row in reader:38 if not str(row[0]) =="ptID":39 filelist.append(str(row[0])+".mat")40 f1.close()41 return filelist42# In[335]:43def writeheadertocsvonce(output_dir, csvfilename):44 cols=['ptID','Num_Leads','Sample_Fs','Lead_Name_1','Gain_Lead_1','Lead_Name_2','Gain_Lead_2','Lead_Name_3','Gain_Lead_3','Lead_Name_4','Gain_Lead_4','Lead_Name_5','Gain_Lead_5','Lead_Name_6','Gain_Lead_6','Lead_Name_7','Gain_Lead_7','Lead_Name_8','Gain_Lead_8','Lead_Name_9','Gain_Lead_9','Lead_Name_10','Gain_Lead_10','Lead_Name_11','Gain_Lead_11','Lead_Name_12','Gain_Lead_12','Age','Sex','Length_ECG','SNOMED_Label_ID','Label_Name','Label_Abbvreviated']45 savingto= output_dir+"/../CSV/"+"/"+csvfilename46 if not os.path.exists(savingto):47 with open(savingto,'w') as f1:48 writer=csv.writer(f1, delimiter=',',lineterminator='\n',)49 writer.writerow(cols)50 f1.close()51# In[336]:52def makealldirectoriesatonce(output_directory,actual_labels,classes,csvfilename):53 lead_names=['I','II','III','aVR','aVL','aVF','V1', 'V2', 'V3', 'V4','V5','V6']54 tmp_class_names=list(actual_labels.values())55 56 #print(tmp_class_names)57 #print(actual_labels)58 if not os.path.isdir(output_directory):59 os.mkdir(output_directory)60 if not os.path.isdir(output_directory +"/../CSV"):61 os.mkdir(output_directory+"/../CSV")62 63 64 writeheadertocsvonce(output_directory,csvfilename)65 66 for i in range(len(lead_names)):67 if not os.path.isdir(output_directory+"/"+str(lead_names[i])):68 os.mkdir(output_directory+"/"+str(lead_names[i]))69 for ii in range(len(tmp_class_names)):70 if not os.path.isdir(output_directory+"/"+str(lead_names[i])+"/"+str(tmp_class_names[ii])):71 os.mkdir(output_directory+"/"+str(lead_names[i])+"/"+str(tmp_class_names[ii]))72# In[337]:73def drawandsavefig(PTDETAILSDATA, data, output_directory):74 leads=list()75 ptID=str(PTDETAILSDATA[0])76 num_leads=int(PTDETAILSDATA[1])77 for i in range(num_leads):78 79 leads.append(PTDETAILSDATA[2*i+3])80 newdir=output_directory+"/"+ str(leads[i])+"/"+str(PTDETAILSDATA[-1])81 savingto=newdir+"/"+ptID+"_"+str(leads[i])+".jpg"82 if not os.path.exists(savingto):83 x=pp.figure(num=None, figsize=(4, 4), dpi=300, facecolor='w', edgecolor='k')84 pp.axis('off')85 pp.grid(False)86 87 #print("Length: "+ str(len(data[i])))88 pp.plot(data[i][:2000], "k")89 pp.savefig(savingto,dpi=300)90 #print("Saved to: "+ savingto)91 pp.close(x)92 #pp.show()93 94# In[ ]:95# In[338]:96def load_data(filename):97 x = loadmat(filename)98 data = np.asarray(x['val'], dtype=np.float64)99 new_file = filename.replace('.mat','.hea')100 input_header_file = os.path.join(new_file)101 with open(input_header_file,'r') as f:102 header_data=f.readlines()103 return data, header_data104# In[339]:105def getactuallabels(classes):106 dictclasses={'164884008':'Premature Ventricular Complexes', '164889003':'Atrial Fibrillation', '164909002':'Left Bundle Branch Block', '164931005':'ST Elevation', '270492004':'1st Degree AV Block', '284470004':'Premature Atrial Contraction', '426783006':'Sinus Rhythm', '429622005':'ST Depression', '59118001':'Right Bundle Branch Block'}107 dictclasses_abrevated={'164884008':'PVC', '164889003':'AF', '164909002':'LBBB', '164931005':'STE', '270492004':'IAVB', '284470004':'PAC', '426783006':'SNR', '429622005':'STD', '59118001':'RBBB'}108 '''for label in classes:109 #print(label)110 print(dictclasses_abrevated[str(label)] + " : " + dictclasses[str(label)])111 '''112 return dictclasses, dictclasses_abrevated113# In[ ]:114# In[340]:115def get_classes(input_directory,files):116 classes=set()117 for f in files:118 g = f.replace('.mat','.hea')119 input_file = os.path.join(input_directory,g)120 with open(input_file,'r') as f:121 for lines in f:122 if lines.startswith('#Dx'):123 tmp = lines.split(': ')[1].split(',')124 for c in tmp:125 classes.add(c.strip())126 return sorted(classes)127# In[341]:128def get_12ECG_features(tmp_input_file, data, header_data):129 ptDetails=list()130 gainLeadDetails=list()131 132 tmp_hea = header_data[0].split(' ')133 134 ptID = tmp_hea[0]135 ptDetails.append(ptID)136 num_leads = int(tmp_hea[1])137 ptDetails.append(num_leads)138 sample_Fs= int(tmp_hea[2])139 ptDetails.append(sample_Fs)140 141 142 gain_lead = np.zeros(num_leads)143 #ptDetails.append(gain_lead)144 for ii in range(num_leads):145 tmp_hea = header_data[ii+1].split(' ')146 gain_lead[ii] = int(tmp_hea[2].split('/')[0])147 lead_no= str(tmp_hea[8]).strip()148 ptDetails.append(lead_no)149 ptDetails.append(gain_lead[ii])150 151 # for testing, we included the mean age of 57 if the age is a NaN152 # This value will change as more data is being released153 for iline in header_data:154 if iline.startswith('#Age'):155 tmp_age = iline.split(': ')[1].strip()156 age = int(tmp_age if tmp_age != 'NaN' else 57)157 ptDetails.append(age)158 elif iline.startswith('#Sex'):159 tmp_sex = iline.split(': ')[1]160 if tmp_sex.strip()=='Female':161 sex=1162 else:163 sex=0164 ptDetails.append(sex)165 elif iline.startswith('#Dx'):166 label = iline.split(': ')[1].split(',')[0].strip()167 ptDetails.append(len(data[0]))168 ptDetails.append(label)169 170 171 #ptDetails.append()172 #ptDetails.append(tmp_input_file, ptID,label,num_leads,sample_Fs, gain_lead,age,sex,gainLeadDetails)173 return ptDetails174# In[ ]:175# In[342]:176def main():177 178 179 DRAW_SAVE_ONLY_IMPORTANT_PICS=1180 TO_DRAW_PICS=list()181 DRAWN_PICS=list()182 183 184 #classes=get_classes(input_directory,input_files)185 classes= ['164884008', '164889003', '164909002', '164931005', '270492004', '284470004', '426783006', '429622005', '59118001']186 #print(classes)187 actual_label=getactuallabels(classes)188 #print(actual_label[0])189 190 191 192 input_directory="../DATA/Training_WFDB"193 output_directory="../DATA/Training_IMAGES_Classed_Trimmed_0_2"194 csvfilename="1.PATIENT_HEADER.csv"195 196 makealldirectoriesatonce(output_directory,actual_label[1],classes,csvfilename)197 198 199 #data=readfile("AOOO.mat")200 #header_data=readfile("A0000.hea")201 input_files = []202 203 alreadyprocessed_input_files=returnlistofcsvfile(output_directory,csvfilename)204 205 for f in os.listdir(input_directory):206 if os.path.isfile(os.path.join(input_directory, f)) and not f.lower().startswith('.') and f.lower().endswith('mat'):207 if f not in alreadyprocessed_input_files:208 input_files.append(f)209 210 211 print("Noof input files remaining :" + str(len(set(input_files))))212 print("Noof input files processed :" + str(len(set(alreadyprocessed_input_files))))213 214 '''215 if not alreadyprocessed_input_files == "":216 print("Noof input files processed:" + str(len( alreadyprocessed_input_files)))217 #print(input_files)218 219 set_input_files=set(input_files) - set(alreadyprocessed_input_files)220 #print(set_input_files)221 222 input_files = list(set_input_files)223 #print(list(set_input_files))224 print("Noof input files remaining:" + str(len(input_files)))225 '''226 227 num_files = len(input_files)228 229 230 231 for label in classes:232 break233 #actual label234 #print(actual_label[0][str(label)])235 #abrevated label236 #print(actual_label[1][str(label)])237 238 239 240 for i, f in enumerate(input_files):241 #print(' {}/{}...'.format(i+1, num_files))242 tmp_input_file = os.path.join(input_directory,f)243 244 245 data,header_data = load_data(tmp_input_file)246 PTDETAILSDATA=get_12ECG_features(tmp_input_file, data, header_data)247 PTDETAILSDATA.append(actual_label[0][str(PTDETAILSDATA[-1])])248 PTDETAILSDATA.append(actual_label[1][str(PTDETAILSDATA[-2])])249 250 print("DONE:" + PTDETAILSDATA[0])251 drawandsavefig(PTDETAILSDATA,data,output_directory)252 writetocsv(PTDETAILSDATA, output_directory,csvfilename)253 #print(header_data)254 255 256 #annotation = wfdb.rdann(tmp_input_file.replace('.hea',''), 'atr', sampto=3000)257 #wfdb.plotrec(record, annotation = " ",title='Record 100 from MIT-BIH Arrhythmia Database',timeunits = 'seconds', figsize = (10,4), ecggrids = 'all')258 259 260# In[343]:261def drawandsavefig_temp(PTDETAILSDATA, data, output_directory):262 leads=list()263 ptID=str(PTDETAILSDATA[0])264 num_leads=int(PTDETAILSDATA[1])265 266 267 for i in range(num_leads):268 269 leads.append(PTDETAILSDATA[2*i+3])270 newdir=output_directory+"/"+ str(leads[i])+"/"+str(PTDETAILSDATA[-1])271 savingto=newdir+"/"+ptID+"_"+str(leads[i])+".jpg"272 273 print("Saving to: "+ savingto)274 275 pp.figure(num=None, figsize=(14, 6), dpi=300, facecolor='w', edgecolor='k')276 pp.axis('off')277 pp.plot(data[i][:2000])278 pp.show()279 pp.savefig(newdir+"/"+"")280# In[ ]:281# In[344]:282if __name__=="__main__":283 main()...
inputType.py
Source:inputType.py
...37 # se for list["",""]-> eh strings pro fusion38 # se for list[ [rks1], [rks2] ] -> eh o arquivo, escrever e passar o path39 if isinstance(self.input_files_list, str): # path40 # vai escrever o path e colocar auto no format41 self.set_input_files(self.input_files_list)42 if isinstance(self.input_files_list, list):43 # list de strs, ou seja, lista de paths44 if isinstance(self.input_files_list[0], str):45 self.set_input_files(self.input_files_list)46 # list de list -> ou seja, precisa escrever47 if isinstance(self.input_files_list[0], list):48 aux = os.path.dirname(self.config_path)49 data_paths = configGenerator.write_input_files(50 self.input_files_list, aux)51 self.set_input_files(data_paths)52 def set_method_name(self, value):53 """54 Set the method to be used55 Parameters:56 value -> new method value57 """58 configGenerator.setParameter("UDL_METHOD", value, self.parameters)59 def set_output_file_format(self, value):60 """61 Set the output format62 Parameters:63 value -> new method value64 """65 configGenerator.setParameter(66 "OUTPUT_FILE_FORMAT", value, self.parameters)67 def set_output_matrix_type(self, value):68 """69 Set the output matrix type70 Parameters:71 value -> new method value72 """73 configGenerator.setParameter(74 "OUTPUT_MATRIX_TYPE", value, self.parameters)75 def set_output_rk_format(self, value):76 """77 Set the output ranked list format78 Parameters:79 value -> new method value80 """81 configGenerator.setParameter(82 "OUTPUT_RK_FORMAT", value, self.parameters)83 def set_output_file_path(self, value):84 """85 Set the path of the output86 Parameters:87 value -> new method value88 """89 configGenerator.setParameter(90 "OUTPUT_FILE_PATH", value, self.parameters)91 def set_rk_format(self, value):92 """93 """94 configGenerator.setParameter("INPUT_RK_FORMAT", value, self.parameters)95 def set_input_matrix_type(self, value):96 """97 """98 configGenerator.setParameter(99 "INPUT_MATRIX_TYPE", value, self.parameters)100 def set_input_files(self, value):101 """102 """103 self.input_files_list = value104 if isinstance(self.input_files_list, list):105 if isinstance(self.input_files_list[0], list):106 aux = os.path.dirname(self.config_path)107 data_paths = configGenerator.write_input_files(108 self.input_files_list, aux)109 self.set_input_files(data_paths)110 return111 configGenerator.set_input(value, self.parameters, self.list_parameters)112 def set_ranked_lists_size(self, value):113 """114 Set ALL ranked lists sizes!115 """116 configGenerator.set_all_ranked_lists_size(117 value, self.parameters, self.list_parameters)118 def set_dataset_size(self, value):119 """120 """121 configGenerator.setParameter("SIZE_DATASET", value, self.parameters)122 def set_lists_file(self, value):123 """...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!