def test_prepare_keywords_does_nothing_if_no_keywords_were_predicted(): schema = load_schema('hep') subschema = schema['properties']['keywords'] data = { 'keywords': [ { 'schema': 'INSPIRE', 'value': 'field theory: conformal', }, ], } extra_data = {} assert validate(data['keywords'], subschema) is None obj = MockObj(data, extra_data) eng = MockEng() assert prepare_keywords(obj, eng) is None expected = [ { 'schema': 'INSPIRE', 'value': 'field theory: conformal', }, ] result = obj.data assert validate(result['keywords'], subschema) is None assert expected == result['keywords']
def test_prepare_keywords_does_nothing_if_no_keywords_were_predicted(): schema = load_schema('hep') subschema = schema['properties']['keywords'] data = { 'keywords': [ { 'schema': 'INSPIRE', 'value': 'field theory: conformal', }, ], } extra_data = {} assert validate(data['keywords'], subschema) is None obj = MockObj(data, extra_data) eng = MockEng() assert prepare_keywords(obj, eng) is None expected = [ { 'schema': 'INSPIRE', 'value': 'field theory: conformal', }, ] result = obj.data assert validate(result['keywords'], subschema) is None assert expected == result['keywords']
def test_prepare_keywords(): schema = load_schema('hep') subschema = schema['properties']['keywords'] data = {} extra_data = { 'keywords_prediction': { 'keywords': [ {'label': 'galaxy'}, {'label': 'numerical calculations'}, ], }, } obj = MockObj(data, extra_data) eng = MockEng() assert prepare_keywords(obj, eng) is None expected = [ { 'source': 'magpie', 'value': 'galaxy', }, { 'source': 'magpie', 'value': 'numerical calculations', }, ] result = obj.data assert validate(result['keywords'], subschema) is None assert expected == result['keywords']
def test_prepare_keywords_appends_to_existing_keywords(): schema = load_schema('hep') subschema = schema['properties']['keywords'] data = { 'keywords': [ { 'schema': 'INSPIRE', 'value': 'field theory: conformal', }, ], } extra_data = { 'keywords_prediction': { 'keywords': [ { 'label': 'expansion 1/N' }, { 'label': 'supergravity' }, ], }, } assert validate(data['keywords'], subschema) is None obj = MockObj(data, extra_data) eng = MockEng() assert prepare_keywords(obj, eng) is None expected = [ { 'schema': 'INSPIRE', 'value': 'field theory: conformal', }, { 'source': 'magpie', 'value': 'expansion 1/N', }, { 'source': 'magpie', 'value': 'supergravity', }, ] result = obj.data assert validate(result['keywords'], subschema) is None assert expected == result['keywords']
def test_prepare_keywords_appends_to_existing_keywords(): schema = load_schema('hep') subschema = schema['properties']['keywords'] data = { 'keywords': [ { 'schema': 'INSPIRE', 'value': 'field theory: conformal', }, ], } extra_data = { 'keywords_prediction': { 'keywords': [ {'label': 'expansion 1/N'}, {'label': 'supergravity'}, ], }, } assert validate(data['keywords'], subschema) is None obj = MockObj(data, extra_data) eng = MockEng() assert prepare_keywords(obj, eng) is None expected = [ { 'schema': 'INSPIRE', 'value': 'field theory: conformal', }, { 'source': 'magpie', 'value': 'expansion 1/N', }, { 'source': 'magpie', 'value': 'supergravity', }, ] result = obj.data assert validate(result['keywords'], subschema) is None assert expected == result['keywords']
def test_prepare_keywords(): schema = load_schema('hep') subschema = schema['properties']['keywords'] data = {} extra_data = { 'keywords_prediction': { 'keywords': [ { 'label': 'galaxy' }, { 'label': 'numerical calculations' }, ], }, } obj = MockObj(data, extra_data) eng = MockEng() assert prepare_keywords(obj, eng) is None expected = [ { 'source': 'magpie', 'value': 'galaxy', }, { 'source': 'magpie', 'value': 'numerical calculations', }, ] result = obj.data assert validate(result['keywords'], subschema) is None assert expected == result['keywords']