選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

test_pkg.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import pytest
  2. from pathlib import Path
  3. from typing import Tuple
  4. import subprocess
  5. import platform
  6. from dds_ci import proc
  7. from dds_ci.dds import DDSWrapper
  8. from dds_ci.testing import ProjectOpener, Project, error
  9. @pytest.fixture()
  10. def test_project(project_opener: ProjectOpener) -> Project:
  11. return project_opener.open('projects/simple')
  12. def test_create_pkg(test_project: Project, tmp_path: Path) -> None:
  13. # Create in the default location
  14. test_project.pkg_create()
  15. sd_dir = test_project.build_root / 'foo@1.2.3.tar.gz'
  16. assert sd_dir.is_file(), 'Did not create an sdist in the default location'
  17. # Create in a different location
  18. dest = tmp_path / 'dummy.tar.gz'
  19. test_project.pkg_create(dest=dest)
  20. assert dest.is_file(), 'Did not create an sdist in the new location'
  21. @pytest.fixture()
  22. def _test_pkg(test_project: Project) -> Tuple[Path, Project]:
  23. repo_content_path = test_project.dds.repo_dir / 'foo@1.2.3'
  24. assert not repo_content_path.is_dir()
  25. test_project.pkg_create()
  26. assert not repo_content_path.is_dir()
  27. return test_project.build_root / 'foo@1.2.3.tar.gz', test_project
  28. def test_import_sdist_archive(_test_pkg: Tuple[Path, Project]) -> None:
  29. sdist, project = _test_pkg
  30. repo_content_path = project.dds.repo_dir / 'foo@1.2.3'
  31. project.dds.pkg_import(sdist)
  32. assert repo_content_path.is_dir(), \
  33. 'The package did not appear in the local cache'
  34. assert repo_content_path.joinpath('library.jsonc').is_file(), \
  35. 'The package\'s library.jsonc did not get imported'
  36. # Excluded file will not be in the sdist:
  37. assert not repo_content_path.joinpath('other-file.txt').is_file(), \
  38. 'Non-package content appeared in the package cache'
  39. def test_import_sdist_stdin(_test_pkg: Tuple[Path, Project]) -> None:
  40. sdist, project = _test_pkg
  41. repo_content_path = project.dds.repo_dir / 'foo@1.2.3'
  42. pipe = subprocess.Popen(
  43. list(proc.flatten_cmd([
  44. project.dds.path,
  45. project.dds.repo_dir_arg,
  46. 'pkg',
  47. 'import',
  48. '--stdin',
  49. ])),
  50. stdin=subprocess.PIPE,
  51. )
  52. assert pipe.stdin
  53. with sdist.open('rb') as sdist_bin:
  54. buf = sdist_bin.read(1024)
  55. while buf:
  56. pipe.stdin.write(buf)
  57. buf = sdist_bin.read(1024)
  58. pipe.stdin.close()
  59. rc = pipe.wait()
  60. assert rc == 0, 'Subprocess failed'
  61. assert repo_content_path.is_dir(), \
  62. 'The package did not appear in the local cache'
  63. assert repo_content_path.joinpath('library.jsonc').is_file(), \
  64. 'The package\'s library.jsonc did not get imported'
  65. # Excluded file will not be in the sdist:
  66. assert not repo_content_path.joinpath('other-file.txt').is_file(), \
  67. 'Non-package content appeared in the package cache'
  68. def test_sdist_invalid_project(tmp_project: Project) -> None:
  69. with error.expect_error_marker('no-package-json5'):
  70. tmp_project.pkg_create()
  71. @pytest.mark.skipif(platform.system() != 'Linux', reason='We know this fails on Linux')
  72. def test_sdist_unreadable_dir(dds: DDSWrapper) -> None:
  73. with error.expect_error_marker('failed-package-json5-scan'):
  74. dds.run(['pkg', 'create', '--project=/root'])
  75. def test_sdist_invalid_json5(tmp_project: Project) -> None:
  76. tmp_project.write('package.json5', 'bogus json5')
  77. with error.expect_error_marker('package-json5-parse-error'):
  78. tmp_project.pkg_create()