ver Jan18th
completed all the incomplete tasks stored under libreoffice_calc before added metric check_data_validations
This commit is contained in:
@@ -6,6 +6,7 @@ from urllib.parse import urlparse, urlunparse
|
||||
import re
|
||||
import functools
|
||||
import operator
|
||||
import builtins
|
||||
|
||||
import lxml.cssselect
|
||||
import lxml.etree
|
||||
@@ -15,6 +16,7 @@ from lxml.etree import _Element
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.chart._chart import ChartBase
|
||||
from openpyxl.worksheet.worksheet import Worksheet
|
||||
from openpyxl.worksheet.cell_range import MultiCellRange
|
||||
|
||||
V = TypeVar("Value")
|
||||
|
||||
@@ -138,6 +140,8 @@ def load_charts(xlsx_file: Workbook, **options) -> Dict[str, Any]:
|
||||
def _match_record(pattern: Dict[str, Any], item: Dict[str, Any]) -> bool:
|
||||
return all(k in item and item[k] == val for k, val in pattern.items())
|
||||
|
||||
def _multicellrange_containsby(subset_candidate: MultiCellRange, superset_candidate: MultiCellRange) -> bool:
|
||||
return all(r in superset_candidate for r in subset_candidate)
|
||||
def _match_value_to_rule(value: V, rule: Dict[str, Union[str, V]]) -> bool:
|
||||
"""
|
||||
Args:
|
||||
@@ -165,6 +169,23 @@ def _match_value_to_rule(value: V, rule: Dict[str, Union[str, V]]) -> bool:
|
||||
, "ge", "gt"
|
||||
}:
|
||||
return getattr(operator, rule["method"])(value, rule["ref"])
|
||||
if rule["method"] == "spreadsheet_range":
|
||||
subset_limit = MultiCellRange(rule["ref"][0])
|
||||
superset_limit = MultiCellRange(rule["ref"][1])
|
||||
return _multicellrange_containsby(subset_limit, value)\
|
||||
and _multicellrange_containsby(value, superset_limit)
|
||||
if rule["method"].startswith("range."): # e.g., range.te [0, 2] -> 0 < x <= 2
|
||||
left_et = rule["method"][6]
|
||||
right_et = rule["method"][7]
|
||||
return getattr(operator, "l" + left_et)(rule["ref"][0], value)\
|
||||
and getattr(operator, "l" + right_et)(value, rule["ref"][1])
|
||||
if rule["method"] in {"str_list_eq", "str_set_eq"}:
|
||||
container_type_str: str = rule["method"][4:-3]
|
||||
container_type = getattr(builtins, container_type_str)
|
||||
|
||||
value: container_type = container_type(value.strip("\"'").split(","))
|
||||
ref: container_type = container_type(rule["ref"])
|
||||
return value==ref
|
||||
raise NotImplementedError()
|
||||
|
||||
def are_lists_equal(list1, list2, comparison_func):
|
||||
|
||||
Reference in New Issue
Block a user