Skip to content

Commit

Permalink
Fix validate for inquiry (#1557)
Browse files Browse the repository at this point in the history
* Fix for inquiry validate

* add tests

* Add InquiryResource file

* Export InquiryResource

* Fixed implementation

---------

Co-authored-by: roll <[email protected]>
  • Loading branch information
shashigharti and roll authored Jul 11, 2023
1 parent bee2303 commit b7d6ccc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions frictionless/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .file import *
from .inquiry import *
from .json import *
from .metadata import *
from .package import *
Expand Down
38 changes: 38 additions & 0 deletions frictionless/resources/inquiry.py
Original file line number Diff line number Diff line change
@@ -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,
)
6 changes: 0 additions & 6 deletions frictionless/resources/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions tests/console/commands/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit b7d6ccc

Please sign in to comment.