Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config error handling updates #74

Merged
merged 17 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
markers =
no_setup_config_file_fs: mark test to not use setup_config_file_fs fixture
115 changes: 93 additions & 22 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,87 @@ def setup_tmp_local(tmp_path: Path):
yield [local_root, local_empty_root]


@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(scope="function")
def no_config_permission(tmp_path: Path):
config_dir = tmp_path / "config"
config_dir.mkdir(exist_ok=True)
os.chmod(config_dir, 0o44)

with patch(
"jupyter_fsspec.file_manager.jupyter_config_dir", return_value=str(config_dir)
):
print(f"Patching jupyter_config_dir to: {config_dir}")
yield config_dir

os.chmod(config_dir, 0o755)
config_dir.rmdir()


@pytest.fixture(scope="function")
def malformed_config(tmp_path: Path):
config_dir = tmp_path / "config"
config_dir.mkdir(exist_ok=True)

yaml_content = f"""sources:
- name: "TestSourceAWS"
path: "s3://my-test-bucket/"
kwargs:
anon: false
key: "my-access-key"
secret: "my-secret-key"
client_kwargs:
endpoint_url: "{ENDPOINT_URI}"
"""
yaml_file = config_dir / "jupyter-fsspec.yaml"
yaml_file.write_text(yaml_content)

with patch(
"jupyter_fsspec.file_manager.jupyter_config_dir", return_value=str(config_dir)
):
print(f"Patching jupyter_config_dir to: {config_dir}")


@pytest.fixture(scope="function")
def bad_info_config(tmp_path: Path):
config_dir = tmp_path / "config"
config_dir.mkdir(exist_ok=True)

yaml_content = f"""sources:
- nme: "TestSourceAWS"
path: s3://my-test-bucket/"
kwargs:
anon: false
key: "my-access-key"
secret: "my-secret-key"
client_kwargs:
endpoint_url: "{ENDPOINT_URI}"
"""
yaml_file = config_dir / "jupyter-fsspec.yaml"
yaml_file.write_text(yaml_content)

with patch(
"jupyter_fsspec.file_manager.jupyter_config_dir", return_value=str(config_dir)
):
print(f"Patching jupyter_config_dir to: {config_dir}")


@pytest.fixture(scope="function")
def empty_config(tmp_path: Path):
config_dir = tmp_path / "config"
config_dir.mkdir(exist_ok=True)

yaml_content = """ """
yaml_file = config_dir / "jupyter-fsspec.yaml"
yaml_file.write_text(yaml_content)

with patch(
"jupyter_fsspec.file_manager.jupyter_config_dir", return_value=str(config_dir)
):
print(f"Patching jupyter_config_dir to: {config_dir}")


# TODO: split?
@pytest.fixture(scope="function")
def setup_config_file_fs(tmp_path: Path, setup_tmp_local):
tmp_local = setup_tmp_local[0]
items_tmp_local = list(tmp_local.iterdir())
Expand Down Expand Up @@ -76,36 +156,27 @@ def setup_config_file_fs(tmp_path: Path, setup_tmp_local):


@pytest.fixture(scope="function")
def fs_manager_instance(setup_config_file_fs, s3_client):
async def fs_manager_instance(setup_config_file_fs, s3_client):
fs_manager = setup_config_file_fs
fs_info = fs_manager.get_filesystem_by_protocol("memory")
mem_fs = fs_info["info"]["instance"]
mem_root_path = fs_info["info"]["path"]

if mem_fs:
if mem_fs.exists(f"{mem_root_path}/test_dir"):
mem_fs.rm(f"{mem_root_path}/test_dir", recursive=True)
if mem_fs.exists(f"{mem_root_path}/second_dir"):
mem_fs.rm(f"{mem_root_path}/second_dir", recursive=True)

mem_fs.touch(f"{mem_root_path}/file_in_root.txt")
with mem_fs.open(f"{mem_root_path}/file_in_root.txt", "wb") as f:
f.write("Root file content".encode())

mem_fs.mkdir(f"{mem_root_path}/test_dir", exist_ok=True)
mem_fs.mkdir(f"{mem_root_path}/second_dir", exist_ok=True)
# mem_fs.mkdir(f'{mem_root_path}/second_dir/subdir', exist_ok=True)
mem_fs.touch(f"{mem_root_path}/test_dir/file1.txt")
with mem_fs.open(f"{mem_root_path}/test_dir/file1.txt", "wb") as f:
f.write("Test content".encode())
f.close()
if await mem_fs._exists(f"{mem_root_path}/test_dir"):
await mem_fs._rm(f"{mem_root_path}/test_dir", recursive=True)
if await mem_fs._exists(f"{mem_root_path}/second_dir"):
await mem_fs._rm(f"{mem_root_path}/second_dir", recursive=True)

await mem_fs._pipe(f"{mem_root_path}/file_in_root.txt", b"Root file content")

await mem_fs._mkdir(f"{mem_root_path}/test_dir", exist_ok=True)
await mem_fs._mkdir(f"{mem_root_path}/second_dir", exist_ok=True)

await mem_fs._pipe(f"{mem_root_path}/test_dir/file1.txt", b"Test content")
else:
print("In memory filesystem NOT FOUND")

if mem_fs.exists(f"{mem_root_path}/test_dir/file1.txt"):
mem_fs.info(f"{mem_root_path}/test_dir/file1.txt")
else:
print("File does not exist!")
return fs_manager


Expand Down
4 changes: 4 additions & 0 deletions jupyter_fsspec/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

class JupyterFsspecException(Exception):
pass


class ConfigFileException(JupyterFsspecException):
pass
Loading
Loading