def test_get_server_version(self, options: Options, requests_mock): url = urljoin(options.url, Endpoint.ABOUT.s) options.autoload = True requests_mock.register_uri( "GET", f"{url}?format=text", content=bytes("foo bar baz\nversion: 42.1337.00", encoding="utf-8"), ) version = _get_server_version(options) assert requests_mock.called_once assert version == "42.1337.00"
def test_get_server_version_no_autoload(self, options: Options, requests_mock, caplog): url = urljoin(options.url, Endpoint.ABOUT.s) options.autoload = False requests_mock.register_uri("GET", f"{url}?format=text", text="foobarbaz") with caplog.at_level(logging.DEBUG): version = _get_server_version(options) assert not requests_mock.called_once assert ("Unable to get server version. Reason: `Autoload is disabled.`" in caplog.text) assert version == UNKNOWN_SERVER_VERSION
def test_get_server_version_not_decodable(self, options: Options, requests_mock, caplog): url = urljoin(options.url, Endpoint.ABOUT.s) options.autoload = True requests_mock.register_uri("GET", f"{url}?format=text", content=bytes("foobarbaz", encoding="utf-8")) with caplog.at_level(logging.DEBUG): version = _get_server_version(options) assert requests_mock.called_once assert ( "Unable to get server version. Reason: `list index out of range`" in caplog.text) assert version == UNKNOWN_SERVER_VERSION
from omnipath._core.cache import clear_cache from omnipath._core.utils import options # from_first in isort is important here from omnipath._core.downloader._downloader import _get_server_version import omnipath.requests as requests import omnipath.constants as constants import omnipath.interactions as interactions __author__ = ", ".join(["Michal Klein", "Dénes Türei"]) __maintainer__ = ", ".join(["Michal Klein", "Dénes Türei"]) __version__ = "1.0.4" __email__ = "*****@*****.**" try: from importlib_metadata import version # Python < 3.8 except ImportError: from importlib.metadata import version # Python = 3.8 from packaging.version import parse __full_version__ = parse(version(__name__)) __full_version__ = ( f"{__version__}+{__full_version__.local}" if __full_version__.local else __version__ ) __server_version__ = _get_server_version(options) del parse, version, _get_server_version