Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

98 lines
3.4KB

  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/sdist')
  12. def test_create_sdist(test_project: Project, tmp_path: Path) -> None:
  13. # Create in the default location
  14. test_project.sdist_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.sdist_create(dest=dest)
  20. assert dest.is_file(), 'Did not create an sdist in the new location'
  21. @pytest.fixture()
  22. def test_sdist(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.sdist_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_sdist: Tuple[Path, Project]) -> None:
  29. sdist, project = test_sdist
  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_sdist: Tuple[Path, Project]) -> None:
  40. sdist, project = test_sdist
  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. # project.dds.pkg_import(sdist)
  62. assert repo_content_path.is_dir(), \
  63. 'The package did not appear in the local cache'
  64. assert repo_content_path.joinpath('library.jsonc').is_file(), \
  65. 'The package\'s library.jsonc did not get imported'
  66. # Excluded file will not be in the sdist:
  67. assert not repo_content_path.joinpath('other-file.txt').is_file(), \
  68. 'Non-package content appeared in the package cache'
  69. def test_sdist_invalid_project(tmp_project: Project) -> None:
  70. with error.expect_error_marker('no-package-json5'):
  71. tmp_project.sdist_create()
  72. @pytest.mark.skipif(platform.system() != 'Linux', reason='We know this fails on Linux')
  73. def test_sdist_unreadable_dir(dds: DDSWrapper) -> None:
  74. with error.expect_error_marker('failed-package-json5-scan'):
  75. dds.run(['sdist', 'create', '--project=/root'])
  76. def test_sdist_invalid_json5(tmp_project: Project) -> None:
  77. tmp_project.write('package.json5', 'bogus json5')
  78. with error.expect_error_marker('package-json5-parse-error'):
  79. tmp_project.sdist_create()