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

Check up on restrictions to signac view #926

Merged
merged 9 commits into from
Jul 19, 2023
6 changes: 3 additions & 3 deletions signac/linked_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_linked_view(project, prefix=None, job_ids=None, path=None):
Linked views cannot be created on Windows because
symbolic links are not supported by the platform.
RuntimeError
When state points contain one of ``[os.sep, " ", "*"]``.
When state points contain ``os.sep``.

"""
from .import_export import _check_directory_structure_validity, _make_path_function
Expand All @@ -64,7 +64,7 @@ def create_linked_view(project, prefix=None, job_ids=None, path=None):
key_list = [k for job in jobs for k in job.statepoint().keys()]
value_list = [v for job in jobs for v in job.statepoint().values()]
item_list = key_list + value_list
bad_chars = [os.sep, " ", "*"]
bad_chars = [os.sep]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a list any more. It should also be a quicker check to use ==.

bad_items = [
item
for item in item_list
Expand All @@ -76,7 +76,7 @@ def create_linked_view(project, prefix=None, job_ids=None, path=None):
err_msg = " ".join(
[
f"In order to use view, state points should not contain {bad_chars}:",
*bad_items,
str(set(bad_items)),
]
)
raise RuntimeError(err_msg)
Expand Down
11 changes: 10 additions & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2038,14 +2038,23 @@ def test_create_linked_view_heterogeneous_schema_problematic(self):

@pytest.mark.skipif(WINDOWS, reason="Linked views unsupported on Windows.")
def test_create_linked_view_with_slash_raises_error(self):
bad_chars = [os.sep, " ", "*"]
bad_chars = [os.sep]
statepoints = [{f"a{i}b": 0, "b": f"bad{i}val"} for i in bad_chars]
view_prefix = os.path.join(self._tmp_pr, "view")
for sp in statepoints:
self.project.open_job(sp).init()
with pytest.raises(RuntimeError):
self.project.create_linked_view(prefix=view_prefix)
b-butler marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.skipif(WINDOWS, reason="Linked views unsupported on Windows.")
def test_create_linked_view_weird_chars_in_file_name(self):
bad_chars = [" ", "*", "~"]
statepoints = [{f"a{i}b": 0, "b": f"bad{i}val"} for i in bad_chars]
b-butler marked this conversation as resolved.
Show resolved Hide resolved
view_prefix = os.path.join(self._tmp_pr, "view")
for sp in statepoints:
self.project.open_job(sp).init()
self.project.create_linked_view(prefix=view_prefix)

@pytest.mark.skipif(WINDOWS, reason="Linked views unsupported on Windows.")
def test_create_linked_view_duplicate_paths(self):
view_prefix = os.path.join(self._tmp_pr, "view")
Expand Down