Skip to content

Commit

Permalink
global: merging changes upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnmag committed Oct 12, 2016
2 parents 7526c3a + 5f29094 commit e1d6af6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
15 changes: 12 additions & 3 deletions hepdata_validator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from jsonschema import validate, ValidationError
import yaml
from yaml.scanner import ScannerError
from yaml.parser import ParserError

from .version import __version__
Expand Down Expand Up @@ -35,9 +36,17 @@ def validate(self, **kwargs):
if data is None:

try:
data = yaml.load(open(file_path, 'r'), Loader=yaml.CLoader)
except: # pragma: no cover
data = yaml.load(open(file_path, 'r')) # pragma: no cover
try:
data = yaml.load(open(file_path, 'r'), Loader=yaml.CLoader)
except ScannerError as se:
self.add_validation_message(ValidationMessage(file=file_path, message=str(se)))
return False
except: #pragma: no cover
try: #pragma: no cover
data = yaml.load(open(file_path, 'r')) #pragma: no cover
except ScannerError as se: #pragma: no cover
self.add_validation_message(ValidationMessage(file=file_path, message=str(se))) #pragma: no cover
return False #pragma: no cover

try:
validate(data, schema)
Expand Down
5 changes: 3 additions & 2 deletions hepdata_validator/submission_file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def validate(self, **kwargs):
except ScannerError as se:
self.add_validation_message(
ValidationMessage(file=file_path,
message='There was a problem parsing the file. '
message='There was a problem parsing the file. '
'This can be because you forgot spaces '
'after colons in your YAML file for instance.')
'after colons in your YAML file for instance. '
'Diagnostic information follows.\n' + str(se))
)
29 changes: 29 additions & 0 deletions testsuite/test_data/invalid_data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
independent_variables:
- header: {name: SQRT(S), units: GEV}
values:
- value: 7000
- value: 8000
- value: 9000
dependent_variables:
- header: {name: SIG(fiducial), units: FB}
qualifiers:
- {name: RE, value: P P --> Z0 < LEPTON+ LEPTON- > Z0 < LEPTON+ LEPTON- > X}
values:
- value: 25.4
errors:
- {asymerror: {plus: 3.3, minus: -3.0}, label: stat}
- {asymerror: {plus: 1, minus: -1.2}, label: sys}
- {asymerror: {plus: 1, minus: -1}, label: 'sys,lumi'}

- value: 29.8
errors:
- {asymerror: {plus: 3.8, minus: -3.5}, label: stat}
- {asymerror: {plus: 1.7, minus: -1.5}, label: sys}
- {symerror: 1.2, label: 'sys,lumi'}

- value: 12.7
errors:
- {asymerror:{plus: 3.1, minus: -2.9}, label: stat}
- {symerror: 1.7, label: sys}
- {symerror: 0.5, label: 'sys,lumi'}
12 changes: 12 additions & 0 deletions testsuite/validation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def setUp(self):
'test_data/valid_data_with_error.yaml'
)

self.invalid_data_yaml = os.path.join(
self.base_dir,
'test_data/invalid_data.yaml'
)

def test_valid_yaml_file(self):
print '___DATA_VALIDATION: Testing valid yaml submission___'
is_valid = self.validator.validate(file_path=self.valid_file_yaml)
Expand Down Expand Up @@ -141,6 +146,13 @@ def test_invalid_json_file(self):
self.validator.print_errors(self.invalid_file_json)
print 'Invalid\n'

def test_invalid_data_file(self):
print '___DATA_VALIDATION: Testing invalid data file___'
self.assertEqual(self.validator.validate(file_path=self.invalid_data_yaml),
False)
self.validator.print_errors(self.invalid_data_yaml)
print 'Invalid\n'


if __name__ == '__main__':
unittest.main()

0 comments on commit e1d6af6

Please sign in to comment.