-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b53ef5
commit 78c7e06
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from griptape.drivers import LocalFileManagerDriver | ||
from griptape.loaders import TextLoader | ||
|
||
loader = TextLoader(file_manager_driver=LocalFileManagerDriver()) | ||
|
||
data = loader.load("tests/resources/test.txt") | ||
|
||
data.value = data.value.replace("foo", "bar") | ||
|
||
loader.save("tests/resources/test.txt", data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import tempfile | ||
|
||
import pytest | ||
|
||
from griptape.loaders.text_loader import TextLoader | ||
|
||
|
||
class TestBaseFileLoader: | ||
@pytest.fixture(params=["ascii", "utf-8", None]) | ||
def loader(self, request): | ||
encoding = request.param | ||
if encoding is None: | ||
return TextLoader() | ||
else: | ||
return TextLoader(encoding=encoding) | ||
|
||
@pytest.fixture(params=["path_from_resource_path"]) | ||
def create_source(self, request): | ||
return request.getfixturevalue(request.param) | ||
|
||
def test_fetch(self, loader, create_source): | ||
source = create_source("test.txt") | ||
|
||
data = loader.fetch(source) | ||
|
||
assert data.startswith(b"foobar foobar foobar") | ||
|
||
def test_save(self, loader, create_source): | ||
source = create_source("test.txt") | ||
|
||
data = loader.load(source) | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
destination = create_source(f"{temp_dir}/test.txt") | ||
|
||
loader.save(destination, data) | ||
|
||
data_copy = loader.load(destination) | ||
|
||
assert data.value == data_copy.value |