test_bibtex_entry_from_pmid.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import subprocess
  2. import unittest.mock
  3. from pubmed_bibtex import bibtex_entry_from_pmid, _main
  4. TEST_PMID = '31025164'
  5. TEST_BIBTEX_ENTRY = r"""@Article{pmid31025164,
  6. Author="Egger, F. and Hofer, C. and Hammerle, F. P. and Lofler, S. and Nurnberg, M. and Fiedler, L. and Kriz, R. and Kern, H. and Huber, K. ",
  7. Title="{{I}nfluence of electrical stimulation therapy on permanent pacemaker function}",
  8. Journal="Wien. Klin. Wochenschr.",
  9. Year="2019",
  10. Month="Apr",
  11. Note={[DOI:\href{https://dx.doi.org/10.1007/s00508-019-1494-5}{10.1007/s00508-019-1494-5}] [PubMed:\href{https://www.ncbi.nlm.nih.gov/pubmed/31025164}{31025164}] }
  12. }
  13. """
  14. def test_bibtex_entry_from_pmid():
  15. assert bibtex_entry_from_pmid(pmid=TEST_PMID) == TEST_BIBTEX_ENTRY
  16. def test_main(capsys):
  17. with unittest.mock.patch('sys.argv', ['', TEST_PMID]):
  18. _main()
  19. out, err = capsys.readouterr()
  20. assert not err
  21. assert out == TEST_BIBTEX_ENTRY
  22. def test_script():
  23. proc_info = subprocess.run(['pubmed-bibtex', TEST_PMID],
  24. check=True,
  25. stdout=subprocess.PIPE,
  26. stderr=subprocess.PIPE)
  27. assert not proc_info.stderr
  28. assert proc_info.stdout == TEST_BIBTEX_ENTRY.encode()