示例#1
0
def test_Bib_update_content_bib_info(entries):
    bib1 = bm.Bib(entries['jones_minimal'])
    bib1.bibcode = 'bibcode1'
    bib2 = bm.Bib(entries['jones_minimal'])
    bib1.update_content(bib2)
    # bibcode gets updated to None since it's bibtex info:
    assert bib1.bibcode is None
示例#2
0
def test_Bib_not_equal_both_no_author():
    b1 = bm.Bib('''@MISC{1978windEnergyReport,
        title = "{Wind energy systems: Program summary}",
         year = 1978,
    }''')
    b2 = bm.Bib('''@MISC{1979NewWindEnergyReport,
        title = "{New wind energy systems: Program summary}",
         year = 1979,
    }''')
    assert b2 != b1
示例#3
0
def test_Bib_equal_no_year():
    b1 = bm.Bib('''@Misc{JonesEtal2001scipy,
       author = {Eric Jones},
       title  = {SciPy},
    }''')
    b2 = bm.Bib('''@Misc{JonesEtalScipy_noyear,
       author = {Eric Jones},
       title  = {SciPy},
    }''')
    assert b1 == b2
示例#4
0
def test_Bib_lower_than_both_no_author():
    b1 = bm.Bib('''@MISC{1978windEnergyReport,
        title = "{Wind energy systems: Program summary}",
         year = 1978,
    }''')
    b2 = bm.Bib('''@MISC{1979windEnergyReport,
        title = "{Wind energy systems: Program summary}",
         year = 1979,
    }''')
    assert b2 > b1
示例#5
0
def test_Bib_meta():
    e = '''@Misc{JonesEtal2001scipy,
       author = {Eric Jones},
       title  = {SciPy},
       year   = {2001},
    }'''
    bib = bm.Bib(e)
    assert bib.meta() == ''
    bib = bm.Bib(e, freeze=True, pdf='file.pdf')
    assert bib.meta() == 'freeze\npdf: file.pdf\n'
示例#6
0
def test_Bib_equal_no_author():
    b1 = bm.Bib('''@MISC{1978windEnergyReport,
        title = "{Wind energy systems: Program summary}",
         year = 1978,
    }''')
    b2 = bm.Bib('''@Misc{ZJones2001Scipy,
       author = {Eric ZJones},
       title  = {SciPy},
         year = 2001,
    }''')
    assert b1 != b2
示例#7
0
def test_Bib_lower_than_no_year():
    b1 = bm.Bib('''@Misc{JonesEtal2001scipy,
       author = {Eric Jones},
       title  = {SciPy},
       year   = {2001},
    }''')
    b2 = bm.Bib('''@Misc{JonesEtalScipy_noyear,
       author = {Eric Jones},
       title  = {SciPy},
    }''')
    assert b1 < b2
示例#8
0
def test_Bib_update_content_keep_meta(entries):
    bib1 = bm.Bib(entries['jones_minimal'])
    bib1.bibcode = 'bibcode1'
    bib1.pdf = 'pdf1'
    bib1.freeze = True
    bib1.tags = ['tag']
    bib2 = bm.Bib(entries['jones_minimal'])
    bib1.update_content(bib2)
    # pdf, freeze, and tags remeain as in bib1 since they are None in bib2:
    assert bib1.pdf == 'pdf1'
    assert bib1.freeze is True
    assert bib1.tags == ['tag']
示例#9
0
def test_merge_bibs_no_titles(capfd, mock_init):
    e1 = """@Misc{Jones2001scipy,
   author = {Eric Jones},
   year   = {2001},
 }"""
    e2 = """@Misc{Oliphant2001scipy,
   author = {Travis Oliphant},
   year   = {2001},
 }"""
    bibs = [bm.Bib(e1), bm.Bib(e2)]
    bm.merge(new=bibs)
    captured = capfd.readouterr()
    assert captured.out == "\nMerged 2 new entries.\n"
示例#10
0
def test_Bib_update_content(entries):
    bib1 = bm.Bib(entries['jones_minimal'])
    bib1.bibcode = 'bibcode1'
    bib1.pdf = 'pdf1'
    bib1.freeze = True
    bib2 = bm.Bib(entries['jones_minimal'])
    bib2.pdf = 'pdf2'
    bib1.update_content(bib2)
    # bibcode gets updated to None since it's bibtex info:
    assert bib1.bibcode is None
    # pdf gets updated since it's not None:
    assert bib1.pdf == 'pdf2'
    # freeze does not get updated, since it's not bibtex and is None:
    assert bib1.freeze is True
