Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ output/
coverage.xml

llm_web_kit.egg-info/*
.llm-web-kit.jsonc
3 changes: 3 additions & 0 deletions llm_web_kit/input/datajson.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def to_json(self, pretty=False) -> str:
else:
return json.dumps(content_lst, ensure_ascii=False)

def to_dict(self) -> dict:
return copy.deepcopy(self._get_data())

@abstractmethod
def _get_data(self) -> List[Dict]:
raise NotImplementedError('This method must be implemented by the subclass.')
Expand Down
10 changes: 8 additions & 2 deletions tests/llm_web_kit/libs/test_standard_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def test_json_loads(input: Union[str, bytes], target_dict) -> None:
'0': 'aaa',
'1': 'bbb',
'2': 'ccc'
}, '''{"0": "aaa", "1": "bbb", "2": "ccc"}'''),
}, '''{"0":"aaa","1":"bbb","2":"ccc"}'''),
({
'track_id': '7c5b99d3',
'warc_record_offset': 65390694,
'warc_record_length': '16190',
'layout_id': 0
}, '{"track_id": "7c5b99d3", "warc_record_offset": 65390694, "warc_record_length": "16190", "layout_id": 0}'),
}, '{"track_id":"7c5b99d3","warc_record_offset":65390694,"warc_record_length":"16190","layout_id":0}'),
])
def test_json_dumps(input_dict: dict, target_str) -> None:
"""
Expand All @@ -66,4 +66,10 @@ def test_json_dumps(input_dict: dict, target_str) -> None:
Returns: None

"""
expected_obj = json_loads(target_str)
# 比较两个对象是否相等
for key, value in input_dict.items():
assert expected_obj[key] == value

# 比较json_dumps的输出是否与target_str相等
assert target_str == json_dumps(input_dict)
Loading