diff --git a/pyproject.toml b/pyproject.toml index 78b9a5cf..b82353b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,6 +73,7 @@ test = [ "pytest>=7.2.0", "pytest-mock>=3.10.0", "pytest-cov>=4.0.0", + "pytest-console-scripts>=1.4.1", "flake8>=5.0.4", "mypy>=0.981", "pytest-asyncio>=0.21.0", diff --git a/servicex/app/cli_options.py b/servicex/app/cli_options.py index 7015c86b..75aef22f 100644 --- a/servicex/app/cli_options.py +++ b/servicex/app/cli_options.py @@ -31,3 +31,5 @@ url_cli_option = typer.Option(None, "-u", "--url", help="URL of ServiceX server") backend_cli_option = typer.Option(None, "-b", "--backend", help="Name of backend server from .servicex file") +config_file_option = typer.Option(None, "-c", "--config", + help="ServiceX client configuration file") diff --git a/servicex/app/codegen.py b/servicex/app/codegen.py index a117e36b..5b41f235 100644 --- a/servicex/app/codegen.py +++ b/servicex/app/codegen.py @@ -29,7 +29,7 @@ import rich import typer -from servicex.app.cli_options import url_cli_option, backend_cli_option +from servicex.app.cli_options import url_cli_option, backend_cli_option, config_file_option from servicex.servicex_client import ServiceXClient from typing import Optional @@ -39,11 +39,12 @@ @codegen_app.command(no_args_is_help=False) def flush( url: Optional[str] = url_cli_option, - backend: Optional[str] = backend_cli_option): + backend: Optional[str] = backend_cli_option, + config_path: Optional[str] = config_file_option): """ Flush the available code generators from the cache """ - sx = ServiceXClient(url=url, backend=backend) + sx = ServiceXClient(url=url, backend=backend, config_path=config_path) cache = sx.query_cache cache.delete_codegen_by_backend(backend) rich.print("Deleted cached code generators.") @@ -52,9 +53,10 @@ def flush( @codegen_app.command(no_args_is_help=False) def list( url: Optional[str] = url_cli_option, - backend: Optional[str] = backend_cli_option): + backend: Optional[str] = backend_cli_option, + config_path: Optional[str] = config_file_option): """ List the available code generators """ - sx = ServiceXClient(url=url, backend=backend) + sx = ServiceXClient(url=url, backend=backend, config_path=config_path) rich.print_json(data=sx.get_code_generators()) diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 00000000..25c487c1 --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,60 @@ +# Copyright (c) 2024, IRIS-HEP +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from unittest.mock import patch + + +def test_app_version(script_runner): + import servicex._version + result = script_runner.run(['servicex', '--version']) + assert result.returncode == 0 + assert result.stdout == f'ServiceX {servicex._version.__version__}\n' + + +def test_codegen_list(script_runner): + with patch('servicex.servicex_adapter.ServiceXAdapter.get_code_generators', return_value={ + "uproot": "http://uproot-codegen", + "xaod": "http://xaod-codegen" + }): + result = script_runner.run(['servicex', 'codegen', 'list', '-c', + 'tests/example_config.yaml']) + assert result.returncode == 0 + assert result.stdout == '''{ + "uproot": "http://uproot-codegen", + "xaod": "http://xaod-codegen" +} +''' + + +def test_codegen_flush(script_runner): + with patch('servicex.query_cache.QueryCache.delete_codegen_by_backend') as p: + result = script_runner.run(['servicex', 'codegen', 'flush', + '-c', 'tests/example_config.yaml', + '-b', 'localhost']) + assert result.returncode == 0 + p.assert_called_once_with('localhost')