From f89fe3a8bdaa45852c306ae62d29a4b4e6d68918 Mon Sep 17 00:00:00 2001 From: Alexis Deprez Date: Thu, 3 Oct 2024 17:35:19 +0200 Subject: [PATCH] feat: remove unused exceptions (#613) * feat: remove unused exceptions * chore: format --- .../lavague/drivers/playwright/base.py | 12 ------- .../lavague/drivers/selenium/base.py | 10 +----- lavague-sdk/lavague/sdk/base_driver.py | 5 ++- lavague-sdk/lavague/sdk/exceptions.py | 35 ++----------------- 4 files changed, 5 insertions(+), 57 deletions(-) diff --git a/lavague-integrations/drivers/lavague-drivers-playwright/lavague/drivers/playwright/base.py b/lavague-integrations/drivers/lavague-drivers-playwright/lavague/drivers/playwright/base.py index 78bbf337..4b9cad8c 100644 --- a/lavague-integrations/drivers/lavague-drivers-playwright/lavague/drivers/playwright/base.py +++ b/lavague-integrations/drivers/lavague-drivers-playwright/lavague/drivers/playwright/base.py @@ -11,10 +11,6 @@ PossibleInteractionsByXpath, InteractionType, ) -from lavague.sdk.exceptions import ( - NoElementException, - AmbiguousException, -) import time @@ -207,14 +203,6 @@ def exec_code( ) elif action_name == "wait": self.perform_wait(item["action"]["args"]["duration"]) - elif action_name == "failNoElement": - raise NoElementException( - "No element: " + item["action"]["args"]["value"] - ) - elif action_name == "failAmbiguous": - raise AmbiguousException( - "Ambiguous: " + item["action"]["args"]["value"] - ) self.wait_for_idle() diff --git a/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py b/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py index 46fd0aa0..9cd741a2 100644 --- a/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py +++ b/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py @@ -25,11 +25,7 @@ InteractionType, DOMNode, ) -from lavague.sdk.exceptions import ( - CannotBackException, - NoElementException, - AmbiguousException, -) +from lavague.sdk.exceptions import CannotBackException from PIL import Image from io import BytesIO from selenium.webdriver.chrome.options import Options @@ -298,10 +294,6 @@ def exec_code( xpath, ScrollDirection.from_string(args.get("value", "DOWN")), ) - case "failNoElement": - raise NoElementException("No element: " + args["value"]) - case "failAmbiguous": - raise AmbiguousException("Ambiguous: " + args["value"]) case _: raise ValueError(f"Unknown action: {action_name}") diff --git a/lavague-sdk/lavague/sdk/base_driver.py b/lavague-sdk/lavague/sdk/base_driver.py index ec398851..2c9dfefe 100644 --- a/lavague-sdk/lavague/sdk/base_driver.py +++ b/lavague-sdk/lavague/sdk/base_driver.py @@ -20,6 +20,7 @@ class InteractionType(Enum): r_get_xpaths_from_html = r'xpath=["\'](.*?)["\']' + class ScrollDirection(Enum): """Enum for the different scroll directions. Value is (x, y, dimension_index)""" @@ -277,7 +278,7 @@ def scroll( scroll_factor=0.75, ): pass - + # TODO: Remove these methods as they are not used @abstractmethod def scroll_up(self): @@ -489,8 +490,6 @@ def __exit__(self, exc_type, exc_val, exc_tb): pass - - def js_wrap_function_call(fn: str): return "(function(){" + fn + "})()" diff --git a/lavague-sdk/lavague/sdk/exceptions.py b/lavague-sdk/lavague/sdk/exceptions.py index db902474..19fa7e25 100644 --- a/lavague-sdk/lavague/sdk/exceptions.py +++ b/lavague-sdk/lavague/sdk/exceptions.py @@ -1,38 +1,7 @@ -from typing import Optional - - -class NavigationException(Exception): - pass - - -class ExtractorException(Exception): +class DriverException(Exception): pass -class CannotBackException(NavigationException): +class CannotBackException(DriverException): def __init__(self, message="History root reached, cannot go back"): super().__init__(message) - - -class RetrievalException(NavigationException): - pass - - -class NoElementException(RetrievalException): - def __init__(self, message="No element found"): - super().__init__(message) - - -class AmbiguousException(RetrievalException): - def __init__(self, message="Multiple elements could match"): - super().__init__(message) - - -class HallucinatedException(RetrievalException): - def __init__(self, xpath: str, message: Optional[str] = None): - super().__init__(message or f"Element was hallucinated: {xpath}") - - -class ElementOutOfContextException(RetrievalException): - def __init__(self, xpath: str, message: Optional[str] = None): - super().__init__(message or f"Element exists but was not in context: {xpath}")