ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

如何用 Azurite 在本地运行 GraphRAG 的 Azure 存储相关测试?

如何用 Azurite 在本地运行 GraphRAG 的 Azure 存储相关测试? 如何用 Azurite 在本地运行 GraphRAG 的 Azure 存储相关测试【免费下载链接】graphragA modular graph-based Retrieval-Augmented Generation (RAG) system项目地址: https://gitcode.com/GitHub_Trending/gr/graphragGraphRAG 是一个模块化的基于知识图谱的 RAGRetrieval-Augmented Generation系统。它的部分测试依赖 Azurite 这个 Azure 资源模拟器如果你要在本地复现涉及 Azure Blob Storage 的集成测试或者想跑使用 Azurite 的 smoke 测试套件就需要先在本地把 Azurite 启动起来让测试代码通过http://127.0.0.1:10000访问本地 Blob 端点而不是真实的 Azure 账户。这篇文章基于仓库内的 docs/developing.md 和测试代码给出从安装依赖、启动 Azurite 到运行测试并判断结果的完整路径。准备条件docs/developing.md 列出的开发环境要求Python 3.10-3.12uv用于包管理和虚拟环境管理。安装依赖# install python dependencies uv sync --all-packages如果你在安装依赖时遇到uv sync报错DEVELOPING.md 的 Troubleshooting 一节给出了两类已知问题的处理方式需要系统包安装权限属于 Linux/apt 环境下的可选修复步骤RuntimeError: llvm-config failed executing, please point LLVM_CONFIG to the path for llvm-config确认安装了llvm-9和llvm-9-devsudo apt-get install llvm-9 llvm-9-dev并在 bashrc 中加export LLVM_CONFIG/usr/bin/llvm-config-9numba/_pymodule.h:6:10: fatal error: Python.h: No such file or directory安装python3.10-dev或更通用的pythonversion-dev。如果后续需要跑 smoke 测试它还依赖 Node.js 环境提供的npx这一点由启动脚本本身决定见下一节。启动 Azuritedocs/developing.md 明确说明Some unit and smoke tests use Azurite to emulate Azure resources. 启动方式有两种运行仓库自带的脚本./scripts/start-azurite.sh如果已经全局安装了 Azurite也可以直接在终端运行azurite。脚本 scripts/start-azurite.sh 的全部内容只有一行#!/bin/sh npx --yes azurite -L -l ./temp_azurite -d ./temp_azurite/debug.log也就是说它通过npx --yes拉取并运行 azurite 包前提是机器上有 Node.js 环境副作用是在当前目录下创建./temp_azurite文件夹Azurite 的本地数据和debug.log调试日志都写在这里。脚本本身不终止任何进程、不删除文件CtrlC 即可停止 Azurite。测试代码中使用的正是 Azurite 的well-known开发账户连接串例如 tests/integration/storage/test_blob_storage.pyWELL_KNOWN_BLOB_STORAGE_KEY DefaultEndpointsProtocolhttp;AccountNamedevstoreaccount1;AccountKeyEby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw;BlobEndpointhttp://127.0.0.1:10000/devstoreaccount1;其中BlobEndpointhttp://127.0.0.1:10000/devstoreaccount1表明测试连的是本地端口 10000 上的 Azurite Blob 服务——这正是必须先启动 Azurite的原因。运行 Azure Blob 存储集成测试与 Azurite 直接相关的测试在 tests/integration/storage/test_blob_storage.py 中包含三个用例test_find在名为testfind的容器里写入input/christmas.txt和test.txt用正则.*\.txt$调find验证列出的对象再get读取内容、delete删除后确认读回为Nonetest_get_creation_date写入对象后取创建时间按%Y-%m-%d %H:%M:%S %z格式解析并做往返断言test_child通过parent.child(input)获取子路径存储验证子路径读写在父路径视角下呈现为input/...前缀。每个用例的finally里都会调用storage._delete_container()清理容器测试只读写本地 Azurite 实例不碰真实 Azure 资源。在仓库根目录执行docs/developing.md 中uv run poe test_integration即等价于pytest ./tests/integration这里用-k缩小到 Blob 相关测试uv run pytest ./tests/integration/storage/test_blob_storage.py预期结果是 pytest 报出 3 个用例全部PASSED。如果 Azurite 没启动测试会在连接127.0.0.1:10000时失败这时先确认 Azurite 进程还在、再看./temp_azurite/debug.log。跑使用 Azurite 的 smoke 测试smoke 测试入口在 tests/smoke/test_fixtures.py。它会遍历tests/fixtures/下的各个 fixture 目录其中 tests/fixtures/azure/config.json 是 Azure 场景{ input_path: ./tests/fixtures/azure, input_type: text, index_method: standard, workflow_config: { skip_assert: true, azure: { input_container: azurefixture, input_base_dir: input } }, query_config: [], slow: false }当 fixture 配置里带有azure字段时prepare_azurite_data会先把 tests/fixtures/azure/input 下的.txt/.csv文件上传到 Azurite 的azurefixture容器并重建容器以清掉上次运行留下的数据然后用BLOB_STORAGE_CONNECTION_STRING和LOCAL_BLOB_STORAGE_CONNECTION_STRING都指向127.0.0.1:10000的环境变量运行uv run poe index。注意该 fixture 设置了skip_assert: true即只验证 indexer 进程返回码为 0不做输出产物断言测试结束后会删除azurefixture容器。执行方式uv run pytest ./tests/smoke由于 smoke 套件中的 azure fixture 会真实调用 LLM 完成索引其余 fixture 如 tests/fixtures/min-csv/config.json、tests/fixtures/text/config.json 也都需要 LLM运行前需要具备 docs/config/models.md 所述的模型凭据且耗时取决于模型调用。如果你只想复现 Azure 存储这条链路也可以先用上一节的集成测试验证 Azurite 本身工作正常。已知限制与边界tests/integration/storage/test_factory.py 里的test_create_blob_storage带有pytest.mark.skip(reasonBlob storage emulator is not available in this environment)在当前环境是跳过的而test_create_cosmosdb_storage通过skipif(not sys.platform.startswith(win))限制为只在 Windows 运行器上执行注释说明 Cosmos DB emulator 目前只在 Windows runners 可用。也就是说 Cosmos 存储测试不能作为本地 Linux/macOS 验证 Azurite 的路径。上文出现的devstoreaccount1账户名、AccountKey 和127.0.0.1:10000端点是 Azurite 的 well-known 开发凭据仅对本地模拟器有效不要指向真实 Azure 资源。文档之间的细节存在一处不一致docs/developing.md 写的是uv sync --all-packages、Python 3.10-3.12而根目录 DEVELOPING.md 写的是uv sync、Python 3.10 or 3.11。仓库是 monorepo 结构packages/下多个包本地开发以uv sync --all-packages为准更稳妥。Azurite 跑通后验证方式就是集成测试全绿、smoke 测试中 azure fixture 的 indexer 返回码为 0两者都只依赖本地127.0.0.1的模拟器端点。【免费下载链接】graphragA modular graph-based Retrieval-Augmented Generation (RAG) system项目地址: https://gitcode.com/GitHub_Trending/gr/graphrag创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表