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

Decouple test_session_completer from project level noxfile #480

Merged
merged 2 commits into from
Sep 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/resources/noxfile_multiple_sessions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2018 Alethea Katherine Flowers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import nox

# Deliberately giving these silly names so we know this is not confused
# with the projects noxfile


@nox.session
def testytest(session):
session.log("Testing")


@nox.session
def lintylint(session):
session.log("Linting")


@nox.session
def typeytype(session):
session.log("Type Checking")
19 changes: 13 additions & 6 deletions tests/test__option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path

import pytest

from nox import _option_set, _options
Expand All @@ -20,6 +22,9 @@
# :func:`OptionSet.namespace` needs a bit of help to get to full coverage.


RESOURCES = Path(__file__).parent.joinpath("resources")


class TestOptionSet:
def test_namespace(self):
optionset = _option_set.OptionSet()
Expand Down Expand Up @@ -79,14 +84,16 @@ def test_parser_groupless_option(self):
optionset.parser()

def test_session_completer(self):
parsed_args = _options.options.namespace(sessions=(), keywords=(), posargs=[])
all_nox_sessions = _options._session_completer(
parsed_args = _options.options.namespace(
posargs=[],
noxfile=str(RESOURCES.joinpath("noxfile_multiple_sessions.py")),
)
actual_sessions_from_file = _options._session_completer(
prefix=None, parsed_args=parsed_args
)
# if noxfile.py changes, this will have to change as well since these are
# some of the actual sessions found in noxfile.py
some_expected_sessions = ["blacken", "lint", "docs"]
assert len(set(some_expected_sessions) - set(all_nox_sessions)) == 0

expected_sessions = ["testytest", "lintylint", "typeytype"]
assert expected_sessions == actual_sessions_from_file

def test_session_completer_invalid_sessions(self):
parsed_args = _options.options.namespace(
Expand Down