From 79c17c20faf9d9857ee4cdee3fcbc9420c0064f7 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 5 Jan 2024 17:18:43 -0600 Subject: [PATCH] fix: bad warnings --- solcx/install.py | 13 +++++++++---- tests/install/test_install.py | 7 ++++++- tests/install/test_validate_installation.py | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/solcx/install.py b/solcx/install.py index e6abdf1..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_clean 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): diff --git a/tests/install/test_validate_installation.py b/tests/install/test_validate_installation.py index 49525b6..ca5c98c 100644 --- a/tests/install/test_validate_installation.py +++ b/tests/install/test_validate_installation.py @@ -1,4 +1,5 @@ import sys +import warnings import pytest @@ -6,6 +7,19 @@ from solcx.exceptions import SolcInstallationError, UnexpectedVersionError, UnexpectedVersionWarning +def test_validate_installation(mocker, install_mock, solc_binary, install_path): + version = solcx.wrapper.get_solc_version(solc_binary) + version_str_patch = mocker.patch("solcx.wrapper.get_version_str_from_solc_binary") + version_str_patch.return_value = f"{version}" + + # This should not warn! + with warnings.catch_warnings(): + warnings.simplefilter("error") + solcx.install_solc() + + assert install_path.exists() + + def test_validate_installation_wrong_version(mocker, install_mock, install_path): patch = mocker.patch("solcx.wrapper.get_version_str_from_solc_binary") patch.return_value = "0.0.0"