def test_ensure_existing_dir(tmp_path): """should ensure dir exists""" not_exist = tmp_path / "i_dont_exist" file = tmp_path / "file.txt" file.touch() with pytest.raises(NotADirectoryError): utils.ensure_existing_dir(not_exist) with pytest.raises(NotADirectoryError): utils.ensure_existing_dir(file) result = utils.ensure_existing_dir(str(tmp_path)) assert result == tmp_path assert result.exists() assert result.is_dir()
def get_source(location, **kwargs): """Factory for StubSource Instance Args: location (str): PathLike object or valid URL Returns: obj: Either Local or Remote StubSource Instance """ try: utils.ensure_existing_dir(location) except NotADirectoryError: return RemoteStubSource(location, **kwargs) else: return LocalStubSource(location, **kwargs)
def __init__(self, path, **kwargs): location = utils.ensure_existing_dir(path) return super().__init__(location, **kwargs)