Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
7f2d405a
Unverified
Commit
7f2d405a
authored
Apr 21, 2023
by
David Hotham
Committed by
GitHub
Apr 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unit test type annotations (#7820)
parent
735235a0
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
125 additions
and
88 deletions
+125
-88
tests/console/commands/cache/test_clear.py
+4
-4
tests/console/commands/env/test_info.py
+3
-3
tests/console/commands/source/test_add.py
+7
-7
tests/console/commands/test_add.py
+0
-0
tests/console/commands/test_init.py
+12
-6
tests/console/commands/test_install.py
+20
-2
tests/console/commands/test_search.py
+1
-1
tests/console/conftest.py
+6
-7
tests/helpers.py
+3
-0
tests/installation/test_executor.py
+1
-1
tests/installation/test_installer.py
+38
-32
tests/mixology/solutions/providers/test_python_requirement_solution_provider.py
+2
-2
tests/mixology/solutions/solutions/test_python_requirement_solution.py
+1
-1
tests/puzzle/test_transaction.py
+7
-5
tests/repositories/test_legacy_repository.py
+4
-4
tests/utils/test_cache.py
+3
-3
tests/utils/test_env.py
+11
-8
tests/utils/test_pip.py
+2
-2
No files found.
tests/console/commands/cache/test_clear.py
View file @
7f2d405a
...
...
@@ -28,7 +28,7 @@ def test_cache_clear_all(
repository_one
:
str
,
repository_cache_dir
:
Path
,
cache
:
CacheManager
,
):
)
->
None
:
exit_code
=
tester
.
execute
(
f
"cache clear {repository_one} --all"
,
inputs
=
"yes"
)
repository_one_dir
=
repository_cache_dir
/
repository_one
...
...
@@ -45,7 +45,7 @@ def test_cache_clear_all_no(
repository_one
:
str
,
repository_cache_dir
:
Path
,
cache
:
CacheManager
,
):
)
->
None
:
exit_code
=
tester
.
execute
(
f
"cache clear {repository_one} --all"
,
inputs
=
"no"
)
assert
exit_code
==
0
...
...
@@ -62,7 +62,7 @@ def test_cache_clear_pkg(
repository_one
:
str
,
cache
:
CacheManager
,
package_name
:
str
,
):
)
->
None
:
exit_code
=
tester
.
execute
(
f
"cache clear {repository_one}:{package_name}:0.1"
,
inputs
=
"yes"
)
...
...
@@ -77,7 +77,7 @@ def test_cache_clear_pkg_no(
tester
:
ApplicationTester
,
repository_one
:
str
,
cache
:
CacheManager
,
):
)
->
None
:
exit_code
=
tester
.
execute
(
f
"cache clear {repository_one}:cachy:0.1"
,
inputs
=
"no"
)
assert
exit_code
==
0
...
...
tests/console/commands/env/test_info.py
View file @
7f2d405a
...
...
@@ -32,7 +32,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return
command_tester_factory
(
"env info"
)
def
test_env_info_displays_complete_info
(
tester
:
CommandTester
):
def
test_env_info_displays_complete_info
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
()
expected
=
f
"""
...
...
@@ -54,13 +54,13 @@ Executable: python
assert
tester
.
io
.
fetch_output
()
==
expected
def
test_env_info_displays_path_only
(
tester
:
CommandTester
):
def
test_env_info_displays_path_only
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
(
"--path"
)
expected
=
str
(
Path
(
"/prefix"
))
+
"
\n
"
assert
tester
.
io
.
fetch_output
()
==
expected
def
test_env_info_displays_executable_only
(
tester
:
CommandTester
):
def
test_env_info_displays_executable_only
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
(
"--executable"
)
expected
=
str
(
sys
.
executable
)
+
"
\n
"
assert
tester
.
io
.
fetch_output
()
==
expected
tests/console/commands/source/test_add.py
View file @
7f2d405a
...
...
@@ -87,7 +87,7 @@ def test_source_add_secondary_legacy(
source_existing
:
Source
,
source_secondary
:
Source
,
poetry_with_source
:
Poetry
,
):
)
->
None
:
tester
.
execute
(
f
"--secondary {source_secondary.name} {source_secondary.url}"
)
assert_source_added_legacy
(
tester
,
poetry_with_source
,
source_existing
,
source_secondary
...
...
@@ -99,7 +99,7 @@ def test_source_add_default(
source_existing
:
Source
,
source_default
:
Source
,
poetry_with_source
:
Poetry
,
):
)
->
None
:
tester
.
execute
(
f
"--priority=default {source_default.name} {source_default.url}"
)
assert_source_added
(
tester
,
poetry_with_source
,
source_existing
,
source_default
)
...
...
@@ -109,7 +109,7 @@ def test_source_add_second_default_fails(
source_existing
:
Source
,
source_default
:
Source
,
poetry_with_source
:
Poetry
,
):
)
->
None
:
tester
.
execute
(
f
"--priority=default {source_default.name} {source_default.url}"
)
assert_source_added
(
tester
,
poetry_with_source
,
source_existing
,
source_default
)
poetry_with_source
.
pyproject
.
reload
()
...
...
@@ -155,7 +155,7 @@ def test_source_add_error_default_and_secondary_legacy(tester: CommandTester) ->
assert
tester
.
status_code
==
1
def
test_source_add_error_priority_and_deprecated_legacy
(
tester
:
CommandTester
):
def
test_source_add_error_priority_and_deprecated_legacy
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
(
"--priority secondary --secondary error https://error.com"
)
assert
(
tester
.
io
.
fetch_error
()
.
strip
()
...
...
@@ -204,7 +204,7 @@ def test_source_add_existing_legacy(
def
test_source_add_existing_no_change
(
tester
:
CommandTester
,
source_existing
:
Source
,
poetry_with_source
:
Poetry
):
)
->
None
:
tester
.
execute
(
f
"--priority=primary {source_existing.name} {source_existing.url}"
)
assert
(
tester
.
io
.
fetch_output
()
.
strip
()
...
...
@@ -220,7 +220,7 @@ def test_source_add_existing_no_change(
def
test_source_add_existing_updating
(
tester
:
CommandTester
,
source_existing
:
Source
,
poetry_with_source
:
Poetry
):
)
->
None
:
tester
.
execute
(
f
"--priority=default {source_existing.name} {source_existing.url}"
)
assert
(
tester
.
io
.
fetch_output
()
.
strip
()
...
...
@@ -243,7 +243,7 @@ def test_source_add_existing_fails_due_to_other_default(
source_existing
:
Source
,
source_default
:
Source
,
poetry_with_source
:
Poetry
,
):
)
->
None
:
tester
.
execute
(
f
"--priority=default {source_default.name} {source_default.url}"
)
tester
.
io
.
fetch_output
()
...
...
tests/console/commands/test_add.py
View file @
7f2d405a
This diff is collapsed.
Click to expand it.
tests/console/commands/test_init.py
View file @
7f2d405a
...
...
@@ -14,9 +14,9 @@ import pytest
from
cleo.testers.command_tester
import
CommandTester
from
packaging.utils
import
canonicalize_name
from
poetry.console.application
import
Application
from
poetry.console.commands.init
import
InitCommand
from
poetry.repositories
import
RepositoryPool
from
tests.helpers
import
PoetryTestApplication
from
tests.helpers
import
get_package
...
...
@@ -29,6 +29,7 @@ if TYPE_CHECKING:
from
poetry.config.config
import
Config
from
poetry.poetry
import
Poetry
from
tests.helpers
import
PoetryTestApplication
from
tests.helpers
import
TestRepository
from
tests.types
import
FixtureDirGetter
...
...
@@ -54,8 +55,7 @@ def patches(mocker: MockerFixture, source_dir: Path, repo: TestRepository) -> No
@pytest.fixture
def
tester
(
patches
:
None
)
->
CommandTester
:
# we need a test application without poetry here.
app
=
PoetryTestApplication
(
None
)
app
=
Application
()
return
CommandTester
(
app
.
find
(
"init"
))
...
...
@@ -108,6 +108,7 @@ def test_noninteractive(
tmp_path
:
Path
,
)
->
None
:
command
=
app
.
find
(
"init"
)
assert
isinstance
(
command
,
InitCommand
)
command
.
_pool
=
poetry
.
pool
repo
.
add_package
(
get_package
(
"pytest"
,
"3.6.0"
))
...
...
@@ -328,7 +329,8 @@ _generate_choice_list_packages_params: list[list[Package]] = [
@pytest.fixture
(
params
=
_generate_choice_list_packages_params
)
def
_generate_choice_list_packages
(
request
:
FixtureRequest
)
->
list
[
Package
]:
return
request
.
param
packages
:
list
[
Package
]
=
request
.
param
return
packages
@pytest.mark.parametrize
(
"package_name"
,
[
"flask"
,
"Flask"
,
"flAsK"
])
...
...
@@ -338,6 +340,7 @@ def test_generate_choice_list(
_generate_choice_list_packages
:
list
[
Package
],
)
->
None
:
init_command
=
tester
.
command
assert
isinstance
(
init_command
,
InitCommand
)
packages
=
_generate_choice_list_packages
choices
=
init_command
.
_generate_choice_list
(
...
...
@@ -880,7 +883,9 @@ pytest = "^3.6.0"
def
test_add_package_with_extras_and_whitespace
(
tester
:
CommandTester
)
->
None
:
result
=
tester
.
command
.
_parse_requirements
([
"databases[postgresql, sqlite]"
])
command
=
tester
.
command
assert
isinstance
(
command
,
InitCommand
)
result
=
command
.
_parse_requirements
([
"databases[postgresql, sqlite]"
])
assert
result
[
0
][
"name"
]
==
"databases"
assert
len
(
result
[
0
][
"extras"
])
==
2
...
...
@@ -1087,7 +1092,8 @@ def test_respect_prefer_active_on_init(
if
GET_PYTHON_VERSION_ONELINER
in
cmd
:
return
"1.1.1"
return
orig_check_output
(
cmd
,
*
_
,
**
__
)
result
:
str
=
orig_check_output
(
cmd
,
*
_
,
**
__
)
return
result
mocker
.
patch
(
"subprocess.check_output"
,
side_effect
=
mock_check_output
)
...
...
tests/console/commands/test_install.py
View file @
7f2d405a
...
...
@@ -9,7 +9,9 @@ import pytest
from
poetry.core.masonry.utils.module
import
ModuleOrPackageNotFound
from
poetry.core.packages.dependency_group
import
MAIN_GROUP
from
poetry.console.commands.installer_command
import
InstallerCommand
from
poetry.console.exceptions
import
GroupNotFound
from
tests.helpers
import
TestLocker
if
TYPE_CHECKING
:
...
...
@@ -123,6 +125,7 @@ def test_group_options_are_passed_to_the_installer(
"""
Group options are passed properly to the installer.
"""
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
editable_builder_mock
=
mocker
.
patch
(
"poetry.masonry.builders.editable.EditableBuilder"
,
...
...
@@ -140,8 +143,8 @@ def test_group_options_are_passed_to_the_installer(
else
:
assert
status_code
==
0
package_groups
=
set
(
tester
.
command
.
poetry
.
package
.
_dependency_groups
.
keys
()
)
installer_groups
=
set
(
tester
.
command
.
installer
.
_groups
)
package_groups
=
set
(
tester
.
command
.
poetry
.
package
.
_dependency_groups
)
installer_groups
=
set
(
tester
.
command
.
installer
.
_groups
or
[]
)
assert
installer_groups
<=
package_groups
assert
set
(
installer_groups
)
==
groups
...
...
@@ -159,6 +162,7 @@ def test_sync_option_is_passed_to_the_installer(
"""
The --sync option is passed properly to the installer.
"""
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
1
)
tester
.
execute
(
"--sync"
)
...
...
@@ -173,6 +177,7 @@ def test_compile_option_is_passed_to_the_installer(
"""
The --compile option is passed properly to the installer.
"""
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
1
)
enable_bytecode_compilation_mock
=
mocker
.
patch
.
object
(
tester
.
command
.
installer
.
executor
.
_wheel_installer
,
...
...
@@ -192,6 +197,7 @@ def test_no_directory_is_passed_to_installer(
The --no-directory option is passed to the installer.
"""
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
1
)
if
skip_directory_cli_value
is
True
:
...
...
@@ -208,6 +214,7 @@ def test_no_all_extras_doesnt_populate_installer(
"""
Not passing --all-extras means the installer doesn't see any extras.
"""
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
1
)
tester
.
execute
()
...
...
@@ -221,6 +228,7 @@ def test_all_extras_populates_installer(
"""
The --all-extras option results in extras passed to the installer.
"""
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
1
)
tester
.
execute
(
"--all-extras"
)
...
...
@@ -232,6 +240,7 @@ def test_extras_are_parsed_and_populate_installer(
tester
:
CommandTester
,
mocker
:
MockerFixture
,
)
->
None
:
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
tester
.
execute
(
'--extras "first second third"'
)
...
...
@@ -245,6 +254,7 @@ def test_extras_conflicts_all_extras(
"""
The --extras doesn't make sense with --all-extras.
"""
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
tester
.
execute
(
"--extras foo --all-extras"
)
...
...
@@ -271,6 +281,7 @@ def test_only_root_conflicts_with_without_only(
tester
:
CommandTester
,
mocker
:
MockerFixture
,
)
->
None
:
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
tester
.
execute
(
f
"{options} --only-root"
)
...
...
@@ -305,6 +316,7 @@ def test_invalid_groups_with_without_only(
valid_groups
:
set
[
str
],
should_raise
:
bool
,
)
->
None
:
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
cmd_args
=
" "
.
join
(
f
"{flag} {groups}"
for
(
flag
,
groups
)
in
options
.
items
())
...
...
@@ -329,6 +341,7 @@ def test_remove_untracked_outputs_deprecation_warning(
tester
:
CommandTester
,
mocker
:
MockerFixture
,
)
->
None
:
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
tester
.
execute
(
"--remove-untracked"
)
...
...
@@ -348,6 +361,7 @@ def test_dry_run_populates_installer(
The --dry-run option results in extras passed to the installer.
"""
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
1
)
tester
.
execute
(
"--dry-run"
)
...
...
@@ -356,6 +370,7 @@ def test_dry_run_populates_installer(
def
test_dry_run_does_not_build
(
tester
:
CommandTester
,
mocker
:
MockerFixture
)
->
None
:
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
mocked_editable_builder
=
mocker
.
patch
(
"poetry.masonry.builders.editable.EditableBuilder"
...
...
@@ -367,6 +382,7 @@ def test_dry_run_does_not_build(tester: CommandTester, mocker: MockerFixture) ->
def
test_install_logs_output
(
tester
:
CommandTester
,
mocker
:
MockerFixture
)
->
None
:
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
mocker
.
patch
(
"poetry.masonry.builders.editable.EditableBuilder"
)
...
...
@@ -382,6 +398,7 @@ def test_install_logs_output(tester: CommandTester, mocker: MockerFixture) -> No
def
test_install_logs_output_decorated
(
tester
:
CommandTester
,
mocker
:
MockerFixture
)
->
None
:
assert
isinstance
(
tester
.
command
,
InstallerCommand
)
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
0
)
mocker
.
patch
(
"poetry.masonry.builders.editable.EditableBuilder"
)
...
...
@@ -412,6 +429,7 @@ def test_install_path_dependency_does_not_exist(
options
:
str
,
)
->
None
:
poetry
=
_project_factory
(
project
,
project_factory
,
fixture_dir
)
assert
isinstance
(
poetry
.
locker
,
TestLocker
)
poetry
.
locker
.
locked
(
True
)
tester
=
command_tester_factory
(
"install"
,
poetry
=
poetry
)
if
options
:
...
...
tests/console/commands/test_search.py
View file @
7f2d405a
...
...
@@ -30,7 +30,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return
command_tester_factory
(
"search"
)
def
test_search
(
tester
:
CommandTester
,
http
:
type
[
httpretty
.
httpretty
]):
def
test_search
(
tester
:
CommandTester
,
http
:
type
[
httpretty
.
httpretty
])
->
None
:
tester
.
execute
(
"sqlalchemy"
)
expected
=
"""
...
...
tests/console/conftest.py
View file @
7f2d405a
...
...
@@ -122,8 +122,8 @@ def command_tester_factory(
executor
:
Executor
|
None
=
None
,
environment
:
Env
|
None
=
None
,
)
->
CommandTester
:
command
=
app
.
find
(
command
)
tester
=
CommandTester
(
command
)
command
_obj
=
app
.
find
(
command
)
tester
=
CommandTester
(
command
_obj
)
# Setting the formatter from the application
# TODO: Find a better way to do this in Cleo
...
...
@@ -136,12 +136,11 @@ def command_tester_factory(
app
.
_poetry
=
poetry
poetry
=
app
.
poetry
command
.
_pool
=
poetry
.
pool
if
hasattr
(
command
,
"set_env"
):
command
.
set_env
(
environment
or
env
)
if
hasattr
(
command
_obj
,
"set_env"
):
command
_obj
.
set_env
(
environment
or
env
)
if
hasattr
(
command
,
"set_installer"
):
if
hasattr
(
command
_obj
,
"set_installer"
):
installer
=
installer
or
Installer
(
tester
.
io
,
env
,
...
...
@@ -152,7 +151,7 @@ def command_tester_factory(
executor
=
executor
or
TestExecutor
(
env
,
poetry
.
pool
,
poetry
.
config
,
tester
.
io
),
)
command
.
set_installer
(
installer
)
command
_obj
.
set_installer
(
installer
)
return
tester
...
...
tests/helpers.py
View file @
7f2d405a
...
...
@@ -178,6 +178,9 @@ class PoetryTestApplication(Application):
class
TestLocker
(
Locker
):
# class name begins 'Test': tell pytest that it does not contain testcases.
__test__
=
False
def
__init__
(
self
,
lock
:
Path
,
local_config
:
dict
)
->
None
:
self
.
_lock
=
lock
self
.
_local_config
=
local_config
...
...
tests/installation/test_executor.py
View file @
7f2d405a
...
...
@@ -901,7 +901,7 @@ def test_executor_should_write_pep610_url_references_for_non_wheel_urls(
def
mock_get_cached_archive_for_link_func
(
_
:
Link
,
*
,
strict
:
bool
,
**
__
:
Any
)
->
None
:
)
->
Path
|
None
:
if
is_wheel_cached
and
not
strict
:
return
cached_wheel
if
is_sdist_cached
:
...
...
tests/installation/test_installer.py
View file @
7f2d405a
...
...
@@ -9,11 +9,11 @@ from typing import Any
import
pytest
from
cleo.io.buffered_io
import
BufferedIO
from
cleo.io.inputs.input
import
Input
from
cleo.io.io
import
IO
from
cleo.io.null_io
import
NullIO
from
cleo.io.outputs.buffered_output
import
BufferedOutput
from
cleo.io.outputs.output
import
Verbosity
from
packaging.utils
import
canonicalize_name
from
poetry.core.packages.dependency_group
import
MAIN_GROUP
from
poetry.core.packages.dependency_group
import
DependencyGroup
from
poetry.core.packages.package
import
Package
...
...
@@ -42,7 +42,6 @@ if TYPE_CHECKING:
from
pytest_mock
import
MockerFixture
from
poetry.installation.operations.operation
import
Operation
from
poetry.packages
import
DependencyPackage
from
poetry.utils.env
import
Env
from
tests.conftest
import
Config
from
tests.types
import
FixtureDirGetter
...
...
@@ -55,19 +54,19 @@ class Executor(BaseExecutor):
super
()
.
__init__
(
*
args
,
**
kwargs
)
self
.
_installs
:
list
[
Package
]
=
[]
self
.
_updates
:
list
[
Dependency
Package
]
=
[]
self
.
_uninstalls
:
list
[
Dependency
Package
]
=
[]
self
.
_updates
:
list
[
Package
]
=
[]
self
.
_uninstalls
:
list
[
Package
]
=
[]
@property
def
installations
(
self
)
->
list
[
Package
]:
return
self
.
_installs
@property
def
updates
(
self
)
->
list
[
Dependency
Package
]:
def
updates
(
self
)
->
list
[
Package
]:
return
self
.
_updates
@property
def
removals
(
self
)
->
list
[
Dependency
Package
]:
def
removals
(
self
)
->
list
[
Package
]:
return
self
.
_uninstalls
def
_do_execute_operation
(
self
,
operation
:
Operation
)
->
int
:
...
...
@@ -105,7 +104,8 @@ class Locker(BaseLocker):
self
.
_content_hash
=
self
.
_get_content_hash
()
@property
def
written_data
(
self
)
->
dict
[
str
,
Any
]
|
None
:
def
written_data
(
self
)
->
dict
[
str
,
Any
]:
assert
self
.
_written_data
is
not
None
return
self
.
_written_data
def
set_lock_path
(
self
,
lock
:
Path
)
->
Locker
:
...
...
@@ -435,7 +435,9 @@ def test_run_install_does_not_remove_locked_packages_if_installed_but_not_requir
installed
.
add_package
(
package
)
# Root package never removed.
package
.
add_dependency
(
Factory
.
create_dependency
(
package_a
.
name
,
package_a
.
version
))
package
.
add_dependency
(
Factory
.
create_dependency
(
package_a
.
name
,
str
(
package_a
.
version
))
)
locker
.
locked
(
True
)
locker
.
mock_lock_data
(
...
...
@@ -503,7 +505,9 @@ def test_run_install_removes_locked_packages_if_installed_and_synchronization_is
installed
.
add_package
(
package
)
# Root package never removed.
package
.
add_dependency
(
Factory
.
create_dependency
(
package_a
.
name
,
package_a
.
version
))
package
.
add_dependency
(
Factory
.
create_dependency
(
package_a
.
name
,
str
(
package_a
.
version
))
)
locker
.
locked
(
True
)
locker
.
mock_lock_data
(
...
...
@@ -571,7 +575,9 @@ def test_run_install_removes_no_longer_locked_packages_if_installed(
installed
.
add_package
(
package
)
# Root package never removed.
package
.
add_dependency
(
Factory
.
create_dependency
(
package_a
.
name
,
package_a
.
version
))
package
.
add_dependency
(
Factory
.
create_dependency
(
package_a
.
name
,
str
(
package_a
.
version
))
)
locker
.
locked
(
True
)
locker
.
mock_lock_data
(
...
...
@@ -664,7 +670,9 @@ def test_run_install_with_synchronization(
installed
.
add_package
(
package
)
# Root package never removed.
package
.
add_dependency
(
Factory
.
create_dependency
(
package_a
.
name
,
package_a
.
version
))
package
.
add_dependency
(
Factory
.
create_dependency
(
package_a
.
name
,
str
(
package_a
.
version
))
)
locker
.
locked
(
True
)
locker
.
mock_lock_data
(
...
...
@@ -878,7 +886,7 @@ def test_run_with_optional_and_python_restricted_dependencies(
repo
.
add_package
(
package_c13
)
repo
.
add_package
(
package_d
)
package
.
extras
=
{
"foo"
:
[
get_dependency
(
"A"
,
"~1.0"
)]}
package
.
extras
=
{
canonicalize_name
(
"foo"
)
:
[
get_dependency
(
"A"
,
"~1.0"
)]}
package
.
add_dependency
(
Factory
.
create_dependency
(
"A"
,
{
"version"
:
"~1.0"
,
"optional"
:
True
})
)
...
...
@@ -925,7 +933,7 @@ def test_run_with_optional_and_platform_restricted_dependencies(
repo
.
add_package
(
package_c13
)
repo
.
add_package
(
package_d
)
package
.
extras
=
{
"foo"
:
[
get_dependency
(
"A"
,
"~1.0"
)]}
package
.
extras
=
{
canonicalize_name
(
"foo"
)
:
[
get_dependency
(
"A"
,
"~1.0"
)]}
package
.
add_dependency
(
Factory
.
create_dependency
(
"A"
,
{
"version"
:
"~1.0"
,
"optional"
:
True
})
)
...
...
@@ -957,7 +965,7 @@ def test_run_with_dependencies_extras(
package_b
=
get_package
(
"B"
,
"1.0"
)
package_c
=
get_package
(
"C"
,
"1.0"
)
package_b
.
extras
=
{
"foo"
:
[
get_dependency
(
"C"
,
"^1.0"
)]}
package_b
.
extras
=
{
canonicalize_name
(
"foo"
)
:
[
get_dependency
(
"C"
,
"^1.0"
)]}
package_b
.
add_dependency
(
Factory
.
create_dependency
(
"C"
,
{
"version"
:
"^1.0"
,
"optional"
:
True
})
)
...
...
@@ -991,11 +999,11 @@ def test_run_with_dependencies_nested_extras(
)
dependency_a
=
Factory
.
create_dependency
(
"A"
,
{
"version"
:
"^1.0"
,
"extras"
:
[
"B"
]})
package_b
.
extras
=
{
"c"
:
[
dependency_c
]}
package_b
.
extras
=
{
canonicalize_name
(
"c"
)
:
[
dependency_c
]}
package_b
.
add_dependency
(
dependency_c
)
package_a
.
add_dependency
(
dependency_b
)
package_a
.
extras
=
{
"b"
:
[
dependency_b
]}
package_a
.
extras
=
{
canonicalize_name
(
"b"
)
:
[
dependency_b
]}
repo
.
add_package
(
package_a
)
repo
.
add_package
(
package_b
)
...
...
@@ -1013,7 +1021,7 @@ def test_run_with_dependencies_nested_extras(
def
test_run_does_not_install_extras_if_not_requested
(
installer
:
Installer
,
locker
:
Locker
,
repo
:
Repository
,
package
:
ProjectPackage
)
->
None
:
package
.
extras
[
"foo"
]
=
[
get_dependency
(
"D"
)]
package
.
extras
[
canonicalize_name
(
"foo"
)
]
=
[
get_dependency
(
"D"
)]
package_a
=
get_package
(
"A"
,
"1.0"
)
package_b
=
get_package
(
"B"
,
"1.0"
)
package_c
=
get_package
(
"C"
,
"1.0"
)
...
...
@@ -1045,7 +1053,7 @@ def test_run_does_not_install_extras_if_not_requested(
def
test_run_installs_extras_if_requested
(
installer
:
Installer
,
locker
:
Locker
,
repo
:
Repository
,
package
:
ProjectPackage
)
->
None
:
package
.
extras
[
"foo"
]
=
[
get_dependency
(
"D"
)]
package
.
extras
[
canonicalize_name
(
"foo"
)
]
=
[
get_dependency
(
"D"
)]
package_a
=
get_package
(
"A"
,
"1.0"
)
package_b
=
get_package
(
"B"
,
"1.0"
)
package_c
=
get_package
(
"C"
,
"1.0"
)
...
...
@@ -1078,7 +1086,7 @@ def test_run_installs_extras_if_requested(
def
test_run_installs_extras_with_deps_if_requested
(
installer
:
Installer
,
locker
:
Locker
,
repo
:
Repository
,
package
:
ProjectPackage
)
->
None
:
package
.
extras
[
"foo"
]
=
[
get_dependency
(
"C"
)]
package
.
extras
[
canonicalize_name
(
"foo"
)
]
=
[
get_dependency
(
"C"
)]
package_a
=
get_package
(
"A"
,
"1.0"
)
package_b
=
get_package
(
"B"
,
"1.0"
)
package_c
=
get_package
(
"C"
,
"1.0"
)
...
...
@@ -1115,7 +1123,7 @@ def test_run_installs_extras_with_deps_if_requested_locked(
)
->
None
:
locker
.
locked
(
True
)
locker
.
mock_lock_data
(
fixture
(
"extras-with-dependencies"
))
package
.
extras
[
"foo"
]
=
[
get_dependency
(
"C"
)]
package
.
extras
[
canonicalize_name
(
"foo"
)
]
=
[
get_dependency
(
"C"
)]
package_a
=
get_package
(
"A"
,
"1.0"
)
package_b
=
get_package
(
"B"
,
"1.0"
)
package_c
=
get_package
(
"C"
,
"1.0"
)
...
...
@@ -1285,14 +1293,12 @@ def test_run_installs_with_local_poetry_directory_and_skip_directory_flag(
result
=
installer
.
run
()
assert
result
==
0
executor
:
Executor
=
installer
.
executor
# type: ignore
expected
=
fixture
(
"with-directory-dependency-poetry-transitive"
)
assert
locker
.
written_data
==
expected
directory_installs
=
[
p
.
name
for
p
in
executor
.
installations
if
p
.
source_type
==
"directory"
p
.
name
for
p
in
installer
.
executor
.
installations
if
p
.
source_type
==
"directory"
]
if
skip_directory
:
...
...
@@ -1496,9 +1502,9 @@ def test_run_update_with_locked_extras(
}
)
package_a
=
get_package
(
"A"
,
"1.0"
)
package_a
.
extras
[
"foo"
]
=
[
get_dependency
(
"B"
)]
package_a
.
extras
[
canonicalize_name
(
"foo"
)
]
=
[
get_dependency
(
"B"
)]
b_dependency
=
get_dependency
(
"B"
,
"^1.0"
,
optional
=
True
)
b_dependency
.
in_extras
.
append
(
"foo"
)
b_dependency
.
in_extras
.
append
(
canonicalize_name
(
"foo"
)
)
c_dependency
=
get_dependency
(
"C"
,
"^1.0"
)
c_dependency
.
python_versions
=
"~2.7"
package_a
.
add_dependency
(
b_dependency
)
...
...
@@ -1890,7 +1896,7 @@ def test_installer_required_extras_should_not_be_removed_when_updating_single_de
package_b
.
add_dependency
(
Factory
.
create_dependency
(
"C"
,
{
"version"
:
"^1.0"
,
"optional"
:
True
})
)
package_b
.
extras
=
{
"foo"
:
[
get_dependency
(
"C"
)]}
package_b
.
extras
=
{
canonicalize_name
(
"foo"
)
:
[
get_dependency
(
"C"
)]}
package_c
=
get_package
(
"C"
,
"1.0.0"
)
package_d
=
get_package
(
"D"
,
"1.0.0"
)
...
...
@@ -2138,7 +2144,7 @@ def test_update_multiple_times_with_split_dependencies_is_idempotent(
def
test_installer_can_install_dependencies_from_forced_source
(
locker
:
Locker
,
package
:
Package
,
package
:
P
rojectP
ackage
,
installed
:
CustomInstalledRepository
,
env
:
NullEnv
,
config
:
Config
,
...
...
@@ -2379,7 +2385,7 @@ def test_run_with_dependencies_quiet(
repo
.
add_package
(
package_a
)
repo
.
add_package
(
package_b
)
installer
.
_io
=
IO
(
Input
(),
BufferedOutput
(),
BufferedOut
put
())
installer
.
_io
=
BufferedIO
(
In
put
())
installer
.
_io
.
set_verbosity
(
Verbosity
.
QUIET
if
quiet
else
Verbosity
.
NORMAL
)
package
.
add_dependency
(
Factory
.
create_dependency
(
"A"
,
"~1.0"
))
...
...
@@ -2391,11 +2397,11 @@ def test_run_with_dependencies_quiet(
expected
=
fixture
(
"with-dependencies"
)
assert
locker
.
written_data
==
expected
installer
.
_io
.
output
.
_buffer
.
seek
(
0
)
output
=
installer
.
_io
.
fetch_output
(
)
if
quiet
:
assert
installer
.
_io
.
output
.
_buffer
.
read
()
==
""
assert
output
==
""
else
:
assert
installer
.
_io
.
output
.
_buffer
.
read
()
!=
""
assert
output
!=
""
def
test_installer_should_use_the_locked_version_of_git_dependencies
(
...
...
tests/mixology/solutions/providers/test_python_requirement_solution_provider.py
View file @
7f2d405a
...
...
@@ -10,7 +10,7 @@ from poetry.mixology.term import Term
from
poetry.puzzle.exceptions
import
SolverProblemError
def
test_it_can_solve_python_incompatibility_solver_errors
():
def
test_it_can_solve_python_incompatibility_solver_errors
()
->
None
:
from
poetry.mixology.solutions.providers
import
PythonRequirementSolutionProvider
from
poetry.mixology.solutions.solutions
import
PythonRequirementSolution
...
...
@@ -24,7 +24,7 @@ def test_it_can_solve_python_incompatibility_solver_errors():
assert
isinstance
(
provider
.
get_solutions
(
exception
)[
0
],
PythonRequirementSolution
)
def
test_it_cannot_solve_other_solver_errors
():
def
test_it_cannot_solve_other_solver_errors
()
->
None
:
from
poetry.mixology.solutions.providers
import
PythonRequirementSolutionProvider
incompatibility
=
Incompatibility
(
...
...
tests/mixology/solutions/solutions/test_python_requirement_solution.py
View file @
7f2d405a
...
...
@@ -10,7 +10,7 @@ from poetry.mixology.term import Term
from
poetry.puzzle.exceptions
import
SolverProblemError
def
test_it_provides_the_correct_solution
():
def
test_it_provides_the_correct_solution
()
->
None
:
from
poetry.mixology.solutions.solutions
import
PythonRequirementSolution
incompatibility
=
Incompatibility
(
...
...
tests/puzzle/test_transaction.py
View file @
7f2d405a
...
...
@@ -5,6 +5,7 @@ from typing import Any
from
poetry.core.packages.package
import
Package
from
poetry.installation.operations.update
import
Update
from
poetry.puzzle.transaction
import
Transaction
...
...
@@ -20,6 +21,7 @@ def check_operations(ops: list[Operation], expected: list[dict[str, Any]]) -> No
result
=
[]
for
op
in
ops
:
if
op
.
job_type
==
"update"
:
assert
isinstance
(
op
,
Update
)
result
.
append
(
{
"job"
:
"update"
,
...
...
@@ -38,7 +40,7 @@ def check_operations(ops: list[Operation], expected: list[dict[str, Any]]) -> No
assert
result
==
expected
def
test_it_should_calculate_operations_in_correct_order
():
def
test_it_should_calculate_operations_in_correct_order
()
->
None
:
transaction
=
Transaction
(
[
Package
(
"a"
,
"1.0.0"
),
Package
(
"b"
,
"2.0.0"
),
Package
(
"c"
,
"3.0.0"
)],
[
...
...
@@ -58,7 +60,7 @@ def test_it_should_calculate_operations_in_correct_order():
)
def
test_it_should_calculate_operations_for_installed_packages
():
def
test_it_should_calculate_operations_for_installed_packages
()
->
None
:
transaction
=
Transaction
(
[
Package
(
"a"
,
"1.0.0"
),
Package
(
"b"
,
"2.0.0"
),
Package
(
"c"
,
"3.0.0"
)],
[
...
...
@@ -89,7 +91,7 @@ def test_it_should_calculate_operations_for_installed_packages():
)
def
test_it_should_remove_installed_packages_if_required
():
def
test_it_should_remove_installed_packages_if_required
()
->
None
:
transaction
=
Transaction
(
[
Package
(
"a"
,
"1.0.0"
),
Package
(
"b"
,
"2.0.0"
),
Package
(
"c"
,
"3.0.0"
)],
[
...
...
@@ -121,7 +123,7 @@ def test_it_should_remove_installed_packages_if_required():
)
def
test_it_should_not_remove_installed_packages_that_are_in_result
():
def
test_it_should_not_remove_installed_packages_that_are_in_result
()
->
None
:
transaction
=
Transaction
(
[],
[
...
...
@@ -146,7 +148,7 @@ def test_it_should_not_remove_installed_packages_that_are_in_result():
)
def
test_it_should_update_installed_packages_if_sources_are_different
():
def
test_it_should_update_installed_packages_if_sources_are_different
()
->
None
:
transaction
=
Transaction
(
[
Package
(
"a"
,
"1.0.0"
)],
[
...
...
tests/repositories/test_legacy_repository.py
View file @
7f2d405a
...
...
@@ -172,7 +172,7 @@ def test_get_package_information_skips_dependencies_with_invalid_constraints() -
Dependency
(
"python-jsonrpc-server"
,
"*"
),
]
all_extra
=
package
.
extras
[
"all"
]
all_extra
=
package
.
extras
[
canonicalize_name
(
"all"
)
]
# rope>-0.10.5 should be discarded
assert
sorted
(
all_extra
,
key
=
lambda
r
:
r
.
name
)
==
[
...
...
@@ -426,7 +426,7 @@ def test_package_yanked(
assert
package
.
yanked_reason
==
yanked_reason
def
test_package_partial_yank
():
def
test_package_partial_yank
()
->
None
:
class
SpecialMockRepository
(
MockRepository
):
def
_get_page
(
self
,
name
:
NormalizedName
)
->
SimpleRepositoryPage
:
return
super
()
.
_get_page
(
canonicalize_name
(
f
"{name}-partial-yank"
))
...
...
@@ -464,7 +464,7 @@ def test_find_links_for_package_yanked(
class
MockHttpRepository
(
LegacyRepository
):
def
__init__
(
self
,
endpoint_responses
:
dict
,
http
:
type
[
httpretty
.
httpretty
]
self
,
endpoint_responses
:
dict
[
str
,
int
]
,
http
:
type
[
httpretty
.
httpretty
]
)
->
None
:
base_url
=
"http://legacy.foo.bar"
super
()
.
__init__
(
"legacy"
,
url
=
base_url
,
disable_cache
=
True
)
...
...
@@ -477,7 +477,7 @@ class MockHttpRepository(LegacyRepository):
def
test_get_200_returns_page
(
http
:
type
[
httpretty
.
httpretty
])
->
None
:
repo
=
MockHttpRepository
({
"/foo/"
:
200
},
http
)
assert
repo
.
get_page
(
"foo"
)
_
=
repo
.
get_page
(
"foo"
)
@pytest.mark.parametrize
(
"status_code"
,
[
401
,
403
,
404
])
...
...
tests/utils/test_cache.py
View file @
7f2d405a
...
...
@@ -200,7 +200,7 @@ def test_cachy_compatibility(
assert
cachy_file_cache
.
get
(
"key4"
)
==
test_obj
def
test_missing_cache_file
(
poetry_file_cache
:
FileCache
)
->
None
:
def
test_missing_cache_file
(
poetry_file_cache
:
FileCache
[
T
]
)
->
None
:
poetry_file_cache
.
put
(
"key1"
,
"value"
)
key1_path
=
(
...
...
@@ -213,7 +213,7 @@ def test_missing_cache_file(poetry_file_cache: FileCache) -> None:
assert
poetry_file_cache
.
get
(
"key1"
)
is
None
def
test_missing_cache_path
(
poetry_file_cache
:
FileCache
)
->
None
:
def
test_missing_cache_path
(
poetry_file_cache
:
FileCache
[
T
]
)
->
None
:
poetry_file_cache
.
put
(
"key1"
,
"value"
)
key1_partial_path
=
poetry_file_cache
.
path
/
"81/74/09/96/87/a2/"
...
...
@@ -237,7 +237,7 @@ def test_missing_cache_path(poetry_file_cache: FileCache) -> None:
],
)
def
test_detect_corrupted_cache_key_file
(
corrupt_payload
:
str
|
bytes
,
poetry_file_cache
:
FileCache
corrupt_payload
:
str
|
bytes
,
poetry_file_cache
:
FileCache
[
T
]
)
->
None
:
poetry_file_cache
.
put
(
"key1"
,
"value"
)
...
...
tests/utils/test_env.py
View file @
7f2d405a
...
...
@@ -248,7 +248,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
:
dict
[
str
,
Any
]
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
...
...
@@ -312,7 +312,7 @@ def test_activate_activates_existing_virtualenv_no_envs_file(
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
:
dict
[
str
,
Any
]
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
...
...
@@ -356,7 +356,7 @@ def test_activate_activates_same_virtualenv_with_envs_file(
m
.
assert_not_called
()
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
:
dict
[
str
,
Any
]
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
...
...
@@ -410,7 +410,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
)
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
:
dict
[
str
,
Any
]
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.6"
assert
envs
[
venv_name
][
"patch"
]
==
"3.6.6"
...
...
@@ -476,7 +476,7 @@ def test_activate_activates_recreates_for_different_patch(
remove_venv_m
.
assert_called_with
(
tmp_path
/
f
"{venv_name}-py3.7"
)
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
:
dict
[
str
,
Any
]
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
...
...
@@ -528,7 +528,7 @@ def test_activate_does_not_recreate_when_switching_minor(
remove_venv_m
.
assert_not_called
()
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
:
dict
[
str
,
Any
]
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.6"
assert
envs
[
venv_name
][
"patch"
]
==
"3.6.6"
...
...
@@ -901,8 +901,8 @@ def test_remove_keeps_dir_if_not_deleteable(
side_effect
=
check_output_wrapper
(
Version
.
parse
(
"3.6.6"
)),
)
def
err_on_rm_venv_only
(
path
:
Path
|
str
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
None
:
if
str
(
path
)
==
str
(
venv_path
):
def
err_on_rm_venv_only
(
path
:
Path
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
None
:
if
path
.
resolve
()
==
venv_path
.
resolve
(
):
raise
OSError
(
16
,
"Test error"
)
# ERRNO 16: Device or resource busy
else
:
remove_directory
(
path
)
...
...
@@ -1259,6 +1259,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
str
(
c
)
for
c
in
sys
.
version_info
[:
3
]
)
assert
version
.
patch
is
not
None
mocker
.
patch
(
"sys.version_info"
,
(
version
.
major
,
version
.
minor
,
version
.
patch
+
1
))
check_output
=
mocker
.
patch
(
"subprocess.check_output"
,
...
...
@@ -1296,6 +1297,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
del
os
.
environ
[
"VIRTUAL_ENV"
]
version
=
Version
.
from_parts
(
*
sys
.
version_info
[:
3
])
assert
version
.
minor
is
not
None
poetry
.
package
.
python_versions
=
f
"~{version.major}.{version.minor - 1}.0"
venv_name
=
manager
.
generate_env_name
(
"simple-project"
,
str
(
poetry
.
file
.
parent
))
...
...
@@ -1334,6 +1336,7 @@ def test_create_venv_fails_if_current_python_version_is_not_supported(
manager
.
create_venv
()
current_version
=
Version
.
parse
(
"."
.
join
(
str
(
c
)
for
c
in
sys
.
version_info
[:
3
]))
assert
current_version
.
minor
is
not
None
next_version
=
"."
.
join
(
str
(
c
)
for
c
in
(
current_version
.
major
,
current_version
.
minor
+
1
,
0
)
)
...
...
tests/utils/test_pip.py
View file @
7f2d405a
...
...
@@ -20,7 +20,7 @@ if TYPE_CHECKING:
def
test_pip_install_successful
(
tmp_path
:
Path
,
tmp_venv
:
VirtualEnv
,
fixture_dir
:
FixtureDirGetter
):
)
->
None
:
file_path
=
fixture_dir
(
"distributions/demo-0.1.0-py2.py3-none-any.whl"
)
result
=
pip_install
(
file_path
,
tmp_venv
)
...
...
@@ -32,7 +32,7 @@ def test_pip_install_with_keyboard_interrupt(
tmp_venv
:
VirtualEnv
,
fixture_dir
:
FixtureDirGetter
,
mocker
:
MockerFixture
,
):
)
->
None
:
file_path
=
fixture_dir
(
"distributions/demo-0.1.0-py2.py3-none-any.whl"
)
mocker
.
patch
(
"subprocess.run"
,
side_effect
=
KeyboardInterrupt
())
with
pytest
.
raises
(
KeyboardInterrupt
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment