Exemplo n.º 1
0
def test_set_pdf_in_new(mock_init_sample, name):
    bib = bm.find(key='ShowmanEtal2009apjRadGCM')
    pdf = u.BM_PDF() + 'file.pdf'
    pathlib.Path(pdf).touch()
    pm.set_pdf(bib, pdf=pdf, filename=name)
    filename = 'file.pdf' if name is None else name
    assert filename in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf == filename
Exemplo n.º 2
0
def test_set_home_pdf_success(tmp_path, mock_init_sample):
    new_home = f'{tmp_path}/bm'
    old_pdf_home = u.BM_PDF()
    pathlib.Path(f"{u.BM_PDF()}Rubin1980.pdf").touch()
    pathlib.Path(f"{u.BM_PDF()}Slipher1913.pdf").touch()
    cm.set('home', new_home)
    # Not registered in database, not moved:
    assert 'Rubin1980.pdf' in os.listdir(f'{old_pdf_home}')
    # Moved:
    assert 'Slipher1913.pdf' in os.listdir(f'{new_home}/pdf/')
    assert 'Slipher1913.pdf' in os.listdir(u.BM_PDF())
Exemplo n.º 3
0
def test_set_pdf_bin_replace_ask_no(mock_init_sample, mock_input):
    bib = bm.find(key='Slipher1913lobAndromedaRarialVelocity')
    bin_pdf = b'file.pdf'
    old = f"{u.BM_PDF()}{bib.pdf}"
    name = 'new.pdf'
    pathlib.Path(old).touch()
    pm.set_pdf(bib, bin_pdf=bin_pdf, filename=name)
    assert name not in os.listdir(u.BM_PDF())
    assert os.path.basename(old) in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf == os.path.basename(old)
Exemplo n.º 4
0
def test_set_pdf_rename(mock_init_sample, replace):
    bib = bm.find(key='Slipher1913lobAndromedaRarialVelocity')
    old = f"{u.BM_PDF()}{bib.pdf}"
    pdf = old
    name = 'new.pdf'
    pathlib.Path(old).touch()
    pm.set_pdf(bib, pdf=pdf, filename=name, replace=replace)
    assert name in os.listdir(u.BM_PDF())
    assert old not in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf == name
Exemplo n.º 5
0
def test_set_pdf_bin_replace(mock_init_sample):
    bib = bm.find(key='Slipher1913lobAndromedaRarialVelocity')
    bin_pdf = b'file.pdf'
    pdf = 'file.pdf'
    name = 'new.pdf'
    old = f"{u.BM_PDF()}{bib.pdf}"
    pathlib.Path(old).touch()
    pm.set_pdf(bib, bin_pdf=bin_pdf, filename=name, replace=True)
    filename = 'file.pdf' if name is None else name
    assert filename in os.listdir(u.BM_PDF())
    assert os.path.basename(old) not in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf == filename
Exemplo n.º 6
0
def test_set_pdf_replace_ask_yes(mock_init_sample, mock_input):
    bib = bm.find(key='Slipher1913lobAndromedaRarialVelocity')
    pdf = 'file.pdf'
    name = 'new.pdf'
    old = f"{u.BM_PDF()}{bib.pdf}"
    pathlib.Path(old).touch()
    pathlib.Path(pdf).touch()
    out_filename = pm.set_pdf(bib, pdf=pdf, filename=name)
    filename = 'file.pdf' if name is None else name
    assert filename in os.listdir(u.BM_PDF())
    assert os.path.basename(old) not in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf == filename
    assert out_filename is not None
    assert out_filename == f"{u.BM_PDF()}{filename}"
Exemplo n.º 7
0
def test_set_pdf_bin_new(mock_init_sample, name):
    bib = bm.find(key='ShowmanEtal2009apjRadGCM')
    bin_pdf = b'file.pdf'
    pm.set_pdf(bib, bin_pdf=bin_pdf, filename=name)
    filename = 'Showman2009_ApJ_699_564.pdf' if name is None else name
    assert filename in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf == filename
Exemplo n.º 8
0
def test_set_pdf_str_bib(mock_init_sample, bib):
    pdf = 'file.pdf'
    name = 'new.pdf'
    pathlib.Path(pdf).touch()
    pm.set_pdf(bib, pdf=pdf, filename=name)
    assert name in os.listdir(u.BM_PDF())
    bib = bm.find(key='ShowmanEtal2009apjRadGCM')
    assert bib.pdf == name
Exemplo n.º 9
0
def test_set_pdf_bin_overwrite_rename(mock_init_sample, mock_input):
    bib = bm.find(key='ShowmanEtal2009apjRadGCM')
    bin_pdf = b'file.pdf'
    name = 'new.pdf'
    pathlib.Path(f"{u.BM_PDF()}{name}").touch()
    pm.set_pdf(bib, bin_pdf=bin_pdf, filename=name)
    assert 'new_new.pdf' in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf == 'new_new.pdf'
