fix some vscode eval problems
This commit is contained in:
@@ -16,7 +16,7 @@ from .vlc import is_vlc_playing, is_vlc_recordings_folder, is_vlc_fullscreen, co
|
||||
from .gimp import increase_saturation, decrease_brightness, check_file_exists, compare_triangle_positions
|
||||
from .general import check_csv, check_accessibility_tree, check_list, run_sqlite3, check_json
|
||||
from .thunderbird import check_thunderbird_prefs, check_thunderbird_filter
|
||||
from .vscode import compare_text_file, compare_config, compare_answer, is_extension_installed
|
||||
from .vscode import compare_text_file, compare_config, compare_answer, is_extension_installed, check_json_settings, check_json_keybindings
|
||||
from .impress import check_image_stretch_and_center, check_slide_numbers_color, compare_pptx_files, check_strikethrough, \
|
||||
check_for_audio, check_formula_shape
|
||||
from .impress import check_slide_orientation_Portrait, contains_mp4_video
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from typing import Dict
|
||||
import json
|
||||
import json, copy
|
||||
|
||||
def check_json_keybindings(actual: str, expected: str, **options) -> float:
|
||||
"""
|
||||
@@ -10,36 +10,58 @@ 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:
|
||||
data = json.load(f)
|
||||
return data
|
||||
except:
|
||||
return None
|
||||
|
||||
def skip_first_line_load_json(fp):
|
||||
try:
|
||||
with open(fp, 'r') as f:
|
||||
f.readline()
|
||||
data = json.load(f)
|
||||
return data
|
||||
except:
|
||||
return None
|
||||
|
||||
with open(actual) as f:
|
||||
data = json.load(f)
|
||||
|
||||
for func in [direct_load_json, skip_first_line_load_json]:
|
||||
data = func(actual)
|
||||
if data is not None and type(data) == list:
|
||||
break
|
||||
else:
|
||||
return 0.0
|
||||
expected = expected['expect']
|
||||
if expected in data:
|
||||
return 1.0
|
||||
else:
|
||||
return 0.0
|
||||
|
||||
|
||||
def check_json_settings(actual: str, expected: str, **options) -> float:
|
||||
"""
|
||||
Args:
|
||||
actual (str): path to result text file
|
||||
expected (str): expected dict{}
|
||||
expected (dict): expected dict{}, containing key "expect"
|
||||
|
||||
Return:
|
||||
float: the score
|
||||
"""
|
||||
|
||||
with open(actual) as f:
|
||||
with open(actual, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
expect = set(expected.items())
|
||||
json = set(data.items())
|
||||
|
||||
if expect.issubset(json):
|
||||
|
||||
expect = expected['expect']
|
||||
data_copy = copy.deepcopy(data)
|
||||
data_copy.update(expect)
|
||||
if data == data_copy:
|
||||
return 1.0
|
||||
else:
|
||||
return 0.0
|
||||
|
||||
|
||||
def compare_text_file(actual: str, expected: str, **options) -> float:
|
||||
"""
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user