You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_sdist.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import pytest
  2. from pathlib import Path
  3. from typing import Tuple
  4. import subprocess
  5. from dds_ci import proc
  6. from dds_ci.testing import ProjectOpener, Project
  7. @pytest.fixture()
  8. def test_project(project_opener: ProjectOpener) -> Project:
  9. return project_opener.open('projects/sdist')
  10. def test_create_sdist(test_project: Project, tmp_path: Path) -> None:
  11. # Create in the default location
  12. test_project.sdist_create()
  13. sd_dir = test_project.build_root / 'foo@1.2.3.tar.gz'
  14. assert sd_dir.is_file(), 'Did not create an sdist in the default location'
  15. # Create in a different location
  16. dest = tmp_path / 'dummy.tar.gz'
  17. test_project.sdist_create(dest=dest)
  18. assert dest.is_file(), 'Did not create an sdist in the new location'
  19. @pytest.fixture()
  20. def test_sdist(test_project: Project) -> Tuple[Path, Project]:
  21. repo_content_path = test_project.dds.repo_dir / 'foo@1.2.3'
  22. assert not repo_content_path.is_dir()
  23. test_project.sdist_create()
  24. assert not repo_content_path.is_dir()
  25. return test_project.build_root / 'foo@1.2.3.tar.gz', test_project
  26. def test_import_sdist_archive(test_sdist: Tuple[Path, Project]) -> None:
  27. sdist, project = test_sdist
  28. repo_content_path = project.dds.repo_dir / 'foo@1.2.3'
  29. project.dds.pkg_import(sdist)
  30. assert repo_content_path.is_dir(), \
  31. 'The package did not appear in the local cache'
  32. assert repo_content_path.joinpath('library.jsonc').is_file(), \
  33. 'The package\'s library.jsonc did not get imported'
  34. # Excluded file will not be in the sdist:
  35. assert not repo_content_path.joinpath('other-file.txt').is_file(), \
  36. 'Non-package content appeared in the package cache'
  37. def test_import_sdist_stdin(test_sdist: Tuple[Path, Project]) -> None:
  38. sdist, project = test_sdist
  39. repo_content_path = project.dds.repo_dir / 'foo@1.2.3'
  40. pipe = subprocess.Popen(
  41. list(proc.flatten_cmd([
  42. project.dds.path,
  43. project.dds.repo_dir_arg,
  44. 'pkg',
  45. 'import',
  46. '--stdin',
  47. ])),
  48. stdin=subprocess.PIPE,
  49. )
  50. assert pipe.stdin
  51. with sdist.open('rb') as sdist_bin:
  52. buf = sdist_bin.read(1024)
  53. while buf:
  54. pipe.stdin.write(buf)
  55. buf = sdist_bin.read(1024)
  56. pipe.stdin.close()
  57. rc = pipe.wait()
  58. assert rc == 0, 'Subprocess failed'
  59. # project.dds.pkg_import(sdist)
  60. assert repo_content_path.is_dir(), \
  61. 'The package did not appear in the local cache'
  62. assert repo_content_path.joinpath('library.jsonc').is_file(), \
  63. 'The package\'s library.jsonc did not get imported'
  64. # Excluded file will not be in the sdist:
  65. assert not repo_content_path.joinpath('other-file.txt').is_file(), \
  66. 'Non-package content appeared in the package cache'