Make up missing getters and metrics; Update VLC scripts; Start to work on Chrome, update examples instructions
This commit is contained in:
@@ -1,20 +1,36 @@
|
||||
import csv
|
||||
import functools
|
||||
import operator
|
||||
import re
|
||||
from numbers import Number
|
||||
from typing import Callable, Any
|
||||
from typing import Dict, List, Pattern
|
||||
|
||||
import lxml.etree
|
||||
from lxml.etree import _Element
|
||||
from lxml.cssselect import CSSSelector
|
||||
|
||||
from typing import Dict, List, Pattern
|
||||
from typing import Callable, Any
|
||||
from numbers import Number
|
||||
|
||||
import operator
|
||||
from lxml.etree import _Element
|
||||
from rapidfuzz import fuzz
|
||||
import functools
|
||||
import re
|
||||
|
||||
|
||||
def exact_match(result, rules) -> float:
|
||||
expect = rules["expected"]
|
||||
print(result, expect)
|
||||
|
||||
if result == expect:
|
||||
return 1.
|
||||
else:
|
||||
return 0.
|
||||
|
||||
|
||||
def fuzzy_match(result, rules) -> float:
|
||||
expect = rules["expected"]
|
||||
|
||||
return fuzz.ratio(result, expect) / 100.
|
||||
|
||||
|
||||
def _match_record(pattern: Dict[str, str], item: Dict[str, str]) -> float:
|
||||
return all(k in item and item[k]==val for k, val in pattern.items())
|
||||
return all(k in item and item[k] == val for k, val in pattern.items())
|
||||
|
||||
|
||||
def check_csv(result: str, rules: Dict[str, List[Dict[str, str]]]) -> float:
|
||||
"""
|
||||
@@ -41,6 +57,7 @@ def check_csv(result: str, rules: Dict[str, List[Dict[str, str]]]) -> float:
|
||||
unexpect_metric = unexpect_metric and not any(_match_record(r, rcd) for r in rules.get("unexpect", []))
|
||||
return float(all(expect_metrics) and unexpect_metric)
|
||||
|
||||
|
||||
def check_list(result: str, rules: Dict[str, List[str]]) -> float:
|
||||
"""
|
||||
Args:
|
||||
@@ -67,15 +84,18 @@ def check_list(result: str, rules: Dict[str, List[str]]) -> float:
|
||||
unexpect_metric = unexpect_metric and all(r.search(l) is None for r in unexpect_patterns)
|
||||
return float(all(expect_metrics) and unexpect_metric)
|
||||
|
||||
_accessibility_ns_map = { "st": "uri:deskat:state.at-spi.gnome.org"
|
||||
, "attr": "uri:deskat:attributes.at-spi.gnome.org"
|
||||
, "cp": "uri:deskat:component.at-spi.gnome.org"
|
||||
, "doc": "uri:deskat:document.at-spi.gnome.org"
|
||||
, "docattr": "uri:deskat:attributes.document.at-spi.gnome.org"
|
||||
, "txt": "uri:deskat:text.at-spi.gnome.org"
|
||||
, "val": "uri:deskat:value.at-spi.gnome.org"
|
||||
, "act": "uri:deskat:action.at-spi.gnome.org"
|
||||
}
|
||||
|
||||
_accessibility_ns_map = {"st": "uri:deskat:state.at-spi.gnome.org"
|
||||
, "attr": "uri:deskat:attributes.at-spi.gnome.org"
|
||||
, "cp": "uri:deskat:component.at-spi.gnome.org"
|
||||
, "doc": "uri:deskat:document.at-spi.gnome.org"
|
||||
, "docattr": "uri:deskat:attributes.document.at-spi.gnome.org"
|
||||
, "txt": "uri:deskat:text.at-spi.gnome.org"
|
||||
, "val": "uri:deskat:value.at-spi.gnome.org"
|
||||
, "act": "uri:deskat:action.at-spi.gnome.org"
|
||||
}
|
||||
|
||||
|
||||
def check_accessibility_tree(result: str, rules: Dict[str, Any]) -> float:
|
||||
"""
|
||||
Args:
|
||||
@@ -106,13 +126,13 @@ def check_accessibility_tree(result: str, rules: Dict[str, Any]) -> float:
|
||||
else:
|
||||
raise ValueError("At least one of xpath and selectors is required")
|
||||
|
||||
if len(elements)==0:
|
||||
if len(elements) == 0:
|
||||
return 0.
|
||||
|
||||
if "text" in rules:
|
||||
match_func: Callable[[str], Number] = functools.partial( operator.eq if rules["exact"] else fuzz.ratio
|
||||
, rules["text"]
|
||||
)
|
||||
match_func: Callable[[str], Number] = functools.partial(operator.eq if rules["exact"] else fuzz.ratio
|
||||
, rules["text"]
|
||||
)
|
||||
match_score: Number = 0
|
||||
for elm in elements:
|
||||
match_score = max(match_score, match_func(elm.text or None))
|
||||
@@ -121,5 +141,5 @@ def check_accessibility_tree(result: str, rules: Dict[str, Any]) -> float:
|
||||
|
||||
return float(match_score)
|
||||
|
||||
#def check_existence(result: str, *args) -> float:
|
||||
#return 1. - (result is None)
|
||||
# def check_existence(result: str, *args) -> float:
|
||||
# return 1. - (result is None)
|
||||
|
||||
Reference in New Issue
Block a user