Skip to content

Commit

Permalink
Add more tests and support for subdirectory writing
Browse files Browse the repository at this point in the history
  • Loading branch information
abegong committed Aug 13, 2019
1 parent d5ae4db commit 2f4b13e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions great_expectations/data_context/store/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ def __init__(

self.path = path
safe_mmkdir(os.path.dirname(self.path))
print(self.path)

def _get(self, key):
with open(os.path.join(self.path, key)) as infile:
return infile.read()

def _set(self, key, value):
with open(os.path.join(self.path, key), "w") as outfile:
filename = os.path.join(self.path, key)
safe_mmkdir(os.path.split(filename)[0])
with open(filename, "w") as outfile:
outfile.write(value)

class S3Store(Store):
Expand Down
15 changes: 12 additions & 3 deletions tests/data_context/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ def test_InMemoryStore_with_serialization():
my_store.set("AAA", {"x":1})
assert my_store.get("AAA") == {"x":1}

my_store = InMemoryStore()
with pytest.raises(TypeError):
my_store.set("BBB", set(["x", "y", "z"]), serialization_type="json")

#??? Should putting a non-string, non-byte object into a store trigger an error?
# with pytest.raises(ValueError):
# my_store.set("AAA", {"x":1})

# my_store.set("CCC", {"x":1})

my_store = InMemoryStore()

with pytest.raises(KeyError):
assert my_store.get("AAA") == {"x":1}

Expand All @@ -40,6 +43,9 @@ def test_InMemoryStore_with_serialization():
assert my_store.get("AAA") == "{\"x\": 1}"
assert my_store.get("AAA", serialization_type="json") == {"x":1}

with pytest.raises(TypeError):
my_store.set("BBB", set(["x", "y", "z"]), serialization_type="json")

def test_FilesystemStore(tmp_path):
my_store = FilesystemStore(**{
"path": tmp_path
Expand All @@ -51,3 +57,6 @@ def test_FilesystemStore(tmp_path):

my_store.set("my_file_AAA", "aaa")
assert my_store.get("my_file_AAA") == "aaa"

my_store.set("subdir/my_file_BBB", "bbb")
assert my_store.get("subdir/my_file_BBB") == "bbb"

0 comments on commit 2f4b13e

Please sign in to comment.