Add test condition for every dir possible
Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
parent
e500c775d4
commit
69151619f7
|
@ -15,18 +15,40 @@ class RepoDirStructure():
|
|||
self._repos_dir = os.path.join(self._base_dir, "repos")
|
||||
|
||||
@property
|
||||
def exists(self) -> bool:
|
||||
def base_dir_exists(self):
|
||||
if not os.path.isdir(self._base_dir):
|
||||
raise DirNotFoundError(self._base_dir)
|
||||
return True
|
||||
|
||||
@property
|
||||
def conf_dir_exists(self):
|
||||
if not os.path.isdir(self._conf_dir):
|
||||
raise DirNotFoundError(self._conf_dir)
|
||||
return True
|
||||
|
||||
@property
|
||||
def cache_dir_exists(self):
|
||||
if not os.path.isdir(self._cache_dir):
|
||||
raise DirNotFoundError(self._cache_dir)
|
||||
return True
|
||||
|
||||
@property
|
||||
def repos_dir_exists(self):
|
||||
if not os.path.isdir(self._repos_dir):
|
||||
raise DirNotFoundError(self._repos_dir)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def dirs_exist(self) -> bool:
|
||||
return all(
|
||||
[
|
||||
self.base_dir_exists,
|
||||
self.conf_dir_exists,
|
||||
self.cache_dir_exists,
|
||||
self.repos_dir_exists,
|
||||
]
|
||||
)
|
||||
|
||||
@property
|
||||
def base_dir(self) -> str:
|
||||
return self._base_dir
|
||||
|
|
|
@ -18,7 +18,7 @@ def test_no_base_dir(tmp_path: PosixPath):
|
|||
x = tmp_path.joinpath("nonexistent")
|
||||
X = RepoDirStructure(x)
|
||||
with pytest.raises(DirNotFoundError) as excinfo:
|
||||
X.exists
|
||||
X.base_dir_exists
|
||||
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
|
||||
assert excinfo.exconly().endswith("/nonexistent")
|
||||
|
||||
|
@ -26,7 +26,7 @@ def test_no_base_dir(tmp_path: PosixPath):
|
|||
def test_no_config(tmp_path: PosixPath):
|
||||
X = RepoDirStructure(tmp_path)
|
||||
with pytest.raises(DirNotFoundError) as excinfo:
|
||||
X.exists
|
||||
X.conf_dir_exists
|
||||
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
|
||||
assert excinfo.exconly().endswith("/config")
|
||||
|
||||
|
@ -35,7 +35,7 @@ def test_no_cache(tmp_path: PosixPath):
|
|||
tmp_path.joinpath("config").mkdir()
|
||||
X = RepoDirStructure(tmp_path)
|
||||
with pytest.raises(DirNotFoundError) as excinfo:
|
||||
X.exists
|
||||
X.cache_dir_exists
|
||||
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
|
||||
assert excinfo.exconly().endswith("/cache")
|
||||
|
||||
|
@ -45,17 +45,22 @@ def test_no_repos(tmp_path: PosixPath):
|
|||
tmp_path.joinpath("cache").mkdir()
|
||||
X = RepoDirStructure(tmp_path)
|
||||
with pytest.raises(DirNotFoundError) as excinfo:
|
||||
X.exists
|
||||
X.repos_dir_exists
|
||||
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
|
||||
assert excinfo.exconly().endswith("/repos")
|
||||
|
||||
|
||||
def test_exists_okay(tmp_path: PosixPath):
|
||||
def test_dirs_exist_okay(tmp_path: PosixPath):
|
||||
tmp_path.joinpath("config").mkdir()
|
||||
tmp_path.joinpath("cache").mkdir()
|
||||
tmp_path.joinpath("repos").mkdir()
|
||||
|
||||
X = RepoDirStructure(tmp_path)
|
||||
assert True == X.exists
|
||||
assert X.base_dir_exists
|
||||
assert X.conf_dir_exists
|
||||
assert X.cache_dir_exists
|
||||
assert X.repos_dir_exists
|
||||
assert X.dirs_exist
|
||||
|
||||
|
||||
def test_base_dir():
|
||||
|
|
Loading…
Reference in New Issue
Block a user