Exemplo n.º 10
0
def test_cli_pdf_set_renamed(capsys, mock_init_sample, mock_call):
    sys.argv = f"bibm pdf 1957RvMP...29..547B file.pdf new.pdf".split()
    pathlib.Path(f"file.pdf").touch()
    cli.main()
    captured = capsys.readouterr()
    assert captured.out == f"Saved PDF to: '{u.BM_PDF()}new.pdf'.\n"
    bib = bm.find(bibcode='1957RvMP...29..547B')
    assert bib.pdf == 'new.pdf'
    assert 'new.pdf' in os.listdir(u.BM_PDF())
Exemplo n.º 11
0
def test_loadfile_pdf_with_path(tmp_path, mock_init):
    pdf_path = str(tmp_path) + '/pathed_file.pdf'
    pathlib.Path(pdf_path).touch()
    with open(u.ROOT + 'examples/sample.bib') as f:
        text = f.read()
    text = f'pdf: {pdf_path}\n{text}'
    bibs = bm.loadfile(text=text)
    assert bibs[0].pdf == 'pathed_file.pdf'
    assert 'pathed_file.pdf' in os.listdir(u.BM_PDF())
    assert not os.path.isfile(pdf_path)
Exemplo n.º 12
0
def test_set_pdf_overwrite_no(mock_init_sample, mock_input):
    bib = bm.find(key='ShowmanEtal2009apjRadGCM')
    pdf = 'file.pdf'
    name = 'new.pdf'
    pathlib.Path(pdf).touch()
    pathlib.Path(f"{u.BM_PDF()}{name}").touch()
    pm.set_pdf(bib, pdf=pdf, filename=name)
    assert name in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf is None
Exemplo n.º 13
0
def test_set_pdf_overwrite_yes(mock_init_sample, mock_input):
    bib = bm.find(key='ShowmanEtal2009apjRadGCM')
    pdf = 'file.pdf'
    name = 'new.pdf'
    pathlib.Path(pdf).touch()
    pathlib.Path(f"{u.BM_PDF()}{name}").touch()
    out_filename = pm.set_pdf(bib, pdf=pdf, filename=name)
    assert name in os.listdir(u.BM_PDF())
    bib = bm.find(key=bib.key)
    assert bib.pdf == name
    # TBD: Check if previous file belongs to another entry?
    assert out_filename is not None
    assert out_filename == f"{u.BM_PDF()}{name}"
Exemplo n.º 14
0
def test_cli_pdf_set_prompt_guess(capsys, mock_init_sample, mock_call,
                                  mock_prompt_session):
    sys.argv = f"bibm pdf".split()
    pathlib.Path(f"file.pdf").touch()
    cli.main()
    captured = capsys.readouterr()
    assert captured.out == (
        "Syntax is:  key: KEY_VALUE PDF_FILE FILENAME\n"
        "       or:  bibcode: BIBCODE_VALUE PDF_FILE FILENAME\n"
        "(output FILENAME is optional, set it to guess for automated naming)\n"
        f"\nSaved PDF to: '{u.BM_PDF()}Burbidge1957_RvMP_29_547.pdf'.\n")
    bib = bm.find(bibcode='1957RvMP...29..547B')
    assert bib.pdf == 'Burbidge1957_RvMP_29_547.pdf'
    assert 'Burbidge1957_RvMP_29_547.pdf' in os.listdir(u.BM_PDF())
Exemplo n.º 15
0
def test_set_home_success(capsys, tmp_path, mock_init_sample):
    new_home = f'{tmp_path}/bm'
    cm.set('home', new_home)
    assert cm.get('home') == new_home + '/'
    # 'constants' now point to new home:
    assert u.BM_DATABASE() == f'{new_home}/bm_database.pickle'
    assert u.BM_BIBFILE() == f'{new_home}/bm_bibliography.bib'
    assert u.BM_TMP_BIB() == f'{new_home}/tmp_bibliography.bib'
    assert u.BM_CACHE() == f'{new_home}/cached_ads_query.pickle'
    assert u.BM_HISTORY_SEARCH() == f'{new_home}/history_search'
    assert u.BM_HISTORY_ADS() == f'{new_home}/history_ads_search'
    assert u.BM_PDF() == f'{new_home}/pdf/'
    captured = capsys.readouterr()
    assert captured.out == f'home updated to: {new_home}/.\n'
    # These files/folders stay:
    assert set(os.listdir(u.HOME)) == set(["config", "examples", "pdf"])
    # These files have been moved/created:
    assert set(os.listdir(str(new_home))) == \
        set(['pdf', 'bm_bibliography.bib', 'bm_database.pickle'])