test_main.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import subprocess
  2. import unittest.mock
  3. import pubmed_bibtex
  4. from pubmed_bibtex.__main__ import main
  5. from conftest import TEST_PMID, TEST_BIBTEX_ENTRY
  6. def test_main(capsys):
  7. with unittest.mock.patch('sys.argv', ['', TEST_PMID]):
  8. main()
  9. out, err = capsys.readouterr()
  10. assert not err
  11. assert out == TEST_BIBTEX_ENTRY
  12. def test_script_module():
  13. proc_info = subprocess.run(['python', '-m', 'pubmed_bibtex', TEST_PMID],
  14. check=True,
  15. stdout=subprocess.PIPE,
  16. stderr=subprocess.PIPE)
  17. assert not proc_info.stderr
  18. assert proc_info.stdout == TEST_BIBTEX_ENTRY.encode()
  19. def test_script():
  20. proc_info = subprocess.run(['pubmed-bibtex', TEST_PMID],
  21. check=True,
  22. stdout=subprocess.PIPE,
  23. stderr=subprocess.PIPE)
  24. assert not proc_info.stderr
  25. assert proc_info.stdout == TEST_BIBTEX_ENTRY.encode()
  26. def test_version():
  27. proc_info = subprocess.run(['pubmed-bibtex', '--version'],
  28. check=True,
  29. stdout=subprocess.PIPE,
  30. stderr=subprocess.PIPE)
  31. assert not proc_info.stderr
  32. assert proc_info.stdout == pubmed_bibtex.__version__.encode() + b'\n'