diff --git a/requirements-dev.txt b/requirements-dev.txt index 7e3ce1d..44a2214 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,13 +3,14 @@ bumpversion==0.5.3 flake8==3.8.3 isort==5.4.2 mypy==0.782 -pytest>=6.0.0,<7.0.0 pytest-cov==2.10.1 +pytest-mock==3.6.1 +pytest>=6.0.0,<7.0.0 +requests>=2.19.0,<3 semantic_version>=2.8.1,<3 sphinx==3.2.1 sphinx_rtd_theme==0.5.0 tox==3.19.0 tqdm>=4.48.0,<5.0.0 twine==3.2.0 -requests>=2.19.0,<3 wheel==0.35.1 diff --git a/solcx/main.py b/solcx/main.py index 5bd3865..a446f1b 100644 --- a/solcx/main.py +++ b/solcx/main.py @@ -235,8 +235,11 @@ def compile_files( ) -def _get_combined_json_outputs() -> str: - help_str = wrapper.solc_wrapper(help=True)[0].split("\n") +def _get_combined_json_outputs(solc_binary: Union[Path, str] = None) -> str: + if solc_binary is None: + solc_binary = get_executable() + + help_str = wrapper.solc_wrapper(solc_binary=solc_binary, help=True)[0].split("\n") combined_json_args = next(i for i in help_str if i.startswith(" --combined-json")) return combined_json_args.split(" ")[-1] @@ -258,23 +261,23 @@ def _parse_compiler_output(stdoutdata: str) -> Dict: def _compile_combined_json( - output_values: Optional[List], - solc_binary: Union[str, Path, None], - solc_version: Optional[Version], - output_dir: Union[str, Path, None], - overwrite: Optional[bool], - allow_empty: Optional[bool], + output_values: Optional[List] = None, + solc_binary: Union[str, Path, None] = None, + solc_version: Optional[Version] = None, + output_dir: Union[str, Path, None] = None, + overwrite: Optional[bool] = False, + allow_empty: Optional[bool] = False, **kwargs: Any, ) -> Dict: + if solc_binary is None: + solc_binary = get_executable(solc_version) + if output_values is None: - combined_json = _get_combined_json_outputs() + combined_json = _get_combined_json_outputs(solc_binary) else: combined_json = ",".join(output_values) - if solc_binary is None: - solc_binary = get_executable(solc_version) - if output_dir: output_dir = Path(output_dir) if output_dir.is_file(): diff --git a/tests/main/test_utils.py b/tests/main/test_utils.py new file mode 100644 index 0000000..7f247ee --- /dev/null +++ b/tests/main/test_utils.py @@ -0,0 +1,14 @@ +import solcx +import solcx.main + + +def test_get_combined_json_outputs_defaults(mocker, foo_source): + # verify we get the correct combined json outputs for different + # compiler versions + spy = mocker.spy(solcx.main, "_get_combined_json_outputs") + + solcx.compile_source(foo_source, solc_version="0.4.12") + assert "function-debug" not in spy.spy_return + + solcx.compile_source(foo_source, solc_version="0.8.9") + assert "function-debug" in spy.spy_return