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
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
import pytest
|
|
from pathlib import Path
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
import sys
|
|
import types
|
|
|
|
from application.parser.file.html_parser import HTMLParser
|
|
|
|
|
|
@pytest.fixture
|
|
def html_parser():
|
|
return HTMLParser()
|
|
|
|
|
|
def test_html_init_parser():
|
|
parser = HTMLParser()
|
|
assert isinstance(parser._init_parser(), dict)
|
|
assert not parser.parser_config_set
|
|
parser.init_parser()
|
|
assert parser.parser_config_set
|
|
|
|
|
|
def test_html_parser_parse_file():
|
|
parser = HTMLParser()
|
|
mock_doc = MagicMock()
|
|
mock_doc.page_content = "Extracted HTML content"
|
|
mock_doc.metadata = {"source": "test.html"}
|
|
|
|
fake_lc = types.ModuleType("langchain_community")
|
|
fake_dl = types.ModuleType("langchain_community.document_loaders")
|
|
|
|
bshtml_mock = MagicMock(return_value=MagicMock(load=MagicMock(return_value=[mock_doc])))
|
|
fake_dl.BSHTMLLoader = bshtml_mock
|
|
fake_lc.document_loaders = fake_dl
|
|
|
|
with patch.dict(sys.modules, {
|
|
"langchain_community": fake_lc,
|
|
"langchain_community.document_loaders": fake_dl,
|
|
}):
|
|
result = parser.parse_file(Path("test.html"))
|
|
assert result == [mock_doc]
|
|
bshtml_mock.assert_called_once_with(Path("test.html"))
|