Skip to content

Commit

Permalink
Add uniqueness check in doi/recid entry
Browse files Browse the repository at this point in the history
Adds a uniqueness check in the related DOI and record ID entries in the schema. Also adds testing against this functionality.
  • Loading branch information
ItIsJordan committed Aug 11, 2023
1 parent 5e1afa0 commit e8064a2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Expand Up @@ -19,6 +19,7 @@
},
"related_to_hepdata_recids" : {
"type" : "array",
"uniqueItems": true,
"items" : {"type" : "integer", "minimum": 1}
},
"preprintyear": {
Expand Down
1 change: 1 addition & 0 deletions hepdata_validator/schemas/1.1.1/submission_schema.json
Expand Up @@ -8,6 +8,7 @@
"name": { "type": "string", "maxLength": 64 },
"related_to_table_dois" : {
"type" : "array",
"uniqueItems": true,
"items" : {"type" : "string", "maxLength" : 128, "pattern" : "^10\\.17182\/hepdata\\.\\d+\\.v\\d+\/t\\d+$" }
},
"location": { "type": "string", "maxLength": 256 },
Expand Down
Expand Up @@ -11,4 +11,6 @@ related_to_table_dois:
- "10.17182/hepdata.1"
- "10.17182/hepdata.1.v1"
- "10.17182/hepdata.1.v1/"
- "10.17182/hepdata.1.v1/a2"
- "10.17182/hepdata.1.v1/a2"
- "10.17182/hepdata.1.v1/t1"
- "10.17182/hepdata.1.v1/t1"
@@ -1,6 +1,6 @@
---
comment: "Test Text"
related_to_hepdata_recids: ["a", a, 0]
related_to_hepdata_recids: ["a", b, 0, 1, 1]
---
name: "Table 1"
description: Words
Expand Down
12 changes: 8 additions & 4 deletions testsuite/test_submission_validator.py
Expand Up @@ -354,8 +354,9 @@ def test_related_submissions(validator_v1, data_path, capsys):
"file": "invalid_submission_recid.yaml",
"errors": [
"'a' is not of type 'integer'",
"'a' is not of type 'integer'",
"0 is less than the minimum of 1"
"'b' is not of type 'integer'",
"0 is less than the minimum of 1",
"has non-unique elements in 'related_to_hepdata_recids'"
]},
{
"file": "invalid_submission_doi.yaml",
Expand All @@ -364,7 +365,8 @@ def test_related_submissions(validator_v1, data_path, capsys):
"'10.17182/hepdata.1' does not match",
"'10.17182/hepdata.1.v1' does not match",
"'10.17182/hepdata.1.v1/' does not match",
"'10.17182/hepdata.1.v1/a2'"
"'10.17182/hepdata.1.v1/a2' does not match",
"has non-unique elements in 'related_to_table_dois'"
]}]

for yfile in yaml_files:
Expand All @@ -381,9 +383,11 @@ def test_related_submissions(validator_v1, data_path, capsys):

if yfile["errors"]:
assert is_valid is False
# Should be the same amount of errors as expected
assert len(error_list) == len(yfile["errors"])
# Then check against the expected errors
for error in error_list:
assert any(yerrors in error for yerrors in yfile['errors'])
else:
# If there is no expected error, then it should be valid
assert is_valid
assert is_valid

0 comments on commit e8064a2

Please sign in to comment.