fix some vscode eval problems
This commit is contained in:
@@ -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