Skip to content

Commit

Permalink
Linting (wntrblm#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynforthewyn committed May 7, 2021
1 parent 7ac3fab commit 0d224b0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
8 changes: 5 additions & 3 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def conda_install(
raise ValueError("At least one argument required to install().")

if self._runner.global_config.no_install:
if (venv.venv_created):
if venv.venv_created:
logger.info(
"Skipping {} conda installation, as --no-install is set.".format(
args[0]
Expand Down Expand Up @@ -451,7 +451,7 @@ def install(self, *args: str, **kwargs: Any) -> None:
raise ValueError("At least one argument required to install().")

if self._runner.global_config.no_install:
if(venv.venv_created):
if venv.venv_created:
logger.info(
"Skipping {} installation, as --no-install is set.".format(args[0])
)
Expand Down Expand Up @@ -554,7 +554,9 @@ def _create_venv(self) -> None:
return

reuse_existing = (
self.func.reuse_venv or self.global_config.reuse_existing_virtualenvs or self.global_config.no_install
self.func.reuse_venv
or self.global_config.reuse_existing_virtualenvs
or self.global_config.no_install
)

if backend is None or backend == "virtualenv":
Expand Down
2 changes: 1 addition & 1 deletion nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,5 +438,5 @@ def create(self) -> bool:
nox.command.run(cmd, silent=True, log=False)

self.venv_created = True

return True
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def lint(session):
"nox",
)
files = ["nox", "tests", "noxfile.py", "setup.py"]
session.run("black", "--check", *files)
session.run("black", *files)
session.run("isort", "--check", "--recursive", *files)
session.run("flake8", "nox", *files)

Expand Down
52 changes: 29 additions & 23 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ def test__normalize_path_give_up():
norm_path = nox.sessions._normalize_path(envdir, "any-path")
assert "any-path" in norm_path


class MockableSession(nox.sessions.Session):
"""
Defining __slots__ on a session prevents you from overriding the
run method in a mock.
Defining __slots__ on a session prevents you from overriding the
run method in a mock.
Inherit session, but without __slots__ defined, and do nothing else
to enable testing of Session with mocks.
"""

pass


class TestSession:
def make_session_and_runner(self):
func = mock.Mock(spec=["python"], python="3.7")
Expand Down Expand Up @@ -328,7 +331,6 @@ def test_run_always_no_install(self, caplog):

assert "Skipping run_always" in caplog.text


def test_conda_install_bad_args(self):
session, runner = self.make_session_and_runner()
runner.venv = mock.create_autospec(nox.virtualenv.CondaEnv)
Expand Down Expand Up @@ -396,30 +398,34 @@ def test_conda_install(self, auto_offline, offline):
external="error",
)

@pytest.mark.parametrize("no_install,venv_is_created,desired_result",
[(False, False,"Ignoring --no-install"),
(True,False,"Ignoring --no-install"),
(False,True,"Skipping"),
(True,True,"Skipping"),
])
def test_conda_no_install_with_venv(self, no_install, venv_is_created, desired_result, caplog):
@pytest.mark.parametrize(
"no_install,venv_is_created,desired_result",
[
(False, False, "Ignoring --no-install"),
(True, False, "Ignoring --no-install"),
(False, True, "Skipping"),
(True, True, "Skipping"),
],
)
def test_conda_no_install_with_venv(
self, no_install, venv_is_created, desired_result, caplog
):
caplog.set_level(logging.INFO)
session, runner = self.make_session_and_runner()

runner.venv = mock.create_autospec(nox.virtualenv.CondaEnv)
runner.venv.location = "/path/to/conda/env"
runner.venv.env = {}
runner.venv.is_offline = lambda: True

runner.global_config.no_install = True
runner.venv.venv_created = venv_is_created

with mock.patch.object(nox.command, "run") as run:
with mock.patch.object(nox.command, "run"):
assert session.conda_install("baked beans", "eggs", "spam") is None

assert desired_result in caplog.text


@pytest.mark.parametrize(
"version_constraint",
["no", "yes", "already_dbl_quoted"],
Expand Down Expand Up @@ -569,22 +575,22 @@ def test_skip_no_log(self):
with pytest.raises(nox.sessions._SessionSkip):
session.skip()


@pytest.mark.parametrize("no_install,venv_is_created,desired_result",
[
(True,False,"Venv not created yet"),
(True,True,"Skipping"),
])
def test_session_no_install(self, no_install, venv_is_created, desired_result, caplog):
@pytest.mark.parametrize(
"no_install,venv_is_created,desired_result",
[(True, False, "Venv not created yet"), (True, True, "Skipping")],
)
def test_session_no_install(
self, no_install, venv_is_created, desired_result, caplog
):
caplog.set_level(logging.INFO)
session, runner = self.make_session_and_runner()

runner.global_config.no_install = no_install
runner.venv.venv_created = venv_is_created

with mock.patch.object(nox.command, "run") as run:
with mock.patch.object(nox.command, "run"):
assert session.install("eggs", "spam") is None

assert desired_result in caplog.text

def test___slots__(self):
Expand Down

0 comments on commit 0d224b0

Please sign in to comment.