示例#11
0
def test_Bib_update_content_update_meta(entries):
    bib1 = bm.Bib(entries['jones_minimal'])
    bib1.bibcode = 'bibcode1'
    bib1.pdf = 'pdf1'
    bib1.tags = ['tag1']
    bib2 = bm.Bib(entries['jones_minimal'])
    bib2.pdf = 'pdf2'
    bib2.freeze = True
    bib1.tags = ['tag2']
    bib1.update_content(bib2)
    # pdf, freeze, and tags get updated since they are not None:
    assert bib1.pdf == 'pdf2'
    assert bib1.freeze is True
    assert bib1.tags == ['tag2']
示例#12
0
def test_display_bibs_meta_shown(capfd, mock_init):
    e1 = '''@Misc{JonesEtal2001scipy,
       author = {Eric Jones},
       title  = {SciPy},
       year   = {2001},
    }'''
    e2 = '''@Misc{Jones2001,
       author = {Travis Oliphant},
       title  = {tools for Python},
       year   = {2001},
    }'''
    bibs = [bm.Bib(e1), bm.Bib(e2, freeze=True, pdf='file.pdf')]
    bm.display_bibs(["DATABASE:\n", "NEW:\n"], bibs, meta=True)
    captured = capfd.readouterr()
    assert captured.out == '\x1b[0m\x1b[?7h\x1b[0;38;5;248;3m\r\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\r\n\x1b[0mDATABASE:\r\n\x1b[0;38;5;248;3m\x1b[0;38;5;34;1;4m@Misc\x1b[0m{\x1b[0;38;5;142mJonesEtal2001scipy\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33mauthor\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{Eric Jones}\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33mtitle\x1b[0;38;5;250m  \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{SciPy}\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33myear\x1b[0;38;5;250m   \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{2001}\x1b[0m,\x1b[0;38;5;250m\r\n    \x1b[0m}\x1b[0;38;5;250m\r\n\x1b[0m\r\nNEW:\r\n\x1b[0;38;5;248;3mfreeze\r\npdf: file.pdf\r\n\x1b[0;38;5;34;1;4m@Misc\x1b[0m{\x1b[0;38;5;142mJones2001\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33mauthor\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{Travis Oliphant}\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33mtitle\x1b[0;38;5;250m  \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{tools for Python}\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33myear\x1b[0;38;5;250m   \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{2001}\x1b[0m,\x1b[0;38;5;250m\r\n    \x1b[0m}\x1b[0;38;5;250m\r\n\x1b[0m\r\n\x1b[0m'
示例#13
0
def test_display_bibs(capfd, mock_init):
    e1 = '''@Misc{JonesEtal2001scipy,
       author = {Eric Jones},
       title  = {SciPy},
       year   = {2001},
    }'''
    e2 = '''@Misc{Jones2001,
       author = {Travis Oliphant},
       title  = {tools for Python},
       year   = {2001},
    }'''
    bibs = [bm.Bib(e1), bm.Bib(e2)]
    bm.display_bibs(["DATABASE:\n", "NEW:\n"], bibs)
    captured = capfd.readouterr()
    assert captured.out == '\x1b[0m\x1b[?7h\x1b[0;38;5;248;3m\r\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\r\n\x1b[0mDATABASE:\r\n\x1b[0;38;5;34;1;4m@Misc\x1b[0m{\x1b[0;38;5;142mJonesEtal2001scipy\x1b[0m,\x1b[0m\r\n       \x1b[0;38;5;33mauthor\x1b[0m \x1b[0m=\x1b[0m \x1b[0;38;5;130m{\x1b[0;38;5;130mEric Jones\x1b[0;38;5;130m}\x1b[0m,\x1b[0m\r\n       \x1b[0;38;5;33mtitle\x1b[0m  \x1b[0m=\x1b[0m \x1b[0;38;5;130m{\x1b[0;38;5;130mSciPy\x1b[0;38;5;130m}\x1b[0m,\x1b[0m\r\n       \x1b[0;38;5;33myear\x1b[0m   \x1b[0m=\x1b[0m \x1b[0;38;5;130m{\x1b[0;38;5;130m2001\x1b[0;38;5;130m}\x1b[0m,\x1b[0m\r\n    \x1b[0m}\x1b[0m\r\n\x1b[0m\r\n\x1b[0mNEW:\r\n\x1b[0;38;5;34;1;4m@Misc\x1b[0m{\x1b[0;38;5;142mJones2001\x1b[0m,\x1b[0m\r\n       \x1b[0;38;5;33mauthor\x1b[0m \x1b[0m=\x1b[0m \x1b[0;38;5;130m{\x1b[0;38;5;130mTravis Oliphant\x1b[0;38;5;130m}\x1b[0m,\x1b[0m\r\n       \x1b[0;38;5;33mtitle\x1b[0m  \x1b[0m=\x1b[0m \x1b[0;38;5;130m{\x1b[0;38;5;130mtools for Python\x1b[0;38;5;130m}\x1b[0m,\x1b[0m\r\n       \x1b[0;38;5;33myear\x1b[0m   \x1b[0m=\x1b[0m \x1b[0;38;5;130m{\x1b[0;38;5;130m2001\x1b[0;38;5;130m}\x1b[0m,\x1b[0m\r\n    \x1b[0m}\x1b[0m\r\n\x1b[0m\r\n\x1b[0m\x1b[0m'
示例#14
0
def test_Bib_minimal(entries):
    # Minimal entry (key, author, title, and year):
    bib = bm.Bib(entries['jones_minimal'])
    assert bib.content == entries['jones_minimal']
    assert bib.key == "JonesEtal2001scipy"
    assert bib.authors == [
        u.Author(last='Jones', first='Eric', von='', jr=''),
        u.Author(last='Oliphant', first='Travis', von='', jr=''),
        u.Author(last='Peterson', first='Pearu', von='', jr='')
    ]
    assert bib.sort_author == u.Sort_author(last='jones',
                                            first='e',
                                            von='',
                                            jr='',
                                            year=2001,
                                            month=13)
    assert bib.year == 2001
    assert bib.title == "SciPy: Open source scientific tools for Python"
    assert bib.doi == None
    assert bib.bibcode == None
    assert bib.adsurl == None
    assert bib.eprint == None
    assert bib.isbn == None
    assert bib.month == 13
    assert bib.pdf is None
    assert bib.freeze is None
示例#15
0
def test_guess_name_no_bibcode():
    bib = bm.Bib('''@ARTICLE{Raftery1995BIC,
       author = {{Raftery}, A.~E},
        title = "{Bayesian Model Selection in Social Research}",
         year = 1995,
    }''')
    assert pm.guess_name(bib) == 'Raftery1995.pdf'
示例#16
0
def test_Bib_published_non_ads():
    # Does not have adsurl:
    entry = '''@ARTICLE{DoeEtal2020,
          author = {{Doe}, J. and {Perez}, J. and {Dupont}, J.},
           title = "What Have the Astromomers ever Done for Us?",
            year = 2020,}'''
    bib = bm.Bib(entry)
    assert bib.published() == -1
示例#17
0
def test_guess_name_no_author_no_year():
    bib = bm.Bib('''@ARTICLE{Raftery1995BIC,
        title = "{Bayesian Model Selection in Social Research}",
    }''')
    with pytest.raises(ValueError,
            match='Could not guess a good filename since entry does not '
                  'have author nor year fields'):
        pm.guess_name(bib)
示例#18
0
def test_Bib_month(month_in, month_out):
    e = '''@Misc{JonesEtal2001scipy,
       author = {Eric Jones},
       title  = {SciPy},
       year   = {2001},
       ''' + month_in + '}'
    bib = bm.Bib(e)
    assert bib.month == month_out
示例#19
0
def test_guess_name_bibcode_no_pages():
    bib = bm.Bib('''@BOOK{Chase1986jttJANAF,
           author = {{Chase}, M.~W.},
            title = "{JANAF thermochemical tables}",
             year = "1986",
           adsurl = {https://ui.adsabs.harvard.edu/abs/1986jtt..book.....C},
    }''')
    assert pm.guess_name(bib) == 'Chase1986_jtt_book.pdf'
示例#20
0
def test_guess_name_bibcode_no_volume():
    bib = bm.Bib('''@PHDTHESIS{Payne1925phdStellarAtmospheres,
           author = {{Payne}, Cecilia Helena},
            title = "{Stellar Atmospheres; a Contribution to the Observational Study of High Temperature in the Reversing Layers of Stars.}",
             year = "1925",
           adsurl = {https://ui.adsabs.harvard.edu/abs/1925PhDT.........1P},
    }''')
    assert pm.guess_name(bib) == 'Payne1925_PhDT_1.pdf'
示例#21
0
def test_guess_name_non_ascii():
    bib = bm.Bib('''@ARTICLE{HuangEtal2014jqsrtCO2,
      author = {{Huang (黄新川)}, Xinchuan and {Gamache}, Robert R.},
       title = "{Reliable infrared line lists for 13 CO$_{2}$}",
        year = "2014",
      adsurl = {https://ui.adsabs.harvard.edu/abs/2014JQSRT.147..134H},
    }''')
    assert pm.guess_name(bib) == 'Huang2014_JQSRT_147_134.pdf'
示例#22
0
def test_guess_name_non_letter_characters():
    bib = bm.Bib(r'''@ARTICLE{GarciaMunoz2007pssHD209458bAeronomy,
           author = {{Garc{\'\i}a-Mu{\~n}oz}, A.},
            title = "{Physical and chemical aeronomy of HD 209458b}",
             year = "2007",
           adsurl = {https://ui.adsabs.harvard.edu/abs/2007P&SS...55.1426G},
    }''')
    assert pm.guess_name(bib) == 'GarciaMunoz2007_PSS_55_1426.pdf'
示例#23
0
def test_guess_name_blanks():
    bib = bm.Bib('''@MISC{AASteamHendrickson2018aastex62,
           author = {{AAS Journals Team}, and {Hendrickson}, Amy},
            title = "{Aasjournals/Aastex60: Version 6.2 Official Release}",
             year = "2018",
           adsurl = {https://ui.adsabs.harvard.edu/abs/2018zndo...1209290T},
    }''')
    assert pm.guess_name(bib) == 'AASJournalsTeam2018_zndo_12_9290.pdf'
示例#24
0
def test_search_title_entry_without_title(mock_init_sample, entries):
    # Multiple-title querries act with AND logic:
    bib = bm.Bib(entries['jones_no_title'])
    bm.merge(new=[bib])
    matches = bm.search(title=['HD 209458b', 'atmospheric circulation'])
    assert len(matches) == 1
    keys = [m.key for m in matches]
    assert 'ShowmanEtal2009apjRadGCM' in keys
示例#25
0
def test_guess_name_arxiv_arxiv():
    bib = bm.Bib('''@ARTICLE{AndraeEtal2010arxivChiSquareStats,
           author = {{Andrae}, Rene and {Schulze-Hartung}, Tim and {Melchior}, Peter},
            title = "{Dos and don'ts of reduced chi-squared}",
             year = "2010",
           adsurl = {https://ui.adsabs.harvard.edu/abs/2010arXiv1012.3754A},
        }''')
    assert pm.guess_name(bib, arxiv=True) == \
        'Andrae2010_arXiv_1012_3754.pdf'
示例#26
0
def test_Bib_published_arxiv():
    # Has 'arXiv' adsurl:
    entry = '''@ARTICLE{DoeEtal2020,
          author = {{Doe}, J. and {Perez}, J. and {Dupont}, J.},
           title = "What Have the Astromomers ever Done for Us?",
          adsurl = {http://adsabs.harvard.edu/abs/2016arXiv0123.0045S},
            year = 2020,}'''
    bib = bm.Bib(entry)
    assert bib.published() == 0
示例#27
0
def test_Bib_published_peer_reviewed():
    # Has adsurl field, no 'arXiv' in it:
    entry = '''@ARTICLE{DoeEtal2020,
          author = {{Doe}, J. and {Perez}, J. and {Dupont}, J.},
           title = "What Have the Astromomers ever Done for Us?",
          adsurl = {http://adsabs.harvard.edu/abs/2016Natur.123...45S},
            year = 2020,}'''
    bib = bm.Bib(entry)
    assert bib.published() == 1
示例#28
0
def test_Bib_month_invalid(month):
    e = '''@Misc{JonesEtal2001scipy,
       author = {Eric Jones},
       title  = {SciPy},
       year   = {2001},
       ''' + f'month = {month}' + ',}'
    value = f'{month.lower()}'
    with pytest.raises(ValueError, match=fr"Invalid month value \({value}\)"):
        bib = bm.Bib(e)
示例#29
0
def test_guess_name_with_bibcode():
    bib = bm.Bib('''@ARTICLE{FortneyEtal2008apjTwoClasses,
           author = {{Fortney}, J.~J. and {Lodders}, K. and {Marley}, M.~S. and
             {Freedman}, R.~S.},
            title = "{A Unified Theory for the Atmospheres of the Hot and Very Hot Jupiters: Two Classes of Irradiated Atmospheres}",
             year = "2008",
           adsurl = {https://ui.adsabs.harvard.edu/abs/2008ApJ...678.1419F},
    }''')
    assert pm.guess_name(bib) == 'Fortney2008_ApJ_678_1419.pdf'
示例#30
0
def test_Bib_warning_month(month):
    e = '''@Misc{JonesEtal2001scipy,
       author = {Eric Jones},
       title  = {SciPy},
       year   = {2001},
       ''' + f'month = {month}' + ',}'
    with pytest.warns(Warning) as record:
        bib = bm.Bib(e)
        assert str(record[0].message) == \
            f"Invalid month value '{month}' for entry 'JonesEtal2001scipy'"