mirror of
https://github.com/hwchase17/langchain.git
synced 2025-10-01 08:35:56 +00:00
Add PythonLoader which auto-detects encoding of Python files (#3311)
This PR contributes a `PythonLoader`, which inherits from `TextLoader` but detects and sets the encoding automatically.
This commit is contained in:
19
tests/integration_tests/document_loaders/test_python.py
Normal file
19
tests/integration_tests/document_loaders/test_python.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from langchain.document_loaders.python import PythonLoader
|
||||
|
||||
|
||||
@pytest.mark.parametrize("filename", ["default-encoding.py", "non-utf8-encoding.py"])
|
||||
def test_python_loader(filename: str) -> None:
|
||||
"""Test Python loader."""
|
||||
file_path = Path(__file__).parent.parent / "examples" / filename
|
||||
loader = PythonLoader(str(file_path))
|
||||
docs = loader.load()
|
||||
|
||||
assert len(docs) == 1
|
||||
|
||||
metadata = docs[0].metadata
|
||||
|
||||
assert metadata["source"] == str(file_path)
|
Reference in New Issue
Block a user