Merge branch 'main' into xiaochuanli/addChromeExtensions
This commit is contained in:
@@ -20,7 +20,6 @@ from .chrome import (
|
||||
get_find_unpacked_extension_path,
|
||||
get_data_delete_automacally,
|
||||
get_active_tab_html_parse,
|
||||
get_active_tab_html_parse_accTree,
|
||||
get_active_tab_url_parse,
|
||||
get_gotoRecreationPage_and_get_html_content,
|
||||
get_url_dashPart,
|
||||
|
||||
@@ -33,16 +33,25 @@ def _parse_sheet_idx(sheet_idx: Union[int, str]
|
||||
) -> Tuple[BOOK, str]:
|
||||
# function _parse_sheet_idx {{{ #
|
||||
if isinstance(sheet_idx, int):
|
||||
index: str = result_sheet_names[sheet_idx]
|
||||
try:
|
||||
index: str = result_sheet_names[sheet_idx]
|
||||
except:
|
||||
index = ""
|
||||
book: BOOK = result
|
||||
elif sheet_idx.startswith("RI"):
|
||||
index: str = result_sheet_names[int(sheet_idx[2:])]
|
||||
try:
|
||||
index: str = result_sheet_names[int(sheet_idx[2:])]
|
||||
except:
|
||||
index = ""
|
||||
book: BOOK = result
|
||||
elif sheet_idx.startswith("RN"):
|
||||
index: str = sheet_idx[2:]
|
||||
book: BOOK = result
|
||||
elif sheet_idx.startswith("EI"):
|
||||
index: str = expected_sheet_names[int(sheet_idx[2:])]
|
||||
try:
|
||||
index: str = expected_sheet_names[int(sheet_idx[2:])]
|
||||
except:
|
||||
index = ""
|
||||
book: BOOK = expected
|
||||
elif sheet_idx.startswith("EN"):
|
||||
index: str = sheet_idx[2:]
|
||||
@@ -59,24 +68,29 @@ SHEET = Union[pd.DataFrame, Worksheet, List[str]]
|
||||
|
||||
def _load_sheet(book: BOOK, index: str) -> SHEET:
|
||||
# function _load_sheet {{{ #
|
||||
if isinstance(book, str):
|
||||
book: str = cast(str, book)
|
||||
csv_name: str = "{:}-{:}.csv".format(os.path.splitext(book)[0], index)
|
||||
try:
|
||||
if isinstance(book, str):
|
||||
book: str = cast(str, book)
|
||||
csv_name: str = "{:}-{:}.csv".format(os.path.splitext(book)[0], index)
|
||||
|
||||
with open(csv_name) as f:
|
||||
csv_lines: List[str] = list(itertools.dropwhile(lambda l: len(l) == 0
|
||||
, map(lambda l: l.strip()
|
||||
, reversed(f.read().splitlines())
|
||||
)
|
||||
)
|
||||
)
|
||||
return csv_lines
|
||||
if isinstance(book, pd.ExcelFile):
|
||||
return pd.read_excel(book, index)
|
||||
if isinstance(book, Workbook):
|
||||
return book[index]
|
||||
logger.error("Not supported workbook format")
|
||||
raise NotImplementedError("Not supported workbook format")
|
||||
with open(csv_name) as f:
|
||||
csv_lines: List[str] = list(itertools.dropwhile(lambda l: len(l) == 0
|
||||
, map(lambda l: l.strip()
|
||||
, reversed(f.read().splitlines())
|
||||
)
|
||||
)
|
||||
)
|
||||
return csv_lines
|
||||
if isinstance(book, pd.ExcelFile):
|
||||
return pd.read_excel(book, index)
|
||||
if isinstance(book, Workbook):
|
||||
return book[index]
|
||||
logger.error("Not supported workbook format")
|
||||
raise NotImplementedError("Not supported workbook format")
|
||||
except NotImplementedError as e:
|
||||
raise e
|
||||
except:
|
||||
return None
|
||||
# }}} function _load_sheet #
|
||||
|
||||
|
||||
@@ -140,6 +154,8 @@ def compare_table(result: str, expected: str = None, **options) -> float:
|
||||
|
||||
error_limit: int = r.get("precision", 4)
|
||||
sheet1: pd.DataFrame = _load_sheet(*parse_idx(r["sheet_idx0"], pdworkbookr, pdworkbooke)).round(error_limit)
|
||||
if sheet1 is None:
|
||||
return 0.
|
||||
sheet2: pd.DataFrame = _load_sheet(*parse_idx(r["sheet_idx1"], pdworkbookr, pdworkbooke)).round(error_limit)
|
||||
metric: bool = sheet1.equals(sheet2)
|
||||
logger.debug("Sheet1: \n%s", str(sheet1))
|
||||
@@ -158,6 +174,8 @@ def compare_table(result: str, expected: str = None, **options) -> float:
|
||||
# ignore_case: optional, defaults to False
|
||||
|
||||
sheet1: List[str] = _load_sheet(*parse_idx(r["sheet_idx0"], result, expected))
|
||||
if sheet1 is None:
|
||||
return 0.
|
||||
sheet2: List[str] = _load_sheet(*parse_idx(r["sheet_idx1"], result, expected))
|
||||
if r.get("ignore_case", False):
|
||||
sheet1 = [l.lower() for l in sheet1]
|
||||
@@ -195,11 +213,11 @@ def compare_table(result: str, expected: str = None, **options) -> float:
|
||||
# sheet_idx1: as sheet_idx0
|
||||
# props: list of str indicating concerned styles, see utils._read_cell_style
|
||||
|
||||
sheet_idx1: Tuple[Book, str] = parse_idx(r["sheet_idx0"], xlworkbookr, xlworkbooke)
|
||||
sheet_idx1: Tuple[BOOK, str] = parse_idx(r["sheet_idx0"], xlworkbookr, xlworkbooke)
|
||||
book_name1: str = parse_idx(r["sheet_idx0"], result, expected)[0]
|
||||
styles1: Dict[str, List[Any]] = load_xlsx_styles(*sheet_idx1, book_name1, **r)
|
||||
|
||||
sheet_idx2: Tuple[Book, str] = parse_idx(r["sheet_idx1"], xlworkbookr, xlworkbooke)
|
||||
sheet_idx2: Tuple[BOOK, str] = parse_idx(r["sheet_idx1"], xlworkbookr, xlworkbooke)
|
||||
book_name2: str = parse_idx(r["sheet_idx1"], result, expected)[0]
|
||||
styles2: Dict[str, List[Any]] = load_xlsx_styles(*sheet_idx2, book_name2, **r)
|
||||
# number_formats1: List[str] = [c.number_format.lower() for col in sheet1.iter_cols() for c in col if c.value is not None and c.data_type=="n"]
|
||||
@@ -214,6 +232,8 @@ def compare_table(result: str, expected: str = None, **options) -> float:
|
||||
# sheet_idx1: as sheet_idx0
|
||||
|
||||
sheet1: Worksheet = _load_sheet(*parse_idx(r["sheet_idx0"], xlworkbookr, xlworkbooke))
|
||||
if sheet1 is None:
|
||||
return 0.
|
||||
sheet2: Worksheet = _load_sheet(*parse_idx(r["sheet_idx1"], xlworkbookr, xlworkbooke))
|
||||
metric: bool = sheet1.freeze_panes == sheet2.freeze_panes
|
||||
logger.debug("Assertion: %s.freeze(%s) == %s.freeze(%s) - %s"
|
||||
@@ -230,6 +250,8 @@ def compare_table(result: str, expected: str = None, **options) -> float:
|
||||
# ref: value
|
||||
|
||||
sheet: Worksheet = _load_sheet(*parse_idx(r["sheet_idx"], xlworkbookr, xlworkbooke))
|
||||
if sheet is None:
|
||||
return 0.
|
||||
zoom_scale: Number = sheet.sheet_view.zoomScale or 100.
|
||||
metric: bool = _match_value_to_rule(zoom_scale, r)
|
||||
logger.debug("Assertion: %s.zoom(%.1f) %s %.1f - %s", r["sheet_idx"], zoom_scale, r["method"], r["ref"],
|
||||
@@ -258,6 +280,8 @@ def compare_table(result: str, expected: str = None, **options) -> float:
|
||||
# * imeMode
|
||||
|
||||
sheet: Worksheet = _load_sheet(*parse_idx(r["sheet_idx"], xlworkbookr, xlworkbooke))
|
||||
if sheet is None:
|
||||
return 0.
|
||||
data_validators: List[DataValidation] = sheet.data_validations.dataValidation
|
||||
|
||||
total_metric = len(data_validators) >= len(r["dv_props"])
|
||||
@@ -348,6 +372,8 @@ def compare_table(result: str, expected: str = None, **options) -> float:
|
||||
# supported attributes: value & those supported by utils._read_cell_style
|
||||
|
||||
sheet: Worksheet = _load_sheet(*parse_idx(r["sheet_idx"], xlworkbookr, xlworkbooke))
|
||||
if sheet is None:
|
||||
return 0.
|
||||
# data_frame: pd.DataFrame = _load_sheet(*parse_idx(r["sheet_idx"], pdworkbookr, pdworkbooke))
|
||||
cell: Cell = sheet[r["coordinate"]]
|
||||
metric: bool = True
|
||||
|
||||
@@ -1,41 +1,62 @@
|
||||
{
|
||||
"id": "9f935cce-0a9f-435f-8007-817732bfc0a5",
|
||||
"snapshot": "chrome",
|
||||
"instruction": "Browse list of Civil Division forms.",
|
||||
"source": "online_tasks",
|
||||
"config": [
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"google-chrome",
|
||||
"--remote-debugging-port=1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"socat",
|
||||
"tcp-listen:9222,fork",
|
||||
"tcp:localhost:1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "chrome_open_tabs",
|
||||
"parameters": {
|
||||
"urls_to_open": [
|
||||
"https://www.justice.gov/"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "activate_window",
|
||||
"parameters": {
|
||||
"window_name": "Google Chrome"
|
||||
}
|
||||
"id": "9f935cce-0a9f-435f-8007-817732bfc0a5",
|
||||
"snapshot": "chrome",
|
||||
"instruction": "Browse list of Civil Division forms.",
|
||||
"source": "online_tasks",
|
||||
"config": [
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"google-chrome",
|
||||
"--remote-debugging-port=1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"socat",
|
||||
"tcp-listen:9222,fork",
|
||||
"tcp:localhost:1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "chrome_open_tabs",
|
||||
"parameters": {
|
||||
"urls_to_open": [
|
||||
"https://www.justice.gov/"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "activate_window",
|
||||
"parameters": {
|
||||
"window_name": "Google Chrome"
|
||||
}
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
"related_apps": [
|
||||
"chrome"
|
||||
],
|
||||
"evaluator": {
|
||||
"func": "is_expected_url_pattern_match",
|
||||
"result": {
|
||||
"type": "active_tab_info",
|
||||
"selectors": [
|
||||
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
|
||||
],
|
||||
"goto_prefix": "https://www."
|
||||
},
|
||||
"expected": {
|
||||
"type": "rule",
|
||||
"rules": {
|
||||
"expected": [
|
||||
"forms\\?title=&field_component_target_id=431"
|
||||
]
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
|
||||
@@ -1,41 +1,63 @@
|
||||
{
|
||||
"id": " b070486d-e161-459b-aa2b-ef442d973b92",
|
||||
"snapshot": "chrome",
|
||||
"instruction": "Show side effects of Tamiflu.",
|
||||
"source": "online_tasks",
|
||||
"config": [
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"google-chrome",
|
||||
"--remote-debugging-port=1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"socat",
|
||||
"tcp-listen:9222,fork",
|
||||
"tcp:localhost:1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "chrome_open_tabs",
|
||||
"parameters": {
|
||||
"urls_to_open": [
|
||||
"https://www.drugs.com/"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "activate_window",
|
||||
"parameters": {
|
||||
"window_name": "Google Chrome"
|
||||
}
|
||||
"id": " b070486d-e161-459b-aa2b-ef442d973b92",
|
||||
"snapshot": "chrome",
|
||||
"instruction": "Show side effects of Tamiflu.",
|
||||
"source": "online_tasks",
|
||||
"config": [
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"google-chrome",
|
||||
"--remote-debugging-port=1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"socat",
|
||||
"tcp-listen:9222,fork",
|
||||
"tcp:localhost:1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "chrome_open_tabs",
|
||||
"parameters": {
|
||||
"urls_to_open": [
|
||||
"https://www.drugs.com/"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "activate_window",
|
||||
"parameters": {
|
||||
"window_name": "Google Chrome"
|
||||
}
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
"related_apps": [
|
||||
"chrome"
|
||||
],
|
||||
"evaluator": {
|
||||
"func": "exact_match",
|
||||
"result": {
|
||||
"type": "url_dashPart",
|
||||
"selectors": [
|
||||
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
|
||||
],
|
||||
"goto_prefix": "https://www.",
|
||||
"partIndex": -1,
|
||||
"needDeleteId": false,
|
||||
"returnType": "string"
|
||||
},
|
||||
"expected": {
|
||||
"type": "rule",
|
||||
"rules": {
|
||||
"expected": "tamiflu.html#side-effects"
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
|
||||
@@ -1,41 +1,64 @@
|
||||
{
|
||||
"id": "cabb3bae-cccb-41bd-9f5d-0f3a9fecd825",
|
||||
"snapshot": "chrome",
|
||||
"instruction": "Browse spider-man toys for kids and sort by lowest price.",
|
||||
"source": "online_tasks",
|
||||
"config": [
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"google-chrome",
|
||||
"--remote-debugging-port=1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"socat",
|
||||
"tcp-listen:9222,fork",
|
||||
"tcp:localhost:1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "chrome_open_tabs",
|
||||
"parameters": {
|
||||
"urls_to_open": [
|
||||
"https://www.kohls.com/"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "activate_window",
|
||||
"parameters": {
|
||||
"window_name": "Google Chrome"
|
||||
}
|
||||
"id": "cabb3bae-cccb-41bd-9f5d-0f3a9fecd825",
|
||||
"snapshot": "chrome",
|
||||
"instruction": "Browse spider-man toys for kids and sort by lowest price.",
|
||||
"source": "online_tasks",
|
||||
"config": [
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"google-chrome",
|
||||
"--remote-debugging-port=1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "launch",
|
||||
"parameters": {
|
||||
"command": [
|
||||
"socat",
|
||||
"tcp-listen:9222,fork",
|
||||
"tcp:localhost:1337"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "chrome_open_tabs",
|
||||
"parameters": {
|
||||
"urls_to_open": [
|
||||
"https://www.kohls.com/"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "activate_window",
|
||||
"parameters": {
|
||||
"window_name": "Google Chrome"
|
||||
}
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
"related_apps": [
|
||||
"chrome"
|
||||
],
|
||||
"evaluator": {
|
||||
"func": "is_expected_url_pattern_match",
|
||||
"result": {
|
||||
"type": "active_url_from_accessTree",
|
||||
"selectors": [
|
||||
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
|
||||
],
|
||||
"goto_prefix": "https://www."
|
||||
},
|
||||
"expected": {
|
||||
"type": "rule",
|
||||
"rules": {
|
||||
"expected": [
|
||||
"AgeAppropriate:Kids",
|
||||
"search=spider-man%20toys",
|
||||
"S=4"
|
||||
]
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
@@ -55,4 +78,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user