Files
wehub-resource-sync fed8b2eed7
Backend release / release (push) Waiting to run
Bandit Security Scan / bandit_scan (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / manifest (push) Blocked by required conditions
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / manifest (push) Blocked by required conditions
Python linting / ruff (push) Waiting to run
Run python tests with pytest / Run tests and count coverage (3.12) (push) Waiting to run
React Widget Build / build (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:28:29 +08:00

50 lines
1.6 KiB
Python

from pathlib import Path
from unittest.mock import patch, mock_open
from application.parser.file.json_parser import JSONParser
def test_json_init_parser():
parser = JSONParser()
assert isinstance(parser._init_parser(), dict)
assert not parser.parser_config_set
parser.init_parser()
assert parser.parser_config_set
def test_json_parser_parses_dict_concat():
parser = JSONParser()
with patch("builtins.open", mock_open(read_data="{}")):
with patch("json.load", return_value={"a": 1}):
result = parser.parse_file(Path("t.json"))
assert result == "{'a': 1}"
def test_json_parser_parses_list_no_concat():
parser = JSONParser()
parser._concat_rows = False
data = [{"a": 1}, {"b": 2}]
with patch("builtins.open", mock_open(read_data="[]")):
with patch("json.load", return_value=data):
result = parser.parse_file(Path("t.json"))
assert result == data
def test_json_parser_row_joiner_config():
parser = JSONParser(row_joiner=" || ")
with patch("builtins.open", mock_open(read_data="[]")):
with patch("json.load", return_value=[{"a": 1}, {"b": 2}]):
result = parser.parse_file(Path("t.json"))
assert result == "{'a': 1} || {'b': 2}"
def test_json_parser_forwards_json_config():
def pf(s):
return 1.23
parser = JSONParser(json_config={"parse_float": pf})
with patch("builtins.open", mock_open(read_data="[]")):
with patch("json.load", return_value=[]) as mock_load:
parser.parse_file(Path("t.json"))
assert mock_load.call_args.kwargs.get("parse_float") is pf