From eee4fc60726a9745ad4f54f0f39ad04efc3eb393 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 5 Jan 2024 17:25:42 -0600 Subject: [PATCH] fix: bad warnings --- solcx/install.py | 13 +++++++++---- tests/install/test_install.py | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/solcx/install.py b/solcx/install.py index 5267a7e..f23be89 100644 --- a/solcx/install.py +++ b/solcx/install.py @@ -489,8 +489,9 @@ def install_solc( version, filename, show_progress, solcx_binary_path=solcx_binary_path ) + base_version = version if isinstance(version, str) else version.base_version try: - _validate_installation(version, solcx_binary_path=solcx_binary_path) + _validate_installation(Version(base_version), solcx_binary_path=solcx_binary_path) except SolcInstallationError as exc: if os_name != "windows": exc.args = ( @@ -703,16 +704,20 @@ def _validate_installation(version: Version, solcx_binary_path: Union[Path, str, installed_version_clean = Version( Version(installed_version.replace("-nightly", "")).base_version ) - if installed_version_clean.base_version != version.base_version: + base_version = version if isinstance(version, str) else version.base_version + if installed_version_clean.base_version != base_version: # Without the nightly suffix, it should be the same! _unlink_solc(binary_path) raise UnexpectedVersionError( f"Attempted to install solc v{version}, but got solc v{installed_version}" ) - if installed_version not in (version.base_version, f"{version}"): + if installed_version_clean not in ( + Version(base_version), + f"{base_version}", + ) or installed_version.endswith("-nightly"): # If it does have the nightly suffix, then only warn. warnings.warn( - f"Installed solc version is v{installed_version}, expecting v{version.base_version}", + f"Installed solc version is v{installed_version_clean}, expecting v{base_version}", UnexpectedVersionWarning, ) diff --git a/tests/install/test_install.py b/tests/install/test_install.py index 1aaed51..e68d6cc 100644 --- a/tests/install/test_install.py +++ b/tests/install/test_install.py @@ -1,3 +1,5 @@ +import warnings + import pytest import solcx @@ -23,7 +25,10 @@ def test_install_unknown_version(): @pytest.mark.skipif("'--no-install' in sys.argv") def test_progress_bar(nosolc): - assert solcx.install_solc("0.6.9", show_progress=True).base_version == "0.6.9" + # There should be no warnings! + with warnings.catch_warnings(): + warnings.simplefilter("error") + assert solcx.install_solc("0.6.9", show_progress=True).base_version == "0.6.9" def test_environment_var_path(monkeypatch, tmp_path):