refactor: 调整模块导入路径,简化引用结构
- 更新 openspec/config.yaml 中 git 任务相关说明 - 将 scripts.core.* 改为 core.*,scripts.readers.* 改为 readers.* - 优化 lyxy_document_reader.py 中 sys.path 设置方式 - 同步更新所有测试文件的导入路径
This commit is contained in:
@@ -1 +1,12 @@
|
||||
"""Tests package for lyxy-document."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 将 scripts/ 目录添加到 sys.path
|
||||
project_root = Path(__file__).resolve().parent.parent
|
||||
scripts_dir = project_root / "scripts"
|
||||
if str(scripts_dir) not in sys.path:
|
||||
sys.path.insert(0, str(scripts_dir))
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
"""测试配置和共享 fixtures。"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 将 scripts/ 目录添加到 sys.path(必须在最顶部,在其他导入之前)
|
||||
project_root = Path(__file__).resolve().parent.parent # tests/ 的父目录是项目根目录
|
||||
scripts_dir = project_root / "scripts"
|
||||
if str(scripts_dir) not in sys.path:
|
||||
sys.path.insert(0, str(scripts_dir))
|
||||
|
||||
import pytest
|
||||
from scripts.readers import READERS
|
||||
from readers import READERS
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from io import StringIO
|
||||
from contextlib import redirect_stdout, redirect_stderr
|
||||
|
||||
@@ -22,7 +23,13 @@ def cli_runner():
|
||||
Returns:
|
||||
tuple: (stdout, stderr, exit_code)
|
||||
"""
|
||||
from scripts.lyxy_document_reader import main
|
||||
# 将 scripts/ 目录添加到 sys.path
|
||||
project_root = Path(__file__).resolve().parent.parent.parent # tests/test_cli/ 的父目录是 tests/,再父目录是项目根目录
|
||||
scripts_dir = project_root / "scripts"
|
||||
if str(scripts_dir) not in sys.path:
|
||||
sys.path.insert(0, str(scripts_dir))
|
||||
|
||||
from lyxy_document_reader import main
|
||||
|
||||
# 保存原始 sys.argv 和 sys.exit
|
||||
original_argv = sys.argv
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""测试 Markdown 工具函数。"""
|
||||
|
||||
from scripts.core import (
|
||||
from core import (
|
||||
get_heading_level,
|
||||
extract_titles,
|
||||
normalize_markdown_whitespace,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试所有 DOCX Readers 的一致性。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.docx import (
|
||||
from readers.docx import (
|
||||
docling,
|
||||
unstructured,
|
||||
pypandoc,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.docx import docling
|
||||
from readers.docx import docling
|
||||
|
||||
|
||||
class TestDoclingDocxReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.docx import markitdown
|
||||
from readers.docx import markitdown
|
||||
|
||||
|
||||
class TestMarkitdownDocxReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.docx import native_xml
|
||||
from readers.docx import native_xml
|
||||
|
||||
|
||||
class TestNativeXmlDocxReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.docx import pypandoc
|
||||
from readers.docx import pypandoc
|
||||
|
||||
|
||||
class TestPypandocDocxReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.docx import DocxReader
|
||||
from readers.docx import DocxReader
|
||||
|
||||
|
||||
class TestPythonDocxReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.docx import unstructured
|
||||
from readers.docx import unstructured
|
||||
|
||||
|
||||
class TestUnstructuredDocxReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试所有 HTML Readers 的一致性。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.html import (
|
||||
from readers.html import (
|
||||
html2text,
|
||||
markitdown,
|
||||
trafilatura,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Domscribe HTML Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.html import domscribe
|
||||
from readers.html import domscribe
|
||||
|
||||
|
||||
class TestDomscribeHtmlReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.html import HtmlReader
|
||||
from readers.html import HtmlReader
|
||||
|
||||
|
||||
class TestHtml2TextReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 MarkItDown HTML Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.html import markitdown
|
||||
from readers.html import markitdown
|
||||
|
||||
|
||||
class TestMarkitdownHtmlReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Trafilatura HTML Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.html import trafilatura
|
||||
from readers.html import trafilatura
|
||||
|
||||
|
||||
class TestTrafilaturaHtmlReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试所有 PDF Readers 的一致性。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pdf import (
|
||||
from readers.pdf import (
|
||||
docling,
|
||||
docling_ocr,
|
||||
markitdown,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Docling OCR PDF Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pdf import docling_ocr
|
||||
from readers.pdf import docling_ocr
|
||||
|
||||
|
||||
class TestDoclingOcrPdfReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Docling PDF Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pdf import docling
|
||||
from readers.pdf import docling
|
||||
|
||||
|
||||
class TestDoclingPdfReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 MarkItDown PDF Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pdf import markitdown
|
||||
from readers.pdf import markitdown
|
||||
|
||||
|
||||
class TestMarkitdownPdfReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.pdf import PdfReader
|
||||
from readers.pdf import PdfReader
|
||||
|
||||
|
||||
class TestPypdfReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Unstructured OCR PDF Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pdf import unstructured_ocr
|
||||
from readers.pdf import unstructured_ocr
|
||||
|
||||
|
||||
class TestUnstructuredOcrPdfReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Unstructured PDF Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pdf import unstructured
|
||||
from readers.pdf import unstructured
|
||||
|
||||
|
||||
class TestUnstructuredPdfReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试所有 PPTX Readers 的一致性。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pptx import (
|
||||
from readers.pptx import (
|
||||
docling,
|
||||
markitdown,
|
||||
native_xml,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Docling PPTX Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pptx import docling
|
||||
from readers.pptx import docling
|
||||
|
||||
|
||||
class TestDoclingPptxReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 MarkItDown PPTX Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pptx import markitdown
|
||||
from readers.pptx import markitdown
|
||||
|
||||
|
||||
class TestMarkitdownPptxReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Native XML PPTX Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pptx import native_xml
|
||||
from readers.pptx import native_xml
|
||||
|
||||
|
||||
class TestNativeXmlPptxReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.pptx import PptxReader
|
||||
from readers.pptx import PptxReader
|
||||
|
||||
|
||||
class TestPythonPptxReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Unstructured PPTX Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.pptx import unstructured
|
||||
from readers.pptx import unstructured
|
||||
|
||||
|
||||
class TestUnstructuredPptxReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import zipfile
|
||||
import pytest
|
||||
from scripts.readers._utils import (
|
||||
from readers._utils import (
|
||||
parse_via_markitdown,
|
||||
parse_via_docling,
|
||||
build_markdown_table,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试所有 XLSX Readers 的一致性。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.xlsx import (
|
||||
from readers.xlsx import (
|
||||
docling,
|
||||
markitdown,
|
||||
native_xml,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Docling XLSX Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.xlsx import docling
|
||||
from readers.xlsx import docling
|
||||
|
||||
|
||||
class TestDoclingXlsxReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 MarkItDown XLSX Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.xlsx import markitdown
|
||||
from readers.xlsx import markitdown
|
||||
|
||||
|
||||
class TestMarkitdownXlsxReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Native XML XLSX Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.xlsx import native_xml
|
||||
from readers.xlsx import native_xml
|
||||
|
||||
|
||||
class TestNativeXmlXlsxReaderParse:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts.readers.xlsx import XlsxReader
|
||||
from readers.xlsx import XlsxReader
|
||||
|
||||
|
||||
class TestPandasXlsxReaderParse:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""测试 Unstructured XLSX Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
from scripts.readers.xlsx import unstructured
|
||||
from readers.xlsx import unstructured
|
||||
|
||||
|
||||
class TestUnstructuredXlsxReaderParse:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""测试文件检测工具函数。"""
|
||||
|
||||
from scripts.utils import is_url, is_html_file
|
||||
from utils import is_url, is_html_file
|
||||
|
||||
|
||||
class TestIsUrl:
|
||||
|
||||
Reference in New Issue
Block a user