def filter_manifest(manifest: Manifest, global_config: Namespace) -> Union[Manifest, int]: """Filter the manifest according to the provided configuration. Args: manifest (~.Manifest): The manifest of sessions to be run. global_config (~nox.main.GlobalConfig): The global configuration. Returns: Union[~.Manifest,int]: ``3`` if a specified session is not found, the manifest otherwise (to be sent to the next task). """ # Filter by the name of any explicit sessions. # This can raise KeyError if a specified session does not exist; # log this if it happens. if global_config.sessions: try: manifest.filter_by_name(global_config.sessions) except KeyError as exc: logger.error("Error while collecting sessions.") logger.error(exc.args[0]) return 3 # Filter by keywords. # This function never errors, but may cause an empty list of sessions # (which is an error condition later). if global_config.keywords: manifest.filter_by_keywords(global_config.keywords) # Return the modified manifest. return manifest
def test_notify(): manifest = Manifest({}, mock.sentinel.CONFIG) # Define a session. def my_session(session): pass my_session.python = None def notified(session): pass notified.python = None # Add the sessions to the manifest. for session in manifest.make_session("my_session", my_session): manifest.add_session(session) for session in manifest.make_session("notified", notified): manifest.add_session(session) assert len(manifest) == 2 # Filter so only the first session is included in the queue. manifest.filter_by_name(("my_session", )) assert len(manifest) == 1 # Notify the notified session. manifest.notify("notified") assert len(manifest) == 2
def test_notify(): manifest = Manifest({}, mock.sentinel.CONFIG) # Define a session. def my_session(session): pass my_session.python = None def notified(session): pass notified.python = None # Add the sessions to the manifest. for session in manifest.make_session("my_session", my_session): manifest.add_session(session) for session in manifest.make_session("notified", notified): manifest.add_session(session) assert len(manifest) == 2 # Filter so only the first session is included in the queue. manifest.filter_by_name(("my_session",)) assert len(manifest) == 1 # Notify the notified session. manifest.notify("notified") assert len(manifest) == 2
def test_notify_with_posargs(): cfg = create_mock_config() manifest = Manifest({}, cfg) session = manifest.make_session("my_session", Func(lambda session: None))[0] manifest.add_session(session) # delete my_session from the queue manifest.filter_by_name(()) assert session.posargs == cfg.posargs assert manifest.notify("my_session", posargs=["--an-arg"]) assert session.posargs == ["--an-arg"]
def test_notify(): manifest = Manifest({}, mock.sentinel.CONFIG) # Define a session. def my_session(session): pass def notified(session): pass # Add the sessions to the manifest. for session in manifest.make_session('my_session', my_session): manifest.add_session(session) for session in manifest.make_session('notified', notified): manifest.add_session(session) assert len(manifest) == 2 # Filter so only the first session is included in the queue. manifest.filter_by_name(('my_session',)) assert len(manifest) == 1 # Notify the notified session. manifest.notify('notified') assert len(manifest) == 2
def filter_manifest(manifest: Manifest, global_config: Namespace) -> Manifest | int: """Filter the manifest according to the provided configuration. Args: manifest (~.Manifest): The manifest of sessions to be run. global_config (~nox.main.GlobalConfig): The global configuration. Returns: Union[~.Manifest,int]: ``3`` if a specified session is not found, the manifest otherwise (to be sent to the next task). """ # Shouldn't happen unless the Noxfile is empty if not manifest: logger.error(f"No sessions found in {global_config.noxfile}.") return 3 # Filter by the name of any explicit sessions. # This can raise KeyError if a specified session does not exist; # log this if it happens. The sessions does not come from the Noxfile # if keywords is not empty. if global_config.sessions is not None: try: manifest.filter_by_name(global_config.sessions) except KeyError as exc: logger.error("Error while collecting sessions.") logger.error(exc.args[0]) return 3 if not manifest and not global_config.list_sessions: print( "No sessions selected. Please select a session with -s <session name>.\n" ) _produce_listing(manifest, global_config) return 0 # Filter by python interpreter versions. if global_config.pythons: manifest.filter_by_python_interpreter(global_config.pythons) if not manifest and not global_config.list_sessions: logger.error( "Python version selection caused no sessions to be selected.") return 3 # Filter by tags. if global_config.tags is not None: manifest.filter_by_tags(global_config.tags) if not manifest and not global_config.list_sessions: logger.error("Tag selection caused no sessions to be selected.") return 3 # Filter by keywords. if global_config.keywords: try: ast.parse(global_config.keywords, mode="eval") except SyntaxError: logger.error( "Error while collecting sessions: keywords argument must be a Python" " expression.") return 3 # This function never errors, but may cause an empty list of sessions # (which is an error condition later). manifest.filter_by_keywords(global_config.keywords) if not manifest and not global_config.list_sessions: logger.error("No sessions selected after filtering by keyword.") return 3 # Return the modified manifest. return manifest
def test_filter_by_name_not_found(): sessions = create_mock_sessions() manifest = Manifest(sessions, mock.sentinel.CONFIG) with pytest.raises(KeyError): manifest.filter_by_name(("baz", ))
def test_filter_by_name_maintains_order(): sessions = create_mock_sessions() manifest = Manifest(sessions, mock.sentinel.CONFIG) manifest.filter_by_name(("bar", "foo")) assert [session.name for session in manifest] == ["bar", "foo"]
def test_filter_by_name(): sessions = create_mock_sessions() manifest = Manifest(sessions, mock.sentinel.CONFIG) manifest.filter_by_name(("foo", )) assert "foo" in manifest assert "bar" not in manifest
def test_filter_by_name_not_found(): sessions = create_mock_sessions() manifest = Manifest(sessions, create_mock_config()) with pytest.raises(KeyError): manifest.filter_by_name(("baz",))
def test_filter_by_name_maintains_order(): sessions = create_mock_sessions() manifest = Manifest(sessions, create_mock_config()) manifest.filter_by_name(("bar", "foo")) assert [session.name for session in manifest] == ["bar", "foo"]
def test_filter_by_name(): sessions = create_mock_sessions() manifest = Manifest(sessions, create_mock_config()) manifest.filter_by_name(("foo",)) assert "foo" in manifest assert "bar" not in manifest
def test_filter_by_name(): sessions = create_mock_sessions() manifest = Manifest(sessions, mock.sentinel.CONFIG) manifest.filter_by_name(('foo', )) assert 'foo' in manifest assert 'bar' not in manifest
def test_filter_by_name_not_found(): sessions = create_mock_sessions() manifest = Manifest(sessions, mock.sentinel.CONFIG) with pytest.raises(KeyError): manifest.filter_by_name(("baz",))
def test_filter_by_name(): sessions = create_mock_sessions() manifest = Manifest(sessions, mock.sentinel.CONFIG) manifest.filter_by_name(("foo",)) assert "foo" in manifest assert "bar" not in manifest