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 set_json_from_solr(self, from_solr): """ save the data from Solr, and go through it for every author format call CSL to style the authors :param from_solr: :return: """ self.from_solr = from_solr if (self.from_solr.get('responseHeader')): self.status = self.from_solr['responseHeader'].get( 'status', self.status) json_for_csl = CSLJson(self.from_solr).get_author() for element in self.parsed_spec: if (element[2] == 'author'): # my mac has been formatted for case-insensitive # so need to make lower case doubled to be different # shall continue with this eventhough on the Linux side we shall be OK if (element[1][-1].isupper()): csl_file_name = 'ads-author-' + element[1][-1] else: csl_file_name = 'ads-author-' + element[1][-1] + element[ 1][-1] key = element[1] self.from_cls[key] = CSL(json_for_csl, csl_file_name).get( adsOrganizer.bibliography) self.author_count[key] = self.__get_num_authors()
def test_tmp_bibcode_format(self): # test bibcodes that have no volume and page but doi for all CSL formats csl_export_output = { 'aastex': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A} Aharon, P.\\ 2005, Geo-Marine Letters. doi:10.1007/s00367-005-0006-y\n', 'icarus': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A} Aharon, P.\\ 2005.\\ Catastrophic flood outbursts in mid-continent left imprints in the Gulf of Mexico.\\ Geo-Marine Letters. doi:10.1007/s00367-005-0006-y\n', 'mnras': u'\\bibitem[\\protect\\citeauthoryear{Aharon}{2005}]{2005GML...tmp....1A} Aharon P., 2005, GML...tmp. doi:10.1007/s00367-005-0006-y\n', 'soph': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A}Aharon, P.: 2005, {\\it Geo-Marine Letters}. doi:10.1007/s00367-005-0006-y.\n', 'aspc': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A} Aharon, P.\\ 2005, Geo-Marine Letters. doi:10.1007/s00367-005-0006-y.\n', 'apsj': u'P. Aharon, (2005). doi:10.1007/s00367-005-0006-y.\n', 'aasj': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A} Aharon, P.\\ 2005, Geo-Marine Letters. doi:10.1007/s00367-005-0006-y.\n', 'ieee': u'[1]Aharon, P., “Catastrophic flood outbursts in mid-continent left imprints in the Gulf of Mexico”, <i>Geo-Marine Letters</i>, 2005. doi:10.1007/s00367-005-0006-y.\n' } cls_default_formats = [adsFormatter.latex ] * 6 + [adsFormatter.unicode] * 2 for style, format in zip(adsCSLStyle.ads_CLS, cls_default_formats): csl_export = CSL(CSLJson(solrdata.data_7).get(), style, format).get().get('export', '') assert (csl_export == csl_export_output[style])
def test_tmp_bibcode_format(self): # test bibcodes that have no volume and page but doi for all CSL formats csl_export_output = { 'aastex': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A} Aharon, P.\\ 2005, Geo-Marine Letters, doi:10.1007/s00367-005-0006-y\n', 'icarus': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A} Aharon, P.\\ 2005.\\ Catastrophic flood outbursts in mid-continent left imprints in the Gulf of Mexico.\\ Geo-Marine Letters doi:10.1007/s00367-005-0006-y.\n', 'mnras': u'\\bibitem[\\protect\\citeauthoryear{Aharon}{2005}]{2005GML...tmp....1A} Aharon P., 2005, GML...tmp, doi:10.1007/s00367-005-0006-y\n', 'soph': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A}Aharon, P.: 2005, {\\it Geo-Marine Letters} {\\bf doi:10.1007/s00367-005-0006-y}.\n', 'aspc': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A} Aharon, P.\\ 2005, Geo-Marine Letters, doi:10.1007/s00367-005-0006-y.\n', 'apsj': u'P. Aharon, {\\bf doi:10.1007/s00367-005-0006-y}, (2005).\n', 'aasj': u'\\bibitem[Aharon(2005)]{2005GML...tmp....1A} Aharon, P.\\ 2005, Geo-Marine Letters, doi:10.1007/s00367-005-0006-y.\n', } for style in adsCSLStyle.ads_CLS: csl_export = CSL(CSLJson(solrdata.data_7).get(), style, adsFormatter.latex).get().get('export', '') assert (csl_export == csl_export_output[style])
def return_csl_format_export(solr_data, csl_style, export_format, journal_format, request_type='POST'): """ :param solr_data: :param csl_style: :param export_format: :param request_type: :return: """ if (solr_data is not None): csl_export = CSL( CSLJson(solr_data).get(), csl_style, export_format, journal_format) return return_response(csl_export.get(), 200, request_type) return return_response({'error': 'no result from solr'}, 404)
def test_aastex(self): # format the stubdata using the code csl_export = CSL(CSLJson(solrdata.data).get(), 'aastex', adsFormatter.latex).get() # now compare it with an already formatted data that we know is correct assert (csl_export == cslTest.data_AASTex)
def test_ieee(self): # format the stubdata using the code csl_export = CSL( CSLJson(solrdata.data).get(), 'ieee', adsFormatter.unicode).get() # now compare it with an already formatted data that we know is correct assert (csl_export == cslTest.data_ieee)