Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. pipe = subprocess.Popen(
  42. list(proc.flatten_cmd([
  43. project.dds.path,
  44. project.dds.cache_dir_arg,
  45. 'pkg',
  46. 'import',
  47. '--stdin',
  48. ])),
  49. stdin=subprocess.PIPE,
  50. )
  51. assert pipe.stdin
  52. with sdist.open('rb') as sdist_bin:
  53. buf = sdist_bin.read(1024)
  54. while buf:
  55. pipe.stdin.write(buf)
  56. buf = sdist_bin.read(1024)
  57. pipe.stdin.close()
  58. rc = pipe.wait()
  59. assert rc == 0, 'Subprocess failed'
  60. _check_import(project.dds.repo_dir / 'foo@1.2.3')
  61. def test_import_sdist_dir(test_project: Project) -> None:
  62. test_project.dds.run(['pkg', 'import', test_project.dds.cache_dir_arg, test_project.root])
  63. _check_import(test_project.dds.repo_dir / 'foo@1.2.3')
  64. def _check_import(repo_content_path: Path) -> None:
  65. assert repo_content_path.is_dir(), \
  66. 'The package did not appear in the local cache'
  67. assert repo_content_path.joinpath('library.jsonc').is_file(), \
  68. 'The package\'s library.jsonc did not get imported'
  69. # Excluded file will not be in the sdist:
  70. assert not repo_content_path.joinpath('other-file.txt').is_file(), \
  71. 'Non-package content appeared in the package cache'
  72. def test_sdist_invalid_project(tmp_project: Project) -> None:
  73. with error.expect_error_marker('no-package-json5'):
  74. tmp_project.pkg_create()
  75. @pytest.mark.skipif(platform.system() != 'Linux', reason='We know this fails on Linux')
  76. def test_sdist_unreadable_dir(dds: DDSWrapper) -> None:
  77. with error.expect_error_marker('failed-package-json5-scan'):
  78. dds.run(['pkg', 'create', '--project=/root'])
  79. def test_sdist_invalid_json5(tmp_project: Project) -> None:
  80. tmp_project.write('package.json5', 'bogus json5')
  81. with error.expect_error_marker('package-json5-parse-error'):
  82. tmp_project.pkg_create()