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

Make ProcessEnv.bin always return a str #378

Merged
merged 1 commit into from
Feb 8, 2021
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
6 changes: 4 additions & 2 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ def bin_paths(self) -> Optional[List[str]]:
return self.virtualenv.bin_paths

@property
def bin(self) -> Optional[str]:
def bin(self) -> str:
"""The first bin directory for the virtualenv."""
paths = self.bin_paths
return paths[0] if paths is not None else None
if paths is None:
raise ValueError("The environment does not have a bin directory.")
return paths[0]

def create_tmp(self) -> str:
"""Create, and return, a temporary directory."""
Expand Down
6 changes: 4 additions & 2 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ def bin_paths(self) -> Optional[List[str]]:
return self._bin_paths

@property
def bin(self) -> Optional[str]:
def bin(self) -> str:
"""The first bin directory for the virtualenv."""
paths = self.bin_paths
return paths[0] if paths is not None else None
if paths is None:
raise ValueError("The environment does not have a bin directory.")
return paths[0]

def create(self) -> bool:
raise NotImplementedError("ProcessEnv.create should be overwritten in subclass")
Expand Down
5 changes: 4 additions & 1 deletion tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def test_no_bin_paths(self):
session, runner = self.make_session_and_runner()

runner.venv.bin_paths = None
assert session.bin is None
with pytest.raises(
ValueError, match=r"^The environment does not have a bin directory\.$"
):
session.bin
assert session.bin_paths is None

def test_virtualenv_as_none(self):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ def mock_sysfind(arg):
def test_process_env_constructor():
penv = nox.virtualenv.ProcessEnv()
assert not penv.bin_paths
with pytest.raises(
ValueError, match=r"^The environment does not have a bin directory\.$"
):
penv.bin

penv = nox.virtualenv.ProcessEnv(env={"SIGIL": "123"})
assert penv.env["SIGIL"] == "123"

penv = nox.virtualenv.ProcessEnv(bin_paths=["/bin"])
assert penv.bin == "/bin"


def test_process_env_create():
penv = nox.virtualenv.ProcessEnv()
Expand Down