chore: import upstream snapshot with attribution
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Backend release / release (push) Has been cancelled
Bandit Security Scan / bandit_scan (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / manifest (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / manifest (push) Has been cancelled
Python linting / ruff (push) Has been cancelled
Run python tests with pytest / Run tests and count coverage (3.12) (push) Has been cancelled
React Widget Build / build (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Backend release / release (push) Has been cancelled
Bandit Security Scan / bandit_scan (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / manifest (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / manifest (push) Has been cancelled
Python linting / ruff (push) Has been cancelled
Run python tests with pytest / Run tests and count coverage (3.12) (push) Has been cancelled
React Widget Build / build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user