您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

82 行
2.2KB

  1. import json
  2. from pathlib import Path
  3. from functools import partial
  4. from concurrent.futures import ThreadPoolExecutor
  5. from http.server import SimpleHTTPRequestHandler, HTTPServer
  6. import time
  7. import pytest
  8. from tests import dds, DDS
  9. from tests.fileutil import ensure_dir
  10. class DirectoryServingHTTPRequestHandler(SimpleHTTPRequestHandler):
  11. def __init__(self, *args, **kwargs) -> None:
  12. self.dir = kwargs.pop('dir')
  13. super().__init__(*args, **kwargs)
  14. def translate_path(self, path) -> str:
  15. abspath = Path(super().translate_path(path))
  16. relpath = abspath.relative_to(Path.cwd())
  17. return self.dir / relpath
  18. def test_import_json(dds: DDS):
  19. dds.scope.enter_context(ensure_dir(dds.build_dir))
  20. dds.catalog_create()
  21. json_fpath = dds.build_dir / 'data.json'
  22. import_data = {
  23. 'version': 2,
  24. 'packages': {
  25. 'foo': {
  26. '1.2.4': {
  27. 'url': 'git+http://example.com#master',
  28. 'depends': [],
  29. },
  30. '1.2.5': {
  31. 'url': 'git+http://example.com#master',
  32. },
  33. },
  34. 'bar': {
  35. '1.5.1': {
  36. 'url': 'http://example.com/bar-1.5.2.tgz'
  37. },
  38. }
  39. },
  40. }
  41. dds.scope.enter_context(
  42. dds.set_contents(json_fpath,
  43. json.dumps(import_data).encode()))
  44. dds.catalog_import(json_fpath)
  45. @pytest.yield_fixture
  46. def http_import_server():
  47. handler = partial(
  48. DirectoryServingHTTPRequestHandler,
  49. dir=Path.cwd() / 'data/http-test-1')
  50. addr = ('0.0.0.0', 8000)
  51. pool = ThreadPoolExecutor()
  52. with HTTPServer(addr, handler) as httpd:
  53. pool.submit(lambda: httpd.serve_forever(poll_interval=0.1))
  54. try:
  55. yield
  56. finally:
  57. httpd.shutdown()
  58. def test_import_http(dds: DDS, http_import_server):
  59. dds.repo_dir.mkdir(parents=True, exist_ok=True)
  60. dds.run(
  61. [
  62. 'repo',
  63. dds.repo_dir_arg,
  64. 'import',
  65. 'https://github.com/vector-of-bool/neo-buffer/archive/0.4.2.tar.gz?dds_strpcmp=1',
  66. ],
  67. cwd=dds.repo_dir,
  68. )
  69. assert dds.repo_dir.joinpath('neo-buffer@0.4.2').is_dir()