1
1
import os
2
2
import pytest
3
3
import yaml
4
- from hepdata_validator import VALID_SCHEMA_VERSIONS
4
+ from hepdata_validator import VALID_SCHEMA_VERSIONS , YamlLoader
5
5
from hepdata_validator .submission_file_validator import SubmissionFileValidator
6
6
7
- # We try to load using the CSafeLoader for speed improvements.
8
- try :
9
- from yaml import CSafeLoader as Loader
10
- except ImportError :
11
- from yaml import SafeLoader as Loader
12
-
13
7
14
8
####################################################
15
9
# Tests fixtures #
@@ -45,7 +39,7 @@ def test_valid_submission_yaml_v0(validator_v0, data_path):
45
39
file = os .path .join (data_path , 'valid_submission_v0.yaml' )
46
40
47
41
with open (file , 'r' ) as submission :
48
- yaml_obj = yaml .load_all (submission , Loader = Loader )
42
+ yaml_obj = yaml .load_all (submission , Loader = YamlLoader )
49
43
is_valid = validator_v0 .validate (file_path = file , data = yaml_obj )
50
44
validator_v0 .print_errors (file )
51
45
@@ -65,7 +59,7 @@ def test_valid_submission_yaml_v1(validator_v1, data_path):
65
59
file = os .path .join (data_path , 'valid_submission.yaml' )
66
60
67
61
with open (file , 'r' ) as submission :
68
- yaml_obj = yaml .load_all (submission , Loader = Loader )
62
+ yaml_obj = yaml .load_all (submission , Loader = YamlLoader )
69
63
is_valid = validator_v1 .validate (file_path = file , data = yaml_obj )
70
64
validator_v1 .print_errors (file )
71
65
@@ -80,7 +74,7 @@ def test_v0_valid_submission_yaml_v1(validator_v1, data_path):
80
74
file = os .path .join (data_path , 'valid_submission_v0.yaml' )
81
75
82
76
with open (file , 'r' ) as submission :
83
- yaml_obj = yaml .load_all (submission , Loader = Loader )
77
+ yaml_obj = yaml .load_all (submission , Loader = YamlLoader )
84
78
is_valid = validator_v1 .validate (file_path = file , data = yaml_obj )
85
79
validator_v1 .print_errors (file )
86
80
@@ -235,10 +229,11 @@ def test_invalid_parser_submission_yaml_v1(validator_v1, data_path, capsys):
235
229
236
230
assert is_valid is False
237
231
out , err = capsys .readouterr ()
238
- assert out .strip () == """error - while parsing a flow mapping
239
- in "{0}", line 6, column 5
240
- did not find expected ',' or '}}'
241
- in "{0}", line 7, column 3""" .format (file )
232
+ assert out .strip ().startswith (f"""error - while parsing a flow mapping
233
+ in "{ file } ", line 6, column 5""" )
234
+ # message is different in libyaml and non-libyaml versions but this is in both
235
+ assert "expected ',' or '}'" in out
236
+ assert out .strip ().endswith (f'in "{ file } ", line 7, column 3' )
242
237
243
238
244
239
def test_io_error_submission_yaml_v1 (validator_v1 , data_path , capsys ):
@@ -284,7 +279,7 @@ def test_data_schema_submission_yaml_v1(validator_v1, data_path):
284
279
file = os .path .join (data_path , 'valid_submission_custom_remote.yaml' )
285
280
286
281
with open (file , 'r' ) as submission :
287
- yaml_obj = yaml .load_all (submission , Loader = Loader )
282
+ yaml_obj = yaml .load_all (submission , Loader = YamlLoader )
288
283
is_valid = validator_v1 .validate (file_path = file , data = yaml_obj )
289
284
assert is_valid is True
290
285
assert not validator_v1 .has_errors (file )
@@ -298,7 +293,7 @@ def test_invalid_cmenergies_submission_yaml_v1(validator_v1, data_path, capsys):
298
293
file = os .path .join (data_path , 'invalid_cmenergies.yaml' )
299
294
300
295
with open (file , 'r' ) as submission :
301
- yaml_obj = yaml .load_all (submission , Loader = Loader )
296
+ yaml_obj = yaml .load_all (submission , Loader = YamlLoader )
302
297
is_valid = validator_v1 .validate (file_path = file , data = yaml_obj )
303
298
validator_v1 .print_errors (file )
304
299
@@ -332,7 +327,7 @@ def test_check_for_duplicates(validator_v1):
332
327
def test_submission_with_no_data_tables (validator_v0 , validator_v1 , data_path , capsys ):
333
328
file = os .path .join (data_path , 'valid_file.yaml' )
334
329
with open (file , 'r' ) as submission :
335
- yaml_obj = yaml .load_all (submission , Loader = Loader )
330
+ yaml_obj = yaml .load_all (submission , Loader = YamlLoader )
336
331
is_valid = validator_v1 .validate (file_path = file , data = yaml_obj )
337
332
validator_v1 .print_errors (file )
338
333
0 commit comments