You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

import_test.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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()