File tree Expand file tree Collapse file tree 3 files changed +21
-10
lines changed
Expand file tree Collapse file tree 3 files changed +21
-10
lines changed Original file line number Diff line number Diff line change 7272 env :
7373 # Number of expected test passes, safety measure for accidental skip of
7474 # tests. Update value if you add/remove tests.
75- PYTEST_REQPASS : 890
75+ PYTEST_REQPASS : 891
7676 steps :
7777 - uses : actions/checkout@v4
7878 with :
Original file line number Diff line number Diff line change @@ -322,7 +322,7 @@ def get_version_warning() -> str:
322322 with open (cache_file , encoding = "utf-8" ) as f :
323323 data = json .load (f )
324324
325- if refresh or not data :
325+ if not options . offline and ( refresh or not data ) :
326326 release_url = (
327327 "https://api.github.com/repos/ansible/ansible-lint/releases/latest"
328328 )
@@ -339,13 +339,14 @@ def get_version_warning() -> str:
339339 )
340340 return ""
341341
342- html_url = data ["html_url" ]
343- new_version = Version (data ["tag_name" ][1 :]) # removing v prefix from tag
342+ if data :
343+ html_url = data ["html_url" ]
344+ new_version = Version (data ["tag_name" ][1 :]) # removing v prefix from tag
344345
345- if current_version > new_version :
346- msg = "[dim]You are using a pre-release version of ansible-lint.[/]"
347- elif current_version < new_version :
348- msg = f"""[warning]A new release of ansible-lint is available: [red]{ current_version } [/] → [green][link={ html_url } ]{ new_version } [/][/][/]"""
349- msg += f" Upgrade by running: [info]{ pip } [/]"
346+ if current_version > new_version :
347+ msg = "[dim]You are using a pre-release version of ansible-lint.[/]"
348+ elif current_version < new_version :
349+ msg = f"""[warning]A new release of ansible-lint is available: [red]{ current_version } [/] → [green][link={ html_url } ]{ new_version } [/][/][/]"""
350+ msg += f" Upgrade by running: [info]{ pip } [/]"
350351
351352 return msg
Original file line number Diff line number Diff line change 44import shutil
55import subprocess
66import sys
7+ import tempfile
78import time
89from http .client import RemoteDisconnected
910from pathlib import Path
1011
1112import pytest
1213from pytest_mock import MockerFixture
1314
14- from ansiblelint .config import get_version_warning
15+ from ansiblelint .config import get_version_warning , options
1516from ansiblelint .constants import RC
1617
1718
@@ -102,6 +103,15 @@ def test_get_version_warning_remote_disconnect(mocker: MockerFixture) -> None:
102103 pytest .fail ("Failed to handle a remote disconnect" )
103104
104105
106+ def test_get_version_warning_offline (mocker : MockerFixture ) -> None :
107+ """Test that offline mode does not display any message."""
108+ with tempfile .TemporaryDirectory () as temporary_directory :
109+ # ensures a real cache_file is not loaded
110+ mocker .patch ("ansiblelint.config.CACHE_DIR" , Path (temporary_directory ))
111+ options .offline = True
112+ assert get_version_warning () == ""
113+
114+
105115@pytest .mark .parametrize (
106116 ("lintable" ),
107117 (
You can’t perform that action at this time.
0 commit comments