def test_reverse_doi_results(self, monkeypatch, event_loop): fake_return = (4, [ {'title': 'foo', 'DOI': '1234'}, {'title': 'Bar', 'DOI': 'abcd'}, {'title': 'This is almost the correct titel', 'DOI': 'fuzzy'}, {'title': 'CASE SHOULD BE IRRELEVANT', 'DOI': 'case'} ]) mock_retrieval = MagicMock() mock_search = MagicMock() mock_search.search_publication = MagicMock(return_value=fake_return) monkeypatch.setattr(crossref_commons, "retrieval", mock_retrieval) monkeypatch.setattr(crossref_commons, "search", mock_search) cs = CrossrefSource(SilentUI()) e = make_entry({'title': 'Bar'}) result = event_loop.run_until_complete(cs.get_doi(e)) mock_search.search_publication.assert_called_with( [('bibliographic', 'Bar')], order='desc', sort='relevance' ) assert result[0] == "abcd" e = make_entry({'title': 'This is almost the correct title'}) result = event_loop.run_until_complete(cs.get_doi(e)) assert result[0] == "fuzzy" e = make_entry({'title': 'case should be irrelevant'}) result = event_loop.run_until_complete(cs.get_doi(e)) assert result[0] == "case"
def test_repeating(self, datadir, event_loop): set_config({'unify_booktitle': [ [r'(?P<prefix>.*) remove(?P<suffix>.*)', r'{prefix}{suffix}', 'priority:50', 'repeat', 'kind:plain'], ]}) unify_me = make_entry( {'booktitle': ('Proceedings remove of remove some remove conference')}) u = Unifier() sugg = u.unify_entry(unify_me) assert (sugg.data['booktitle'][0] == ((r'Proceedings of some conference'), Suggestion.KIND_PLAIN)) # Test repeat-unifying suggestion sugg = Suggestion('test', unify_me) sugg.add_field('booktitle', 'Proceedings remove of remove some remove conference') u.unify_suggestion(sugg) assert(sugg.data['booktitle'][0] == ('Proceedings of some conference', Suggestion.KIND_PLAIN))
def test_chaining(self, datadir, event_loop): set_config({'unify_booktitle': [ [r'(?P<prefix>.*)first(?P<suffix>.*)', r'{prefix}1st{suffix}', 'kind:plain', 'priority:50'], [r'(?P<prefix>.*) IEEE(?P<suffix>.*)', r'{prefix}{suffix}', 'kind:regex'] ]}) unify_me = make_entry( {'booktitle': ('Proceedings of the first IEEE conference on whatever')}) u = Unifier() sugg = u.unify_entry(unify_me) assert (sugg.data['booktitle'][0] == ((r'Proceedings of the 1st conference on whatever'), Suggestion.KIND_RE)) # Test chain-unifying suggestion sugg = Suggestion('test', unify_me) sugg.add_field('booktitle', ('Proceedings of the first' ' IEEE conference on whatever')) u.unify_suggestion(sugg) assert(sugg.data['booktitle'][0] == (r'Proceedings of the 1st conference on whatever', Suggestion.KIND_RE))
def test_list_ignore_order(self, datadir): e = make_entry({ 'title': 'This is some title.', 'issn': '1234-5678, 2345-67890' }) s = Suggestion('test', e) s.add_field('title', 'This is some title.') s.add_field('issn', '2345-67890, 1234-5678') d = Differ(e) result = d.diff(s) assert result == []
def test_reverse_doi_calls(self, monkeypatch, event_loop): mock_retrieval = MagicMock() mock_search = MagicMock() mock_search.search_publication = MagicMock(return_value=(0, [])) monkeypatch.setattr(crossref_commons, "retrieval", mock_retrieval) monkeypatch.setattr(crossref_commons, "search", mock_search) cs = CrossrefSource(SilentUI()) e = make_entry({'title': 'Testtitle', 'author': 'John Doe'}) event_loop.run_until_complete(cs.get_doi(e)) mock_search.search_publication.assert_any_call( [('bibliographic', 'Testtitle'), ('author', 'John Doe')], order='desc', sort='relevance' ) mock_search.search_publication.reset_mock() e = make_entry({'title': 'Testtitle'}) event_loop.run_until_complete(cs.get_doi(e)) mock_search.search_publication.assert_called_with( [('bibliographic', 'Testtitle')], order='desc', sort='relevance' )
def test_query_calls(self, monkeypatch, event_loop): mock_retrieval = MagicMock() mock_search = MagicMock() mock_retrieval.get_publication_as_json = MagicMock() monkeypatch.setattr(crossref_commons, "retrieval", mock_retrieval) monkeypatch.setattr(crossref_commons, "search", mock_search) def side_effect(doi): raise ValueError() mock_retrieval.get_publication_as_json.side_effect = side_effect cs = CrossrefSource(SilentUI()) e = make_entry({'doi': '1234'}) result = event_loop.run_until_complete(cs.query(e)) mock_retrieval.get_publication_as_json.assert_called_with( '1234' )
def test_unify_entry(self, datadir, event_loop): set_config({'unify_booktitle': [ [r'\d{4} IEEE (?P<name>[^\(]*) \((?P<short>[^\)]*)\)', r'Proceedings of the \d*(th|st|nd|rd) {name} \({short}.*\)'], ]}) unify_me = make_entry( {'booktitle': ('2016 IEEE International Parallel and' ' Distributed Processing Symposium (IPDPS)')}) u = Unifier() sugg = u.unify_entry(unify_me) assert (sugg.data['booktitle'][0] == (r'Proceedings of the \d*(th|st|nd|rd)' r' International Parallel and Distributed' r' Processing Symposium \(IPDPS.*\)', Suggestion.KIND_RE))
def test_re_suggestion(self, datadir): e = make_entry({ 'title': 'This is some title.', 'booktitle': "Proceedings of the 20th Conference on Something Awesome (CSA'20)" }) s = Suggestion('test', e) s.add_field('title', 'This is some title.', kind=Suggestion.KIND_RE) s.add_field('booktitle', r'Proceedings of the \d+(th|st|rd|nd) .* \(.*\)', kind=Suggestion.KIND_RE) d = Differ(e) result = d.diff(s) assert result == [] s = Suggestion('nonmatching_test', e) s.add_field('booktitle', r'Nope', kind=Suggestion.KIND_RE) result = d.diff(s) assert len(result) == 1