This commit is contained in:
rhythmcao
2024-03-02 21:09:37 +08:00
7 changed files with 316 additions and 16 deletions

View File

@@ -13,6 +13,7 @@ from odf.text import P
from odf.text import Span
from skimage.color import deltaE_ciede2000
from skimage.color import rgb2lab
from fuzzywuzzy import fuzz
logger = logging.getLogger("desktopenv.metric.docs")
@@ -57,6 +58,8 @@ def contains_page_break(docx_file):
def compare_docx_files(file1, file2, **options):
ignore_blanks = options.get('ignore_blanks', True)
content_only = options.get('content_only', False)
def get_paragraph_texts_odt(document):
paragraphs = document.getElementsByType(P)
paragraph_texts = []
@@ -89,6 +92,13 @@ def compare_docx_files(file1, file2, **options):
print("Unsupported file types or mismatch between file types.")
return 0
if content_only:
# Compare the content of the documents
text1 = re.sub(r'\s+', ' ', '\n'.join(doc1_paragraphs)).strip()
text2 = re.sub(r'\s+', ' ', '\n'.join(doc2_paragraphs)).strip()
similarity = fuzz.ratio(text1, text2) / 100.0
return similarity
# Process and compare documents
if ignore_blanks:
text1 = re.sub(r'\s+', ' ', '\n'.join(doc1_paragraphs)).strip()

View File

@@ -1,5 +1,7 @@
import copy
import json
from typing import Dict
import json, copy
def check_json_keybindings(actual: str, expected: str, **options) -> float:
"""
@@ -10,6 +12,7 @@ def check_json_keybindings(actual: str, expected: str, **options) -> float:
Return:
float: the score
"""
def direct_load_json(fp):
try:
with open(fp, 'r') as f:
@@ -17,7 +20,7 @@ def check_json_keybindings(actual: str, expected: str, **options) -> float:
return data
except:
return None
def skip_first_line_load_json(fp):
try:
with open(fp, 'r') as f:
@@ -54,7 +57,7 @@ def check_json_settings(actual: str, expected: str, **options) -> float:
with open(actual, 'r') as f:
data = json.load(f)
expect = expected['expected']
data_copy = copy.deepcopy(data)
data_copy.update(expect)
@@ -128,3 +131,11 @@ def is_extension_installed(actual: str, rules: Dict, **options):
return 0.0
else:
raise NotImplementedError
def check_python_file_by_test_suite(actual_file, test_suites, **options) -> float:
pass
def check_python_file_by_gold_file(actual_file, gold_file: str, **options) -> float:
pass