-
Notifications
You must be signed in to change notification settings - Fork 19
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
4adcdca
commit 80a1fd0
Showing
2 changed files
with
63 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from mandr.storage import FileSystem | ||
from mandr.store import Store | ||
from mandr.store.store import MandrRootException | ||
|
||
|
||
class TestDefaultStorage: | ||
"""Test the behaviour of initialisation Mandr when `storage` is not given.""" | ||
|
||
def test_absolute_path(self, monkeypatch, tmp_path): | ||
"""If MANDR_ROOT is an absolute path, the storage is in MANDR_ROOT.""" | ||
monkeypatch.setenv("MANDR_ROOT", str(tmp_path)) | ||
|
||
store = Store("root/probabl") | ||
|
||
assert isinstance(store.storage, FileSystem) | ||
assert Path(store.storage.cache.directory) == tmp_path | ||
|
||
def test_relative_path(self, monkeypatch, tmp_path): | ||
"""If MANDR_ROOT is a relative path, we raise an error.""" | ||
monkeypatch.setattr("pathlib.Path.cwd", lambda: tmp_path) | ||
monkeypatch.setenv("MANDR_ROOT", ".not_datamander") | ||
|
||
with pytest.raises(MandrRootException, match="got '.not_datamander'"): | ||
Store("root/probabl") | ||
|
||
def test_relative_path_no_mandr_root(self, monkeypatch, tmp_path): | ||
"""If MANDR_ROOT is unset, the storage is in ".datamander", | ||
relative to the current working directory.""" | ||
monkeypatch.setattr("pathlib.Path.cwd", lambda: tmp_path) | ||
|
||
store = Store("root/probabl") | ||
|
||
assert isinstance(store.storage, FileSystem) | ||
assert Path(store.storage.cache.directory) == tmp_path / ".datamander" |