2021-04-17 02:33:08 +00:00
|
|
|
# pylint: disable=missing-module-docstring, redefined-outer-name, unused-argument, wrong-import-order, unused-import
|
2021-04-17 00:53:35 +00:00
|
|
|
import poetry.factory
|
|
|
|
import poetry.utils.env
|
|
|
|
import pytest
|
|
|
|
from poetry.puzzle.provider import Provider
|
|
|
|
|
2024-08-13 17:44:25 +00:00
|
|
|
import tox_poetry_installer.hooks._tox_on_install_helpers
|
2021-04-17 00:53:35 +00:00
|
|
|
from .fixtures import mock_poetry_factory
|
|
|
|
from .fixtures import mock_venv
|
|
|
|
from tox_poetry_installer import constants
|
|
|
|
from tox_poetry_installer import exceptions
|
|
|
|
|
|
|
|
|
|
|
|
def test_allow_missing():
|
2021-04-17 02:33:08 +00:00
|
|
|
"""Test that the ``allow_missing`` parameter works as expected"""
|
2021-04-17 00:53:35 +00:00
|
|
|
with pytest.raises(exceptions.LockedDepNotFoundError):
|
2024-08-13 17:44:25 +00:00
|
|
|
tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
|
|
|
"luke-skywalker", {}, None
|
|
|
|
)
|
2021-04-17 00:53:35 +00:00
|
|
|
|
2024-08-13 17:44:25 +00:00
|
|
|
assert not tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
2022-01-05 06:40:02 +00:00
|
|
|
"darth-vader", {}, None, allow_missing=["darth-vader"]
|
2021-04-17 00:53:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_exclude_pep508():
|
2021-04-17 02:33:08 +00:00
|
|
|
"""Test that dependencies specified in PEP508 format are properly excluded"""
|
2021-04-17 00:53:35 +00:00
|
|
|
for version in [
|
|
|
|
"foo==1.0",
|
|
|
|
"foo==1",
|
|
|
|
"foo>2.0.0",
|
|
|
|
"foo<=9.3.4.7.8",
|
|
|
|
"foo>999,<=4.6",
|
|
|
|
"foo>1234 || foo<2021.01.01",
|
|
|
|
"foo!=7",
|
|
|
|
"foo~=0.8",
|
|
|
|
"foo!=9,==7",
|
|
|
|
"=>foo",
|
|
|
|
]:
|
|
|
|
with pytest.raises(exceptions.LockedDepVersionConflictError):
|
2024-08-13 17:44:25 +00:00
|
|
|
tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
|
|
|
version, {}, None
|
|
|
|
)
|
2021-04-17 00:53:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_functional(mock_poetry_factory, mock_venv):
|
2021-04-17 02:33:08 +00:00
|
|
|
"""Integration tests for the :func:`identify_transients` function
|
|
|
|
|
|
|
|
Trivially test that it resolves dependencies properly and that the parent package
|
|
|
|
is always the last in the returned list.
|
|
|
|
"""
|
2021-04-17 00:53:35 +00:00
|
|
|
pypoetry = poetry.factory.Factory().create_poetry(None)
|
2024-08-13 17:44:25 +00:00
|
|
|
packages = tox_poetry_installer.hooks._tox_on_install_helpers.build_package_map(
|
|
|
|
pypoetry
|
|
|
|
)
|
2021-04-17 02:33:08 +00:00
|
|
|
venv = poetry.utils.env.VirtualEnv() # pylint: disable=no-value-for-parameter
|
2021-04-17 00:53:35 +00:00
|
|
|
|
|
|
|
requests_requires = [
|
2022-04-07 04:15:34 +00:00
|
|
|
packages["certifi"][0],
|
|
|
|
packages["chardet"][0],
|
|
|
|
packages["idna"][0],
|
|
|
|
packages["urllib3"][0],
|
|
|
|
packages["requests"][0],
|
2021-04-17 00:53:35 +00:00
|
|
|
]
|
|
|
|
|
2024-08-13 17:44:25 +00:00
|
|
|
transients = tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
|
|
|
"requests", packages, venv
|
|
|
|
)
|
2021-04-17 00:53:35 +00:00
|
|
|
|
|
|
|
assert all((item in requests_requires) for item in transients)
|
|
|
|
assert all((item in transients) for item in requests_requires)
|
|
|
|
|
2022-04-07 04:15:34 +00:00
|
|
|
for package in [packages["requests"][0], packages["tox"][0], packages["flask"][0]]:
|
2024-08-13 17:44:25 +00:00
|
|
|
transients = (
|
|
|
|
tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
|
|
|
package.name, packages, venv
|
|
|
|
)
|
|
|
|
)
|
2021-04-17 00:53:35 +00:00
|
|
|
assert transients[-1] == package
|
2021-04-17 02:33:08 +00:00
|
|
|
assert len(transients) == len(set(transients))
|