2024-07-01 15:25:30 -06:00
|
|
|
# Copyright (c) 2024 Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License
|
|
|
|
"""Blob Storage Tests."""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from graphrag.index.storage.file_pipeline_storage import FilePipelineStorage
|
|
|
|
|
|
|
|
__dirname__ = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_find():
|
|
|
|
storage = FilePipelineStorage()
|
|
|
|
items = list(
|
|
|
|
storage.find(
|
2024-08-14 16:40:47 -06:00
|
|
|
base_dir="tests/fixtures/text/input",
|
2024-07-01 15:25:30 -06:00
|
|
|
file_pattern=re.compile(r".*\.txt$"),
|
|
|
|
progress=None,
|
|
|
|
file_filter=None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assert items == [(str(Path("tests/fixtures/text/input/dulce.txt")), {})]
|
|
|
|
output = await storage.get("tests/fixtures/text/input/dulce.txt")
|
|
|
|
assert len(output) > 0
|
|
|
|
|
|
|
|
await storage.set("test.txt", "Hello, World!", encoding="utf-8")
|
|
|
|
output = await storage.get("test.txt")
|
|
|
|
assert output == "Hello, World!"
|
|
|
|
await storage.delete("test.txt")
|
|
|
|
output = await storage.get("test.txt")
|
|
|
|
assert output is None
|
|
|
|
|
|
|
|
|
|
|
|
async def test_child():
|
|
|
|
storage = FilePipelineStorage()
|
2024-08-14 16:40:47 -06:00
|
|
|
storage = storage.child("tests/fixtures/text/input")
|
2024-07-01 15:25:30 -06:00
|
|
|
items = list(storage.find(re.compile(r".*\.txt$")))
|
2024-08-14 16:40:47 -06:00
|
|
|
assert items == [(str(Path("dulce.txt")), {})]
|
2024-07-01 15:25:30 -06:00
|
|
|
|
2024-08-14 16:40:47 -06:00
|
|
|
output = await storage.get("dulce.txt")
|
2024-07-01 15:25:30 -06:00
|
|
|
assert len(output) > 0
|
|
|
|
|
|
|
|
await storage.set("test.txt", "Hello, World!", encoding="utf-8")
|
|
|
|
output = await storage.get("test.txt")
|
|
|
|
assert output == "Hello, World!"
|
|
|
|
await storage.delete("test.txt")
|
|
|
|
output = await storage.get("test.txt")
|
|
|
|
assert output is None
|