test_cli.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from pathlib import Path
  2. import pytest
  3. import conda_package_handling.cli as cli
  4. from .test_api import data_dir, test_package_name
  5. def test_cli(tmpdir, mocker):
  6. """
  7. Code coverage for the cli.
  8. """
  9. for command in [
  10. ["x", str(Path(data_dir, test_package_name + ".tar.bz2")), f"--prefix={tmpdir}"],
  11. [
  12. "x",
  13. str(Path(data_dir, test_package_name + ".conda")),
  14. "--info",
  15. f"--prefix={tmpdir}",
  16. ],
  17. ["c", str(Path(tmpdir, test_package_name)), ".tar.bz2", f"--out-folder={tmpdir}"],
  18. ]:
  19. cli.main(args=command)
  20. # XXX difficult to get to this error handling code through the actual CLI;
  21. # for example, a .tar.bz2 that can't be extracted raises OSError instead of
  22. # returning errors. Designed for .tar.bz2 -> .conda conversions that somehow
  23. # omit files?
  24. mocker.patch(
  25. "conda_package_handling.api.transmute", return_value=set("that is why you fail".split())
  26. )
  27. with pytest.raises(SystemExit):
  28. command = [
  29. "t",
  30. str(Path(data_dir, test_package_name + ".tar.bz2")),
  31. ".conda",
  32. f"--out-folder={tmpdir}",
  33. ]
  34. cli.main(args=command)
  35. def test_import_main():
  36. """
  37. e.g. python -m conda_package_handling
  38. """
  39. with pytest.raises(SystemExit):
  40. import conda_package_handling.__main__ # noqa