Skip to content

Commit

Permalink
Merge pull request #51 from HEPData/invalidate-only-independent
Browse files Browse the repository at this point in the history
Invalidate case of only independent_variables
  • Loading branch information
GraemeWatt authored Jun 6, 2023
2 parents 30e6daf + 74bf334 commit 8a56cb8
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
:alt: GitHub Issues

.. image:: https://readthedocs.org/projects/hepdata-validator/badge/?version=latest
:target: http://hepdata-validator.readthedocs.io/en/latest/?badge=latest
:target: https://hepdata-validator.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

JSON schema and validation code (in Python 3) for HEPData submissions

* Documentation: http://hepdata-validator.readthedocs.io
* Documentation: https://hepdata-validator.readthedocs.io


Installation
Expand Down
1 change: 0 additions & 1 deletion hepdata_validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import abc
import os

from jsonschema import validate as json_validate, ValidationError
from jsonschema.validators import validator_for
from jsonschema.exceptions import by_relevance
from packaging import version as packaging_version
Expand Down
10 changes: 9 additions & 1 deletion hepdata_validator/data_file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def check_length_values(self, file_path, data):
"""
Check that the length of the 'values' list is consistent for
each of the independent_variables and dependent_variables.
Adds validation error if uncertainties are all zero.
Invalidate only independent_variables but no dependent_variables.
:param data: data table in YAML format
"""
Expand All @@ -260,6 +260,14 @@ def check_length_values(self, file_path, data):
instance=data
)
self.add_validation_error(file_path, error)
if indep_count and not dep_count: # only independent_variables
error = ValidationError(
"Case of only independent_variables but no dependent_variables is not supported: " +
"independent_variables %s, dependent_variables %s" % (str(indep_count), str(dep_count)),
instance=data
)
self.add_validation_error(file_path, error)


def convert_to_float(self, error, file_path, path, instance):
"""
Expand Down
128 changes: 128 additions & 0 deletions testsuite/test_data/binning_average.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
dependent_variables: []
independent_variables:
- header:
name: Bin
values:
- value: 0
- value: 1
- value: 2
- value: 3
- value: 4
- value: 5
- value: 6
- value: 7
- value: 8
- value: 9
- value: 10
- value: 11
- value: 12
- value: 13
- value: 14
- value: 15
- value: 16
- value: 17
- value: 18
- value: 19
- value: 20
- value: 21
- value: 22
- value: 23
- value: 24
- value: 25
- value: 26
- value: 27
- value: 28
- value: 29
- value: 30
- value: 31
- value: 32
- value: 33
- value: 34
- value: 35
- value: 36
- value: 37
- value: 38
- value: 39
- header:
name: Bin
values:
- high: 1.05
low: 1.0
- high: 1.1
low: 1.05
- high: 1.15
low: 1.1
- high: 1.2
low: 1.15
- high: 1.25
low: 1.2
- high: 1.3
low: 1.25
- high: 1.35
low: 1.3
- high: 1.4
low: 1.35
- high: 1.45
low: 1.4
- high: 1.5035
low: 1.45
- high: -0.8
low: -1.0
- high: -0.6
low: -0.8
- high: -0.4
low: -0.6
- high: -0.2
low: -0.4
- high: 0.0
low: -0.2
- high: 0.2
low: 0.0
- high: 0.4
low: 0.2
- high: 0.6
low: 0.4
- high: 0.8
low: 0.6
- high: 1.0
low: 0.8
- high: -0.8
low: -1.0
- high: -0.6
low: -0.8
- high: -0.4
low: -0.6
- high: -0.2
low: -0.4
- high: 0.0
low: -0.2
- high: 0.2
low: 0.0
- high: 0.4
low: 0.2
- high: 0.6
low: 0.4
- high: 0.8
low: 0.6
- high: 1.0
low: 0.8
- high: 0.62832
low: 0.0
- high: 1.2566
low: 0.62832
- high: 1.885
low: 1.2566
- high: 2.5133
low: 1.885
- high: 3.1416
low: 2.5133
- high: 3.7699
low: 3.1416
- high: 4.3982
low: 3.7699
- high: 5.0265
low: 4.3982
- high: 5.6549
low: 5.0265
- high: 6.2832
low: 5.6549
14 changes: 14 additions & 0 deletions testsuite/test_data_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,20 @@ def test_file_with_inconsistent_values_v1(validator_v1, data_path, capsys):
assert out.strip() == "error - Inconsistent length of 'values' list: independent_variables [1], dependent_variables [2]"


def test_file_with_only_independent_variables_v1(validator_v1, data_path, capsys):
"""
Tests the DataFileValidator V1 against a file with only independent variables
Data file from https://www.hepdata.net/record/ins2624324?version=1&table=Binning%20Average
"""
file = os.path.join(data_path, 'binning_average.yaml')
is_valid = validator_v1.validate(file_path=file)
validator_v1.print_errors(file)

assert is_valid is False
out, err = capsys.readouterr()
assert out.strip() == "error - Case of only independent_variables but no dependent_variables is not supported: independent_variables [40, 40], dependent_variables []"


def test_file_with_invalid_independent_variables_v1(validator_v1, data_path, capsys):
"""
Tests the DataFileValidator V1 against a file with invalid independent variables
Expand Down

0 comments on commit 8a56cb8

Please sign in to comment.