mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-03 22:13:01 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
import pytest
|
|
from pathlib import Path
|
|
from unittest.mock import patch, MagicMock
|
|
import sys
|
|
import types
|
|
|
|
from docsgpt.parser.file.epub_parser import EpubParser
|
|
|
|
|
|
@pytest.fixture
|
|
def epub_parser():
|
|
return EpubParser()
|
|
|
|
|
|
def test_epub_init_parser():
|
|
parser = EpubParser()
|
|
assert isinstance(parser._init_parser(), dict)
|
|
assert not parser.parser_config_set
|
|
parser.init_parser()
|
|
assert parser.parser_config_set
|
|
|
|
|
|
def test_epub_parser_fast_ebook_import_error(epub_parser):
|
|
"""Test that ImportError is raised when fast-ebook is not available."""
|
|
with patch.dict(sys.modules, {"fast_ebook": None}):
|
|
with pytest.raises(ValueError, match="`fast-ebook` is required to read Epub files"):
|
|
epub_parser.parse_file(Path("test.epub"))
|
|
|
|
|
|
def test_epub_parser_successful_parsing(epub_parser):
|
|
"""Test successful parsing of an epub file."""
|
|
fake_fast_ebook = types.ModuleType("fast_ebook")
|
|
fake_epub = types.ModuleType("fast_ebook.epub")
|
|
fake_fast_ebook.epub = fake_epub
|
|
|
|
mock_book = MagicMock()
|
|
mock_book.to_markdown.return_value = "# Chapter 1\n\nContent 1\n\n# Chapter 2\n\nContent 2\n"
|
|
|
|
fake_epub.read_epub = MagicMock(return_value=mock_book)
|
|
|
|
with patch.dict(sys.modules, {
|
|
"fast_ebook": fake_fast_ebook,
|
|
"fast_ebook.epub": fake_epub,
|
|
}):
|
|
result = epub_parser.parse_file(Path("test.epub"))
|
|
|
|
assert result == "# Chapter 1\n\nContent 1\n\n# Chapter 2\n\nContent 2\n"
|
|
fake_epub.read_epub.assert_called_once_with(Path("test.epub"))
|
|
|
|
|
|
def test_epub_parser_empty_book(epub_parser):
|
|
"""Test parsing an epub file with no content."""
|
|
fake_fast_ebook = types.ModuleType("fast_ebook")
|
|
fake_epub = types.ModuleType("fast_ebook.epub")
|
|
fake_fast_ebook.epub = fake_epub
|
|
|
|
mock_book = MagicMock()
|
|
mock_book.to_markdown.return_value = ""
|
|
|
|
fake_epub.read_epub = MagicMock(return_value=mock_book)
|
|
|
|
with patch.dict(sys.modules, {
|
|
"fast_ebook": fake_fast_ebook,
|
|
"fast_ebook.epub": fake_epub,
|
|
}):
|
|
result = epub_parser.parse_file(Path("empty.epub"))
|
|
|
|
assert result == ""
|