test_interface.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """
  2. Test format classes.
  3. (Some of their code is unreachable through api.py)
  4. """
  5. import os
  6. from pathlib import Path
  7. import pytest
  8. from conda_package_handling.conda_fmt import CondaFormat_v2
  9. from conda_package_handling.tarball import CondaTarBZ2
  10. from .test_api import data_dir, test_package_name
  11. TEST_CONDA = Path(data_dir, test_package_name + ".conda")
  12. TEST_TARBZ = Path(data_dir, test_package_name + ".tar.bz2")
  13. def test_extract_create(tmpdir):
  14. for format, infile, outfile in (
  15. (CondaFormat_v2, TEST_CONDA, "newmock.conda"),
  16. (CondaTarBZ2, TEST_TARBZ, "newmock.tar.bz2"),
  17. ):
  18. both_path = Path(tmpdir, f"mkdirs-{outfile.split('.', 1)[-1]}")
  19. # these old APIs don't guarantee Path-like's
  20. format.extract(infile, str(both_path))
  21. assert sorted(os.listdir(both_path)) == sorted(["lib", "info"])
  22. if format == CondaFormat_v2:
  23. info_path = Path(tmpdir, "info-only")
  24. format.extract_info(TEST_CONDA, str(info_path)) # type: ignore
  25. assert os.listdir(info_path) == ["info"]
  26. filelist = [str(p.relative_to(both_path)) for p in both_path.rglob("*")]
  27. format.create(
  28. both_path,
  29. filelist,
  30. tmpdir / outfile,
  31. # compression_tuple is for libarchive compatibility. Instead, pass
  32. # compressor=(compressor factory function)
  33. compression_tuple=(".tar.zst", "zstd", "zstd:compression-level=1"),
  34. )
  35. assert (tmpdir / outfile).exists()
  36. with pytest.raises(ValueError):
  37. CondaFormat_v2.create(
  38. "", [], "", compressor=True, compression_tuple=("1", "2", "3") # type: ignore
  39. )