Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

107 rindas
3.8KB

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