Skip to content

Commit

Permalink
Merge pull request #41 from pepkit/dev
Browse files Browse the repository at this point in the history
Release `0.1.7`
  • Loading branch information
nleroy917 authored Aug 11, 2022
2 parents 0d141f3 + faef3fa commit d6d4184
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ webeido/webeido/uploads
# virtual env's
.env
env
venv
venv
.venv

# tests
out/
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.

## [0.1.7] - 2022-08-11
### Changed
- When a validation fails, `eido` will now return all errors instead of just the first one it finds.

## [0.1.6] - 2022-05-16
### Added
- a possibility to set a custom sample table index with `-s/--st-index` option
Expand Down
2 changes: 1 addition & 1 deletion eido/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.6"
__version__ = "0.1.7"
8 changes: 8 additions & 0 deletions eido/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ class EidoFilterError(EidoException):

def __init__(self, key):
super(EidoFilterError, self).__init__(key)


class EidoValidationError(EidoException):
"""Object was not validated successfully according to schema."""

def __init__(self, message, errors):
super().__init__(message)
self.errors = errors
17 changes: 10 additions & 7 deletions eido/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from copy import deepcopy as dpcpy
from logging import getLogger
from warnings import catch_warnings as cw
from .exceptions import EidoValidationError

import jsonschema
from pandas.core.common import flatten
from ubiquerg import size

from jsonschema import Draft7Validator

from .const import (
ALL_INPUTS_KEY,
FILES_KEY,
Expand All @@ -30,12 +32,13 @@ def _validate_object(object, schema, exclude_case=False):
:param bool exclude_case: whether to exclude validated objects
from the error. Useful when used ith large projects
"""
try:
jsonschema.validate(object, schema)
except jsonschema.exceptions.ValidationError as e:
if not exclude_case:
raise
raise jsonschema.exceptions.ValidationError(e.message)

validator = Draft7Validator(schema)
if not validator.is_valid(object):
errors = sorted(validator.iter_errors(object), key=lambda e: e.path)
raise EidoValidationError(
f"Validation unsuccessful. {len(errors)} errors found.", errors
)


def validate_project(project, schema, exclude_case=False):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/schemas/test_schema_imports.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
imports:
- https://schema.databio.org/pep/2.0.0.yaml
- http://schema.databio.org/pep/2.0.0.yaml
description: Schema for a more restrictive PEP
properties:
samples:
Expand Down
13 changes: 6 additions & 7 deletions tests/test_validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from peppy.utils import load_yaml

from eido import *
from eido.exceptions import EidoValidationError


def _check_remote_file_accessible(url):
Expand All @@ -23,13 +24,13 @@ def test_validate_works(self, project_object, schema_file_path):
validate_project(project=project_object, schema=schema_file_path)

def test_validate_detects_invalid(self, project_object, schema_invalid_file_path):
with pytest.raises(ValidationError):
with pytest.raises(EidoValidationError):
validate_project(project=project_object, schema=schema_invalid_file_path)

def test_validate_detects_invalid_imports(
self, project_object, schema_imports_file_path
):
with pytest.raises(ValidationError):
with pytest.raises(EidoValidationError):
validate_project(project=project_object, schema=schema_imports_file_path)

def test_validate_converts_samples_to_private_attr(
Expand Down Expand Up @@ -80,7 +81,7 @@ def test_validate_raises_error_for_incorrect_sample_name(
def test_validate_detects_invalid(
self, project_object, sample_name, schema_sample_invalid_file_path
):
with pytest.raises(ValidationError):
with pytest.raises(EidoValidationError):
validate_sample(
project=project_object,
sample_name=sample_name,
Expand All @@ -96,9 +97,7 @@ def test_validate_succeeds_on_invalid_sample(


class TestRemoteValidation:
@pytest.mark.parametrize(
"schema_url", ["https://schema.databio.org/pep/2.0.0.yaml"]
)
@pytest.mark.parametrize("schema_url", ["http://schema.databio.org/pep/2.0.0.yaml"])
def test_validate_works_with_remote_schemas(self, project_object, schema_url):
_check_remote_file_accessible(schema_url)
validate_project(project=project_object, schema=schema_url)
Expand Down Expand Up @@ -135,7 +134,7 @@ def test_validate_works(self, schema_file_path, remote_pep_cfg):
)
def test_validate_detects_invalid(self, schema_invalid_file_path, remote_pep_cfg):
_check_remote_file_accessible(remote_pep_cfg)
with pytest.raises(ValidationError):
with pytest.raises(EidoValidationError):
validate_project(
project=Project(remote_pep_cfg),
schema=schema_invalid_file_path,
Expand Down

0 comments on commit d6d4184

Please sign in to comment.