Skip to content

Commit

Permalink
Decouple test_session_completer from project level noxfile (#480)
Browse files Browse the repository at this point in the history
* Decouple test_session_completer from project's root noxfile

* Make test variables a bit more intuitive
  • Loading branch information
FollowTheProcess committed Sep 17, 2021
1 parent f584aed commit e7d4f5a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
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

0 comments on commit e7d4f5a

Please sign in to comment.