diff --git a/maigret/checking.py b/maigret/checking.py index 0fe4d83..c0a0603 100644 --- a/maigret/checking.py +++ b/maigret/checking.py @@ -1019,6 +1019,7 @@ async def self_check( i2p_proxy=None, auto_disable=False, diagnose=False, + no_progressbar=False, ) -> dict: """ Run self-check on sites. @@ -1053,7 +1054,7 @@ async def self_check( tasks.append((site.name, future)) if tasks: - with alive_bar(len(tasks), title='Self-checking', force_tty=True) as progress: + with alive_bar(len(tasks), title='Self-checking', force_tty=True, disable=no_progressbar) as progress: for site_name, f in tasks: result = await f result['site_name'] = site_name diff --git a/maigret/maigret.py b/maigret/maigret.py index 8226dfa..a96bd53 100755 --- a/maigret/maigret.py +++ b/maigret/maigret.py @@ -600,6 +600,7 @@ async def main(): i2p_proxy=args.i2p_proxy, auto_disable=args.auto_disable, diagnose=args.diagnose, + no_progressbar=args.no_progressbar, ) # Handle both old (bool) and new (dict) return types diff --git a/maigret/resources/data.json b/maigret/resources/data.json index d426c72..c80fc71 100644 --- a/maigret/resources/data.json +++ b/maigret/resources/data.json @@ -15165,6 +15165,23 @@ "usernameClaimed": "adam", "usernameUnclaimed": "noonewouldeverusethis7" }, + "Max": { + "tags": [ + "messaging", + "ru" + ], + "checkType": "message", + "presenseStrs": [ + "channel:{title:\"" + ], + "absenceStrs": [ + "\u041d\u0435 \u043d\u0430\u0448\u043b\u0438 \u0447\u0430\u0442 \u043f\u043e \u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435" + ], + "urlMain": "https://max.ru", + "url": "https://max.ru/{username}", + "usernameClaimed": "ivolk", + "usernameUnclaimed": "noonewouldeverusethis7" + }, "Maxpark": { "disabled": true, "tags": [ diff --git a/tests/test_maigret.py b/tests/test_maigret.py index 4ff029e..5cd5172 100644 --- a/tests/test_maigret.py +++ b/tests/test_maigret.py @@ -2,6 +2,7 @@ import asyncio import copy +from unittest.mock import patch import pytest from mock import Mock @@ -37,6 +38,51 @@ async def test_self_check_db(test_db): assert test_db.sites_dict['InvalidInactive'].disabled is True +@pytest.mark.slow +@pytest.mark.asyncio +async def test_self_check_no_progressbar(test_db): + """Verify that no_progressbar=True disables the alive_bar in self_check.""" + logger = Mock() + + with patch('maigret.checking.alive_bar') as mock_alive_bar: + mock_bar = Mock() + mock_alive_bar.return_value.__enter__ = Mock(return_value=mock_bar) + mock_alive_bar.return_value.__exit__ = Mock(return_value=False) + + await self_check( + test_db, test_db.sites_dict, logger, silent=True, + no_progressbar=True, + ) + + # First call is the self-check progress bar; subsequent calls are + # from inner search() invocations. + self_check_call = mock_alive_bar.call_args_list[0] + _, kwargs = self_check_call + assert kwargs.get('title') == 'Self-checking' + assert kwargs.get('disable') is True + + +@pytest.mark.slow +@pytest.mark.asyncio +async def test_self_check_progressbar_enabled_by_default(test_db): + """Verify that alive_bar is enabled by default (no_progressbar=False).""" + logger = Mock() + + with patch('maigret.checking.alive_bar') as mock_alive_bar: + mock_bar = Mock() + mock_alive_bar.return_value.__enter__ = Mock(return_value=mock_bar) + mock_alive_bar.return_value.__exit__ = Mock(return_value=False) + + await self_check( + test_db, test_db.sites_dict, logger, silent=True, + ) + + self_check_call = mock_alive_bar.call_args_list[0] + _, kwargs = self_check_call + assert kwargs.get('title') == 'Self-checking' + assert kwargs.get('disable') is False + + @pytest.mark.slow @pytest.mark.skip(reason="broken, fixme") def test_maigret_results(test_db):