From 585d830979c1beb9e63d8c5220c984e032babedb Mon Sep 17 00:00:00 2001 From: Peter Onyisi Date: Mon, 30 Sep 2024 19:27:30 +0000 Subject: [PATCH 1/2] expose OutputFormatEnum instead of ResultFormat to user --- servicex/__init__.py | 6 ++++-- tests/test_databinder.py | 17 ++++++++++++++++- tests/test_dataset_group.py | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/servicex/__init__.py b/servicex/__init__.py index e31f6df5..dc2bd9e6 100644 --- a/servicex/__init__.py +++ b/servicex/__init__.py @@ -27,12 +27,14 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from servicex.databinder_models import Sample, General, ServiceXSpec from servicex.servicex_client import deliver -from .models import ResultFormat, ResultDestination +from .models import ResultDestination import servicex.dataset as dataset import servicex.query as query +OutputFormat = General.OutputFormatEnum + __all__ = [ - "ResultFormat", + "OutputFormat", "ResultDestination", "Sample", "General", diff --git a/tests/test_databinder.py b/tests/test_databinder.py index 40cd9695..eae36fb3 100644 --- a/tests/test_databinder.py +++ b/tests/test_databinder.py @@ -2,7 +2,7 @@ from unittest.mock import patch from pydantic import ValidationError -from servicex import ServiceXSpec, dataset +from servicex import ServiceXSpec, dataset, OutputFormat from servicex.query_core import ServiceXException from servicex.servicex_client import ReturnValueException from servicex.dataset import FileList, Rucio @@ -93,6 +93,21 @@ def test_list_of_root_files(): ] +def test_output_format(): + spec = basic_spec() + spec['General'] = {'OutputFormat': 'root-ttree'} + ServiceXSpec.model_validate(spec) + spec['General'] = {'OutputFormat': 'parquet'} + ServiceXSpec.model_validate(spec) + spec['General'] = {'OutputFormat': OutputFormat.root_ttree} + ServiceXSpec.model_validate(spec) + spec['General'] = {'OutputFormat': OutputFormat.parquet} + ServiceXSpec.model_validate(spec) + with pytest.raises(ValidationError): + spec['General'] = {'OutputFormat': 'root-tree'} + ServiceXSpec.model_validate(spec) + + def test_rucio_did(): spec = ServiceXSpec.model_validate( basic_spec( diff --git a/tests/test_dataset_group.py b/tests/test_dataset_group.py index f603decf..9fa2ad6a 100644 --- a/tests/test_dataset_group.py +++ b/tests/test_dataset_group.py @@ -29,7 +29,7 @@ import pytest -from servicex import ResultFormat +from servicex.models import ResultFormat from servicex.dataset_group import DatasetGroup from servicex.query_core import ServiceXException From c32b49bb81a4cbb3a290ba4831bb190c0c48f881 Mon Sep 17 00:00:00 2001 From: Peter Onyisi Date: Wed, 2 Oct 2024 15:33:05 +0000 Subject: [PATCH 2/2] Mention the enums in the documentation --- docs/transform_request.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/transform_request.rst b/docs/transform_request.rst index 56fdcad0..00b0ac9f 100644 --- a/docs/transform_request.rst +++ b/docs/transform_request.rst @@ -32,7 +32,7 @@ The General Section ^^^^^^^^^^^^^^^^^^^ The General section of the request includes the following fields: -* (Optional) ``OutputFormat``: Can be ``root-ttree`` (default) or ``parquet`` +* (Optional) ``OutputFormat``: Can be ``root-ttree`` (default) or ``parquet`` (you can also use the enums ``servicex.OutputFormat.root_ttree`` and ``servicex.OutputFormat.parquet``) * (Optional) ``Delivery``: Can be ``URLs`` or ``LocalCache`` (default) In general, if you are running on your laptop away from the ServiceX site and are working with a small amount of