diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 496423d5a0..2fce4159f3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ hatch config set 'dirs.env.virtual' '.python' Now you can setup you IDE to use a proper Python path: ```bash -.python/fdapp/bin/python +.python/frictionless/bin/python ``` Enter the virtual environment before starting the work. It will ensure that all the development dependencies are installed into a virtual environment: diff --git a/frictionless/resources/__init__.py b/frictionless/resources/__init__.py index 6c6582a05c..43ac032809 100644 --- a/frictionless/resources/__init__.py +++ b/frictionless/resources/__init__.py @@ -1,4 +1,5 @@ from .file import * +from .inquiry import * from .json import * from .metadata import * from .package import * diff --git a/frictionless/resources/inquiry.py b/frictionless/resources/inquiry.py new file mode 100644 index 0000000000..f1cd867277 --- /dev/null +++ b/frictionless/resources/inquiry.py @@ -0,0 +1,38 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from .. import settings +from ..exception import FrictionlessException +from ..inquiry import Inquiry +from ..report import Report +from .metadata import MetadataResource + +if TYPE_CHECKING: + from .. import types + from ..checklist import Checklist + + +class InquiryResource(MetadataResource[Inquiry]): + datatype = "inquiry" + dataclass = Inquiry + + # Validate + + def validate( + self, + checklist: Optional[Checklist] = None, + *, + name: Optional[str] = None, + on_row: Optional[types.ICallbackFunction] = None, + parallel: bool = False, + limit_rows: Optional[int] = None, + limit_errors: int = settings.DEFAULT_LIMIT_ERRORS, + ) -> Report: + try: + inquiry = self.read_metadata() + except FrictionlessException as exception: + return Report.from_validation(errors=exception.to_errors()) + return inquiry.validate( + parallel=parallel, + ) diff --git a/frictionless/resources/metadata.py b/frictionless/resources/metadata.py index aa0483eb13..59e6a9c2ad 100644 --- a/frictionless/resources/metadata.py +++ b/frictionless/resources/metadata.py @@ -7,7 +7,6 @@ from ..checklist import Checklist from ..dialect import Dialect from ..exception import FrictionlessException -from ..inquiry import Inquiry from ..metadata import Metadata from ..pipeline import Pipeline from ..platform import platform @@ -83,11 +82,6 @@ class PipelineResource(MetadataResource[Pipeline]): dataclass = Pipeline -class InquiryResource(MetadataResource[Inquiry]): - datatype = "inquiry" - dataclass = Inquiry - - class ReportResource(MetadataResource[Report]): datatype = "report" dataclass = Report diff --git a/tests/console/commands/test_validate.py b/tests/console/commands/test_validate.py index f7cb9161db..423e527102 100644 --- a/tests/console/commands/test_validate.py +++ b/tests/console/commands/test_validate.py @@ -259,6 +259,13 @@ def test_console_validate_dialect_overrided_issue_1478(): assert actual.exit_code == 0 +def test_console_validate_inquiry(): + actual = runner.invoke(console, "validate data/inquiry.yaml") + assert actual.exit_code == 1 + assert actual.stdout.count("data/capital-valid.csv") + assert actual.stdout.count("data/capital-invalid.csv") + + # Helpers