From 7df129ec25bf9e162d10b51f4fe35a507707e1ac Mon Sep 17 00:00:00 2001 From: Tom Fleet Date: Fri, 17 Sep 2021 17:20:39 +0100 Subject: [PATCH 1/2] Decouple test_session_completer from project's root noxfile --- tests/resources/noxfile_multiple_sessions.py | 33 ++++++++++++++++++++ tests/test__option_set.py | 18 ++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 tests/resources/noxfile_multiple_sessions.py diff --git a/tests/resources/noxfile_multiple_sessions.py b/tests/resources/noxfile_multiple_sessions.py new file mode 100644 index 00000000..47a6da75 --- /dev/null +++ b/tests/resources/noxfile_multiple_sessions.py @@ -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") diff --git a/tests/test__option_set.py b/tests/test__option_set.py index f8f14211..e34df96e 100644 --- a/tests/test__option_set.py +++ b/tests/test__option_set.py @@ -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 @@ -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() @@ -79,14 +84,17 @@ def test_parser_groupless_option(self): optionset.parser() def test_session_completer(self): - parsed_args = _options.options.namespace(sessions=(), keywords=(), posargs=[]) + parsed_args = _options.options.namespace( + sessions=("testytest", "lintylint", "typeytype"), + posargs=[], + noxfile=str(RESOURCES.joinpath("noxfile_multiple_sessions.py")), + ) all_nox_sessions = _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 + + some_expected_sessions = ["testytest", "lintylint", "typeytype"] + assert some_expected_sessions == all_nox_sessions def test_session_completer_invalid_sessions(self): parsed_args = _options.options.namespace( From b9a85d73d701462e20da7f3bc7f4cccb80be0e20 Mon Sep 17 00:00:00 2001 From: Tom Fleet Date: Fri, 17 Sep 2021 17:30:59 +0100 Subject: [PATCH 2/2] Make test variables a bit more intuitive --- tests/test__option_set.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test__option_set.py b/tests/test__option_set.py index e34df96e..99d2d95a 100644 --- a/tests/test__option_set.py +++ b/tests/test__option_set.py @@ -85,16 +85,15 @@ def test_parser_groupless_option(self): def test_session_completer(self): parsed_args = _options.options.namespace( - sessions=("testytest", "lintylint", "typeytype"), posargs=[], noxfile=str(RESOURCES.joinpath("noxfile_multiple_sessions.py")), ) - all_nox_sessions = _options._session_completer( + actual_sessions_from_file = _options._session_completer( prefix=None, parsed_args=parsed_args ) - some_expected_sessions = ["testytest", "lintylint", "typeytype"] - assert some_expected_sessions == all_nox_sessions + expected_sessions = ["testytest", "lintylint", "typeytype"] + assert expected_sessions == actual_sessions_from_file def test_session_completer_invalid_sessions(self): parsed_args = _options.options.namespace(