PageRenderTime 27ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/third_party/python/pip-tools/tests/test_resolver.py

https://bitbucket.org/vionika/spin.android
Python | 144 lines | 104 code | 22 blank | 18 comment | 14 complexity | f4cf244226054b9a53e0fcca715770a9 MD5 | raw file
Possible License(s): JSON, 0BSD, AGPL-1.0, BSD-2-Clause, GPL-3.0, LGPL-2.1, LGPL-3.0, CC0-1.0, AGPL-3.0, MPL-2.0, Apache-2.0, MIT, BSD-3-Clause, MPL-2.0-no-copyleft-exception, GPL-2.0, Unlicense
  1. import pytest
  2. @pytest.mark.parametrize(
  3. ('input', 'expected', 'prereleases'),
  4. ((tup + (False,))[:3] for tup in [
  5. (['Django'], ['django==1.8']),
  6. (['Flask'],
  7. ['flask==0.10.1', 'itsdangerous==0.24', 'markupsafe==0.23',
  8. 'jinja2==2.7.3', 'werkzeug==0.10.4']),
  9. (['Jinja2', 'markupsafe'],
  10. ['jinja2==2.7.3', 'markupsafe==0.23']),
  11. # We should return a normal release version if prereleases is False
  12. (['SQLAlchemy'],
  13. ['sqlalchemy==0.9.9']),
  14. # We should return the prerelease version if prereleases is True
  15. (['SQLAlchemy'],
  16. ['sqlalchemy==1.0.0b5'],
  17. True),
  18. # Ipython has extras available, but we don't require them in this test
  19. (['ipython'],
  20. ['ipython==2.1.0', 'gnureadline==6.3.3']),
  21. # We should get dependencies for extras
  22. (['ipython[notebook]'],
  23. [
  24. 'ipython[notebook]==2.1.0',
  25. 'pyzmq==2.1.12',
  26. 'jinja2==2.7.3',
  27. 'tornado==3.2.2',
  28. 'markupsafe==0.23',
  29. 'gnureadline==6.3.3']
  30. ),
  31. # We should get dependencies for multiple extras
  32. (['ipython[notebook,nbconvert]'],
  33. [
  34. # Note that the extras should be sorted
  35. 'ipython[nbconvert,notebook]==2.1.0',
  36. 'pyzmq==2.1.12',
  37. 'jinja2==2.7.3',
  38. 'tornado==3.2.2',
  39. 'markupsafe==0.23',
  40. 'gnureadline==6.3.3',
  41. 'pygments==1.5',
  42. 'sphinx==0.3']
  43. ),
  44. # We must take the union of all extras
  45. (['ipython[notebook]', 'ipython[nbconvert]'],
  46. [
  47. # Note that the extras should be sorted
  48. 'ipython[nbconvert,notebook]==2.1.0',
  49. 'pyzmq==2.1.12',
  50. 'jinja2==2.7.3',
  51. 'tornado==3.2.2',
  52. 'markupsafe==0.23',
  53. 'gnureadline==6.3.3',
  54. 'pygments==1.5',
  55. 'sphinx==0.3']
  56. ),
  57. # We must remove child dependencies from result if parent is removed (e.g. vine from amqp>=2.0)
  58. # See: GH-370
  59. # because of upated dependencies in the test index, we need to pin celery
  60. # in order to reproduce vine removal (because it was readded in later releases)
  61. (['celery<=3.1.23', 'librabbitmq'],
  62. [
  63. 'amqp==1.4.9',
  64. 'anyjson==0.3.3',
  65. 'billiard==3.5.0.2',
  66. 'celery==3.1.23',
  67. 'kombu==3.0.35',
  68. 'librabbitmq==1.6.1',
  69. 'pytz==2016.4']
  70. ),
  71. # Support specifying loose top-level requirements that could also appear as
  72. # pinned subdependencies.
  73. (['billiard', 'celery',
  74. 'fake-piptools-test-with-pinned-deps'],
  75. [
  76. 'amqp==1.4.9',
  77. 'anyjson==0.3.3',
  78. 'billiard==3.3.0.23',
  79. 'celery==3.1.18', # this is pinned from test subdependency
  80. 'fake-piptools-test-with-pinned-deps==0.1',
  81. 'kombu==3.0.35',
  82. 'pytz==2016.4']
  83. ),
  84. # Exclude package dependcy of setuptools as it is unsafe.
  85. (['html5lib'], ['html5lib==0.999999999']),
  86. # We shouldn't include irrelevant pip constraints
  87. # See: GH-471
  88. (['Flask', ('click', True), ('itsdangerous', True)],
  89. ['flask==0.10.1', 'itsdangerous==0.24', 'markupsafe==0.23',
  90. 'jinja2==2.7.3', 'werkzeug==0.10.4']
  91. ),
  92. # Unsafe dependencies should be filtered
  93. (['setuptools==35.0.0', 'anyjson==0.3.3'], ['anyjson==0.3.3']),
  94. (['fake-piptools-test-with-unsafe-deps==0.1'],
  95. ['fake-piptools-test-with-unsafe-deps==0.1']
  96. ),
  97. ])
  98. )
  99. def test_resolver(resolver, from_line, input, expected, prereleases):
  100. input = [line if isinstance(line, tuple) else (line, False) for line in input]
  101. input = [from_line(req[0], constraint=req[1]) for req in input]
  102. output = resolver(input, prereleases=prereleases).resolve()
  103. output = {str(line) for line in output}
  104. assert output == {str(line) for line in expected}
  105. @pytest.mark.parametrize(
  106. ('input', 'expected', 'prereleases'),
  107. ((tup + (False,))[:3] for tup in [
  108. (['setuptools==34.0.0'], ['appdirs==1.4.9', 'setuptools==34.0.0', 'packaging==16.8']),
  109. (['fake-piptools-test-with-unsafe-deps==0.1'],
  110. ['appdirs==1.4.9',
  111. 'setuptools==34.0.0',
  112. 'packaging==16.8',
  113. 'fake-piptools-test-with-unsafe-deps==0.1'
  114. ]),
  115. ])
  116. )
  117. def test_resolver__allows_unsafe_deps(resolver, from_line, input, expected, prereleases):
  118. input = [line if isinstance(line, tuple) else (line, False) for line in input]
  119. input = [from_line(req[0], constraint=req[1]) for req in input]
  120. output = resolver(input, prereleases=prereleases, allow_unsafe=True).resolve()
  121. output = {str(line) for line in output}
  122. assert output == {str(line) for line in expected}