def test_no_journal_macro(self): # test by passing replacing journal macros for journal names # bibTex format # display full journal name bibtex_export = BibTexFormat(solrdata.data_5, "%R").get(include_abs=False, maxauthor=10, authorcutoff=200, journalformat=3).get('export', '') bibtex_full_journal_name = u'@ARTICLE{2018PhRvL.120b9901P,\n author = {{Pustilnik}, M. and {van Heck}, B. and {Lutchyn}, R.~M. and\n {Glazman}, L.~I.},\n title = "{Erratum: Quantum Criticality in Resonant Andreev Conduction [Phys. Rev. Lett. 119, 116802 (2017)]}",\n journal = {Physical Review Letters},\n year = 2018,\n month = jan,\n volume = {120},\n number = {2},\n eid = {029901},\n pages = {029901},\n doi = {10.1103/PhysRevLett.120.029901},\n adsurl = {https://ui.adsabs.harvard.edu/abs/2018PhRvL.120b9901P},\n adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n}\n\n' assert (bibtex_export == bibtex_full_journal_name) # display abbreviated journal name bibtex_export = BibTexFormat(solrdata.data_5, "%R").get(include_abs=False, maxauthor=10, authorcutoff=200, journalformat=2).get('export', '') bibtex_abbrev_journal_name = u'@ARTICLE{2018PhRvL.120b9901P,\n author = {{Pustilnik}, M. and {van Heck}, B. and {Lutchyn}, R.~M. and\n {Glazman}, L.~I.},\n title = "{Erratum: Quantum Criticality in Resonant Andreev Conduction [Phys. Rev. Lett. 119, 116802 (2017)]}",\n journal = {PhRvL},\n year = 2018,\n month = jan,\n volume = {120},\n number = {2},\n eid = {029901},\n pages = {029901},\n doi = {10.1103/PhysRevLett.120.029901},\n adsurl = {https://ui.adsabs.harvard.edu/abs/2018PhRvL.120b9901P},\n adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n}\n\n' assert (bibtex_export == bibtex_abbrev_journal_name) # macro (default) bibtex_export = BibTexFormat(solrdata.data_5, "%R").get(include_abs=False, maxauthor=10, authorcutoff=200, journalformat=0).get('export', '') bibtex_default_journal_name = u'@ARTICLE{2018PhRvL.120b9901P,\n author = {{Pustilnik}, M. and {van Heck}, B. and {Lutchyn}, R.~M. and\n {Glazman}, L.~I.},\n title = "{Erratum: Quantum Criticality in Resonant Andreev Conduction [Phys. Rev. Lett. 119, 116802 (2017)]}",\n journal = {\\prl},\n year = 2018,\n month = jan,\n volume = {120},\n number = {2},\n eid = {029901},\n pages = {029901},\n doi = {10.1103/PhysRevLett.120.029901},\n adsurl = {https://ui.adsabs.harvard.edu/abs/2018PhRvL.120b9901P},\n adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n}\n\n' assert (bibtex_export == bibtex_default_journal_name) # aastex format # display full journal name csl_export = CSL(CSLJson(solrdata.data_5).get(), 'aastex', adsFormatter.latex, adsJournalFormat.full).get().get('export', '') # now compare it with an already formatted data that we know is correct aastex_full_journal_name = u'\\bibitem[Pustilnik et al.(2018)]{2018PhRvL.120b9901P} Pustilnik, M., van Heck, B., Lutchyn, R.~M., et al.\\ 2018, Physical Review Letters, 120, 029901\n' assert (csl_export == aastex_full_journal_name) # display full journal name csl_export = CSL(CSLJson(solrdata.data_5).get(), 'aastex', adsFormatter.latex, adsJournalFormat.abbreviated).get().get('export', '') # now compare it with an already formatted data that we know is correct aastex_abbrev_journal_name = u'\\bibitem[Pustilnik et al.(2018)]{2018PhRvL.120b9901P} Pustilnik, M., van Heck, B., Lutchyn, R.~M., et al.\\ 2018, PhRvL, 120, 029901\n' assert (csl_export == aastex_abbrev_journal_name) # display full journal name csl_export = CSL(CSLJson(solrdata.data_5).get(), 'aastex', adsFormatter.latex, adsJournalFormat.default).get().get('export', '') # now compare it with an already formatted data that we know is correct aastex_default_journal_name = u'\\bibitem[Pustilnik et al.(2018)]{2018PhRvL.120b9901P} Pustilnik, M., van Heck, B., Lutchyn, R.~M., et al.\\ 2018, \\prl, 120, 029901\n' assert (csl_export == aastex_default_journal_name)
def test_bibtex_enumeration(self): # test bibtex key_format enumeration bibtex_export = BibTexFormat(solrdata.data_6, "%1H%Y%zm") key_formats_enumerated = [ 'Accomazzi2020', 'Accomazzi2019a', 'Accomazzi2015', 'Accomazzi2019b', 'Accomazzi2019c', 'Accomazzi2018a', 'Accomazzi2018b', 'Accomazzi2017', 'Accomazzi2018c', 'Accomazzi2018d' ] assert (bibtex_export._BibTexFormat__enumerate_keys() == key_formats_enumerated)
def return_bibTex_format_export(solr_data, include_abs, request_type='POST'): """ :param include_abs: :return: """ if (solr_data is not None): if ('error' in solr_data): return return_response({'error': 'unable to query solr'}, 400) bibTex_export = BibTexFormat(solr_data) return return_response(bibTex_export.get(include_abs=include_abs), 200, request_type) return return_response({'error': 'no result from solr'}, 404)
def test_bibtex_with_abs(self): # format the stubdata using the code bibtex_export = BibTexFormat(solrdata.data, "%R").get(include_abs=True, maxauthor=0, authorcutoff=200, journalformat=1) # now compare it with an already formatted data that we know is correct assert (bibtex_export == bibTexTest.data_with_abs)
def return_bibTex_format_export(solr_data, include_abs, keyformat, maxauthor, authorcutoff, journalformat, request_type='POST'): """ :param include_abs: :return: """ if (solr_data is not None): bibTex_export = BibTexFormat(solr_data, keyformat=keyformat) return return_response( bibTex_export.get(include_abs=include_abs, maxauthor=maxauthor, authorcutoff=authorcutoff, journalformat=journalformat), 200, request_type) return return_response({'error': 'no result from solr'}, 404)
def test_bibtex_keyformat(self): solr_data = \ { "responseHeader": { "status": 0, "QTime": 51, "params": { "q": "author:\"^accomazzi\" year:2019", "indent": "on", "fl": "bibcode,author,pub,year", "wt": "json", "_": "1560183872951"}}, "response": {"numFound": 3, "start": 0, "docs": [ { "year": "2019", "bibcode": "2019AAS...23338108A", "bibstem": ["AAS", "AAS...233"], "author": ["Accomazzi, Alberto", "Kurtz, Michael J.", "Henneken, Edwin", "Grant, Carolyn S.", "Thompson, Donna M.", "Chyla, Roman", "McDonald, Stephen", "Blanco-Cuaresma, Sergi", "Shapurian, Golnaz", "Hostetler, Timothy", "Templeton, Matthew", "Lockhart, Kelly"], "pub": "American Astronomical Society Meeting Abstracts #233"}, { "year": "2019", "bibcode": "2019AAS...23320704A", "bibstem":["AAS", "AAS...233"], "author": ["Accomazzi, Alberto"], "pub": "American Astronomical Society Meeting Abstracts #233"}, { "year":"2019", "bibcode":"2019hsax.conf..526G", "author":["Garzón, F.", "Patrick, L.", "Hammersley, P.", "Streblyanska, A.", "Insausti, M.", "Barreto, M.", "Fernández, P.", "Joven, E.", "López, P.", "Mato, A.", "Moreno, H.", "Núñez, M.", "Patrón, J.", "Pascual, S.", "Cardiel, N."], "pub":"Highlights on Spanish Astrophysics X", "bibstem":["hsax", "hsax.conf"] } ]} } bibtex_export = BibTexFormat(solr_data, "%1H:%Y:%q") # both author and title exists assert(bibtex_export._BibTexFormat__format_key(solr_data['response'].get('docs')[0]) == 'Accomazzi:2019:AAS') # verify that key is ascii assert(bibtex_export._BibTexFormat__format_key(solr_data['response'].get('docs')[2]) == 'Garzon:2019:hsax')
def test_bibtex_with_abs(self): # format the stubdata using the code bibtex_export = BibTexFormat(solrdata.data).get(include_abs=True) # now compare it with an already formatted data that we know is correct assert (bibtex_export == bibTexTest.data_with_abs)