Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
yijie-yang committed Oct 10, 2024
1 parent 7af211c commit 04cdda4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 64 deletions.
1 change: 1 addition & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest-playwright
python -m playwright install --with-deps
python3 -m pip install Pillow
Expand Down
141 changes: 77 additions & 64 deletions ci/playwright_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@


def compare_images(image_suffix: str, threshold: int = 0):
tmp_image = Image.open(TMP_SCREENSHOT_DIR + image_suffix).convert("L")
expected_image = Image.open(EXPECTED_SCREENSHOT_DIR + image_suffix).convert("L")
tmp_image = Image.open(TMP_SCREENSHOT_DIR + image_suffix).convert("L")
expected_image = Image.open(EXPECTED_SCREENSHOT_DIR + image_suffix).convert(
"L"
)

if tmp_image.size != expected_image.size:
return False
if tmp_image.size != expected_image.size:
return False

diff = ImageChops.difference(tmp_image, expected_image)
max_diff = diff.getextrema()[1]
if max_diff <= threshold:
return True
return False
diff = ImageChops.difference(tmp_image, expected_image)
max_diff = diff.getextrema()[1]
if max_diff <= threshold:
return True
return False


def test_homepage(page: Page):
Expand All @@ -46,73 +48,84 @@ def test_homepage(page: Page):


def test_litert_direct_adapter(page: Page):
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(TEST_FILES_DIR + "fully_connected.tflite")
page.get_by_role("button", name="Add").click()
page.get_by_text("arrow_drop_down").click()
page.get_by_text("TFLite adapter (Flatbuffer)").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.click(position={"x":469,"y":340})
page.screenshot(path=TMP_SCREENSHOT_DIR + "litert_direct.png")
assert compare_images("litert_direct.png")
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(
TEST_FILES_DIR + "fully_connected.tflite"
)
page.get_by_role("button", name="Add").click()
page.get_by_text("arrow_drop_down").click()
page.get_by_text("TFLite adapter (Flatbuffer)").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.click(position={"x": 469, "y": 340})
page.screenshot(path=TMP_SCREENSHOT_DIR + "litert_direct.png")
assert compare_images("litert_direct.png")


def test_litert_mlir_adapter(page: Page):
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(TEST_FILES_DIR + "fully_connected.tflite")
page.get_by_role("button", name="Add").click()
page.get_by_text("arrow_drop_down").click()
page.get_by_text("TFLite adapter (MLIR)").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.click(position={"x":514,"y":332})
page.screenshot(path=TMP_SCREENSHOT_DIR + "litert_mlir.png")
assert compare_images("litert_mlir.png")
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(
TEST_FILES_DIR + "fully_connected.tflite"
)
page.get_by_role("button", name="Add").click()
page.get_by_text("arrow_drop_down").click()
page.get_by_text("TFLite adapter (MLIR)").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.click(position={"x": 514, "y": 332})
page.screenshot(path=TMP_SCREENSHOT_DIR + "litert_mlir.png")
assert compare_images("litert_mlir.png")


def test_tf_mlir_adapter(page: Page):
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(TEST_FILES_DIR + "simple_add/saved_model.pb")
page.get_by_role("button", name="Add").click()
page.get_by_text("arrow_drop_down").click()
page.get_by_text("TF adapter (MLIR) Default").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.click(position={"x":444,"y":281})
page.screenshot(path=TMP_SCREENSHOT_DIR + "tf_mlir.png")
assert compare_images("tf_mlir.png")

page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(
TEST_FILES_DIR + "simple_add/saved_model.pb"
)
page.get_by_role("button", name="Add").click()
page.get_by_text("arrow_drop_down").click()
page.get_by_text("TF adapter (MLIR) Default").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.click(position={"x": 444, "y": 281})
page.screenshot(path=TMP_SCREENSHOT_DIR + "tf_mlir.png")
assert compare_images("tf_mlir.png")


def test_tf_direct_adapter(page: Page):
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(TEST_FILES_DIR + "simple_add/saved_model.pb")
page.get_by_role("button", name="Add").click()
page.get_by_text("arrow_drop_down").click()
page.get_by_text("TF adapter (direct)").click()
page.get_by_role("button", name="View selected models").click()
page.get_by_text("__inference__traced_save_36", exact=True).click()
page.get_by_text("__inference_add_6").click()
page.locator("canvas").first.click(position={"x":723,"y":278})
page.screenshot(path=TMP_SCREENSHOT_DIR + "tf_direct.png")
assert compare_images("tf_direct.png")
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(
TEST_FILES_DIR + "simple_add/saved_model.pb"
)
page.get_by_role("button", name="Add").click()
page.get_by_text("arrow_drop_down").click()
page.get_by_text("TF adapter (direct)").click()
page.get_by_role("button", name="View selected models").click()
page.get_by_text("__inference__traced_save_36", exact=True).click()
page.get_by_text("__inference_add_6").click()
page.locator("canvas").first.click(position={"x": 723, "y": 278})
page.screenshot(path=TMP_SCREENSHOT_DIR + "tf_direct.png")
assert compare_images("tf_direct.png")


def test_tf_graphdef_adapter(page: Page):
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(TEST_FILES_DIR + "graphdef_foo.pbtxt")
page.get_by_role("button", name="Add").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.click(position={"x":468,"y":344})
page.screenshot(path=TMP_SCREENSHOT_DIR +"graphdef.png")
assert compare_images("graphdef.png")
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(
TEST_FILES_DIR + "graphdef_foo.pbtxt"
)
page.get_by_role("button", name="Add").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.click(position={"x": 468, "y": 344})
page.screenshot(path=TMP_SCREENSHOT_DIR + "graphdef.png")
assert compare_images("graphdef.png")


def test_shlo_mlir_adapter(page: Page):
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(TEST_FILES_DIR + "stablehlo_sin.mlir")
page.get_by_role("button", name="Add").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.dblclick(position={"x":442,"y":339})
time.sleep(0.5) # Delay for the animation
page.locator("canvas").first.click(position={"x":488,"y":408})
page.screenshot(path=TMP_SCREENSHOT_DIR + "shlo_mlir.png")
assert compare_images("shlo_mlir.png")
page.goto(LOCAL_SERVER)
page.get_by_placeholder("Absolute file paths (").fill(
TEST_FILES_DIR + "stablehlo_sin.mlir"
)
page.get_by_role("button", name="Add").click()
page.get_by_role("button", name="View selected models").click()
page.locator("canvas").first.dblclick(position={"x": 442, "y": 339})
time.sleep(0.5) # Delay for the animation
page.locator("canvas").first.click(position={"x": 488, "y": 408})
page.screenshot(path=TMP_SCREENSHOT_DIR + "shlo_mlir.png")
assert compare_images("shlo_mlir.png")

0 comments on commit 04cdda4

Please sign in to comment.