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

Fix path list with whitespace #588

Merged
merged 2 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions src/rez/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class OptionalStrList(StrList):
class PathList(StrList):
sep = os.pathsep

def _parse_env_var(self, value):
value = value.split(self.sep)
return [x for x in value if x]


class Int(Setting):
schema = Schema(int)
Expand Down
13 changes: 13 additions & 0 deletions src/rez/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ def _data(self):
finally:
os.environ = old_environ

def test_7(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

fails on linux (pathsep is :)

"""Test path list environment variable with whitespace."""
c = Config([self.root_config_file], locked=False)

# test basic env-var override
packages_path = [
"c:/foo bar/baz",
"c:/foo 2 bar/baz",
]
asztalosdani marked this conversation as resolved.
Show resolved Hide resolved
os.environ["REZ_PACKAGES_PATH"] = os.pathsep.join(packages_path)
Copy link

Choose a reason for hiding this comment

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

I think it is not a good idea to change an environment variable in the UT as it affects all other tests that are run as part of the same process (i.e when running rez selftests)
This line breaks a test on other unrelated area.
If you really need to, then put the original value back...something along the lines

original_packages_path = os.environ["REZ_PACKAGES_PATH"]
os.environ["REZ_PACKAGES_PATH"] = os.pathsep.join(packages_path)
self.assertEqual(c.packages_path, packages_path)
os.environ["REZ_PACKAGES_PATH"] = original_packages_path

or if you are going to use it several times create a @contextmanager and with with ...

Also, I do not understand the original use case of this change.
Why not set the path like c:/foo;c:/bar/baz or "/foo:baz/bar` why do you need the space?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed on not changing variables that persist across tests, however:

Why not set the path like c:/foo;c:/bar/baz or "/foo:baz/bar` why do you need the space?

The folder c:\foo bar\ is different from c:\foo and c:\bar I think.

Copy link

Choose a reason for hiding this comment

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

Would quotes work in this case? ie. "c:\foo bar"?


self.assertEqual(c.packages_path, packages_path)


if __name__ == '__main__':
unittest.main()
Expand Down