Skip to content

Commit

Permalink
Merge pull request #110 from MJedr/keywords
Browse files Browse the repository at this point in the history
change comparator for keywords
  • Loading branch information
MJedr committed Feb 17, 2022
2 parents 2e87ec5 + 0d7c796 commit 84ccffc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion inspire_json_merger/comparators.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Ret(PrimaryKeyComparator):
TitleComparator = get_pk_comparator(['title'])
URLComparator = get_pk_comparator(['url'])
ValueComparator = get_pk_comparator(['value'])
SchemaValueComparator = get_pk_comparator([['schema', 'value']])


PublicationInfoComparator = get_pk_comparator([
Expand Down Expand Up @@ -146,7 +147,7 @@ class Ret(PrimaryKeyComparator):
'funding_info': FundingInfoComparator,
'imprints': ImprintsComparator,
'isbns': ValueComparator,
'keywords': ValueComparator,
'keywords': SchemaValueComparator,
'license': LicenseComparator,
'new_record': RefComparator,
'persistent_identifiers': PersistentIdentifierComparator,
Expand Down
52 changes: 52 additions & 0 deletions tests/unit/test_comparators.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,55 @@ def test_comparing_publication_info():
assert merged == expected_merged
assert_ordered_conflicts(conflict, expected_conflict)
validate_subschema(merged)


def test_comparing_keywords():
root = {}
head = {
'keywords': [
{
'value': 'shielding',
'schema': 'JACOW',
},
{
'value': 'test',
'schema': 'JACOW',
}
]
}
update = {
'keywords': [
{
'value': 'shielding',
'schema': 'INSPIRE',
},
{
'value': 'shielding',
'schema': 'JACOW',
}
]
}

expected_conflict = []
expected_merged = {
'keywords': [
{
'value': 'shielding',
'schema': 'INSPIRE',
},
{
'value': 'shielding',
'schema': 'JACOW',
},
{
'value': 'test',
'schema': 'JACOW',
},
]
}

merged, conflict = merge(root, head, update, head_source='arxiv')

assert merged == expected_merged
assert_ordered_conflicts(conflict, expected_conflict)
validate_subschema(merged)

0 comments on commit 84ccffc

Please sign in to comment.