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
5a9da19f
Unverified
Commit
5a9da19f
authored
Apr 12, 2023
by
David Hotham
Committed by
GitHub
Apr 12, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tidying (#7779)
parent
71754bcd
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
47 changed files
with
207 additions
and
248 deletions
+207
-248
pyproject.toml
+0
-1
src/poetry/config/config.py
+1
-1
src/poetry/console/commands/init.py
+1
-4
src/poetry/console/commands/new.py
+1
-4
src/poetry/console/commands/self/show/plugins.py
+2
-2
src/poetry/console/commands/show.py
+1
-4
src/poetry/console/io/inputs/run_argv_input.py
+2
-5
src/poetry/installation/chef.py
+2
-2
src/poetry/installation/installer.py
+1
-4
src/poetry/installation/wheel_installer.py
+2
-3
src/poetry/json/__init__.py
+2
-3
src/poetry/layouts/layout.py
+3
-3
src/poetry/mixology/version_solver.py
+2
-2
src/poetry/plugins/plugin_manager.py
+1
-1
src/poetry/puzzle/provider.py
+1
-1
src/poetry/puzzle/solver.py
+1
-1
src/poetry/repositories/pypi_repository.py
+2
-2
src/poetry/utils/_compat.py
+0
-5
src/poetry/utils/cache.py
+4
-3
src/poetry/utils/env.py
+4
-6
src/poetry/utils/extras.py
+1
-1
src/poetry/utils/helpers.py
+4
-4
src/poetry/utils/setup_reader.py
+1
-1
tests/compat.py
+4
-2
tests/conftest.py
+10
-21
tests/console/commands/source/test_add.py
+6
-6
tests/console/commands/source/test_remove.py
+2
-2
tests/console/commands/source/test_show.py
+6
-4
tests/console/commands/test_init.py
+3
-4
tests/console/commands/test_show.py
+38
-32
tests/helpers.py
+1
-1
tests/inspection/test_info.py
+24
-30
tests/installation/test_chooser.py
+8
-8
tests/mixology/helpers.py
+5
-3
tests/mixology/version_solver/test_backtracking.py
+10
-8
tests/mixology/version_solver/test_basic_graph.py
+4
-4
tests/mixology/version_solver/test_dependency_cache.py
+2
-2
tests/mixology/version_solver/test_python_constraint.py
+1
-1
tests/mixology/version_solver/test_unsolvable.py
+9
-7
tests/mixology/version_solver/test_with_lock.py
+9
-8
tests/publishing/test_publisher.py
+7
-7
tests/publishing/test_uploader.py
+10
-10
tests/puzzle/test_provider.py
+1
-11
tests/repositories/test_legacy_repository.py
+1
-5
tests/repositories/test_pypi_repository.py
+3
-6
tests/types.py
+2
-0
tests/utils/test_env_site.py
+2
-3
No files found.
pyproject.toml
View file @
5a9da19f
...
...
@@ -169,7 +169,6 @@ enable_error_code = [
# warning.
[[tool.mypy.overrides]]
module
=
[
'poetry.console.commands.self.show.plugins'
,
'poetry.plugins.plugin_manager'
,
'poetry.repositories.installed_repository'
,
'poetry.utils.env'
,
...
...
src/poetry/config/config.py
View file @
5a9da19f
...
...
@@ -199,7 +199,7 @@ class Config:
repositories
=
{}
pattern
=
re
.
compile
(
r"POETRY_REPOSITORIES_(?P<name>[A-Z_]+)_URL"
)
for
env_key
in
os
.
environ
.
keys
()
:
for
env_key
in
os
.
environ
:
match
=
pattern
.
match
(
env_key
)
if
match
:
repositories
[
match
.
group
(
"name"
)
.
lower
()
.
replace
(
"_"
,
"-"
)]
=
{
...
...
src/poetry/console/commands/init.py
View file @
5a9da19f
...
...
@@ -149,10 +149,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
question
.
set_validator
(
lambda
v
:
self
.
_validate_author
(
v
,
author
))
author
=
self
.
ask
(
question
)
if
not
author
:
authors
=
[]
else
:
authors
=
[
author
]
authors
=
[
author
]
if
author
else
[]
license
=
self
.
option
(
"license"
)
if
not
license
:
...
...
src/poetry/console/commands/new.py
View file @
5a9da19f
...
...
@@ -39,10 +39,7 @@ class NewCommand(Command):
" be ignored. You should consider the option --path instead.</warning>"
)
if
self
.
option
(
"src"
):
layout_cls
=
layout
(
"src"
)
else
:
layout_cls
=
layout
(
"standard"
)
layout_cls
=
layout
(
"src"
)
if
self
.
option
(
"src"
)
else
layout
(
"standard"
)
path
=
Path
(
self
.
argument
(
"path"
))
if
not
path
.
is_absolute
():
...
...
src/poetry/console/commands/self/show/plugins.py
View file @
5a9da19f
...
...
@@ -25,14 +25,14 @@ class PluginPackage:
from
poetry.plugins.application_plugin
import
ApplicationPlugin
from
poetry.plugins.plugin
import
Plugin
group
=
entry_point
.
group
# type: ignore[attr-defined]
group
=
entry_point
.
group
if
group
==
ApplicationPlugin
.
group
:
self
.
application_plugins
.
append
(
entry_point
)
elif
group
==
Plugin
.
group
:
self
.
plugins
.
append
(
entry_point
)
else
:
name
=
entry_point
.
name
# type: ignore[attr-defined]
name
=
entry_point
.
name
raise
ValueError
(
f
"Unknown plugin group ({group}) for {name}"
)
...
...
src/poetry/console/commands/show.py
View file @
5a9da19f
...
...
@@ -142,10 +142,7 @@ lists all packages available."""
packages
=
[
pkg
]
if
required_by
:
packages
=
[
p
for
p
in
locked_packages
for
r
in
required_by
.
keys
()
if
p
.
name
==
r
p
for
p
in
locked_packages
for
r
in
required_by
if
p
.
name
==
r
]
else
:
# if no rev-deps exist we'll make this clear as it can otherwise
...
...
src/poetry/console/io/inputs/run_argv_input.py
View file @
5a9da19f
...
...
@@ -43,12 +43,9 @@ class RunArgvInput(ArgvInput):
# Options with values:
# For long options, test for '--option=' at beginning
# For short options, test for '-o' at beginning
if
value
.
find
(
"--"
)
==
0
:
leading
=
value
+
"="
else
:
leading
=
value
leading
=
value
+
"="
if
value
.
startswith
(
"--"
)
else
value
if
token
==
value
or
leading
!=
""
and
token
.
find
(
leading
)
==
0
:
if
token
==
value
or
leading
!=
""
and
token
.
startswith
(
leading
)
:
return
True
return
False
...
...
src/poetry/installation/chef.py
View file @
5a9da19f
...
...
@@ -8,8 +8,6 @@ from contextlib import redirect_stdout
from
io
import
StringIO
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
Callable
from
typing
import
Collection
from
build
import
BuildBackendException
from
build
import
ProjectBuilder
...
...
@@ -22,6 +20,8 @@ from poetry.utils.env import ephemeral_environment
if
TYPE_CHECKING
:
from
collections.abc
import
Callable
from
collections.abc
import
Collection
from
contextlib
import
AbstractContextManager
from
poetry.repositories
import
RepositoryPool
...
...
src/poetry/installation/installer.py
View file @
5a9da19f
...
...
@@ -554,10 +554,7 @@ class Installer:
def
_filter_operations
(
self
,
ops
:
Iterable
[
Operation
],
repo
:
Repository
)
->
None
:
extra_packages
=
self
.
_get_extra_packages
(
repo
)
for
op
in
ops
:
if
isinstance
(
op
,
Update
):
package
=
op
.
target_package
else
:
package
=
op
.
package
package
=
op
.
target_package
if
isinstance
(
op
,
Update
)
else
op
.
package
if
op
.
job_type
==
"uninstall"
:
continue
...
...
src/poetry/installation/wheel_installer.py
View file @
5a9da19f
from
__future__
import
annotations
import
os
import
platform
import
sys
...
...
@@ -51,9 +50,9 @@ class WheelDestination(SchemeDictionaryDestination):
if
not
parent_folder
.
exists
():
# Due to the parallel installation it can happen
# that two threads try to create the directory.
os
.
makedirs
(
parent_folder
,
exist_ok
=
True
)
parent_folder
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
with
open
(
target_path
,
"wb"
)
as
f
:
with
target_path
.
open
(
"wb"
)
as
f
:
hash_
,
size
=
copyfileobj_with_hashing
(
stream
,
f
,
self
.
hash_algorithm
)
if
is_executable
:
...
...
src/poetry/json/__init__.py
View file @
5a9da19f
from
__future__
import
annotations
import
json
import
os
from
pathlib
import
Path
from
typing
import
Any
...
...
@@ -11,7 +10,7 @@ import jsonschema
from
poetry.core.json
import
SCHEMA_DIR
as
CORE_SCHEMA_DIR
SCHEMA_DIR
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"schemas"
)
SCHEMA_DIR
=
Path
(
__file__
)
.
parent
/
"schemas"
class
ValidationError
(
ValueError
):
...
...
@@ -39,7 +38,7 @@ def validate_object(obj: dict[str, Any]) -> list[str]:
errors
.
append
(
message
)
core_schema
=
json
.
loads
(
Path
(
CORE_SCHEMA_DIR
,
"poetry-schema.json"
)
.
read_text
(
encoding
=
"utf-8"
)
(
CORE_SCHEMA_DIR
/
"poetry-schema.json"
)
.
read_text
(
encoding
=
"utf-8"
)
)
properties
=
{
*
schema
[
"properties"
]
.
keys
(),
*
core_schema
[
"properties"
]
.
keys
()}
...
...
src/poetry/layouts/layout.py
View file @
5a9da19f
...
...
@@ -15,7 +15,7 @@ from poetry.pyproject.toml import PyProjectTOML
if
TYPE_CHECKING
:
from
typing
import
Mapping
from
collections.abc
import
Mapping
from
tomlkit.items
import
InlineTable
...
...
@@ -49,8 +49,8 @@ class Layout:
author
:
str
|
None
=
None
,
license
:
str
|
None
=
None
,
python
:
str
=
"*"
,
dependencies
:
dict
[
str
,
str
|
Mapping
[
str
,
Any
]]
|
None
=
None
,
dev_dependencies
:
dict
[
str
,
str
|
Mapping
[
str
,
Any
]]
|
None
=
None
,
dependencies
:
Mapping
[
str
,
str
|
Mapping
[
str
,
Any
]]
|
None
=
None
,
dev_dependencies
:
Mapping
[
str
,
str
|
Mapping
[
str
,
Any
]]
|
None
=
None
,
)
->
None
:
self
.
_project
=
canonicalize_name
(
project
)
self
.
_package_path_relative
=
Path
(
...
...
src/poetry/mixology/version_solver.py
View file @
5a9da19f
...
...
@@ -320,8 +320,8 @@ class VersionSolver:
# The most_recent_satisfier may not satisfy most_recent_term on its own
# if there are a collection of constraints on most_recent_term that
# only satisfy it together. For example, if most_recent_term is
# `foo
^1.0.0` and _solution contains `[foo >=1.0.0,
# foo
<2.0.0]`, then most_recent_satisfier will be `foo <2.0.0` even
# `foo
^1.0.0` and _solution contains `[foo >=1.0.0,
# foo
<2.0.0]`, then most_recent_satisfier will be `foo <2.0.0` even
# though it doesn't totally satisfy `foo ^1.0.0`.
#
# In this case, we add `not (most_recent_satisfier \ most_recent_term)` to
...
...
src/poetry/plugins/plugin_manager.py
View file @
5a9da19f
...
...
@@ -71,7 +71,7 @@ class PluginManager:
plugin
.
activate
(
*
args
,
**
kwargs
)
def
_load_plugin_entry_point
(
self
,
ep
:
metadata
.
EntryPoint
)
->
None
:
logger
.
debug
(
"Loading the
%
s plugin"
,
ep
.
name
)
# type: ignore[attr-defined]
logger
.
debug
(
"Loading the
%
s plugin"
,
ep
.
name
)
plugin
=
ep
.
load
()
# type: ignore[no-untyped-call]
...
...
src/poetry/puzzle/provider.py
View file @
5a9da19f
...
...
@@ -12,7 +12,6 @@ from collections import defaultdict
from
contextlib
import
contextmanager
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
Collection
from
typing
import
cast
from
cleo.ui.progress_indicator
import
ProgressIndicator
...
...
@@ -40,6 +39,7 @@ from poetry.vcs.git import Git
if
TYPE_CHECKING
:
from
collections.abc
import
Callable
from
collections.abc
import
Collection
from
collections.abc
import
Iterable
from
collections.abc
import
Iterator
...
...
src/poetry/puzzle/solver.py
View file @
5a9da19f
...
...
@@ -5,7 +5,6 @@ import time
from
collections
import
defaultdict
from
contextlib
import
contextmanager
from
typing
import
TYPE_CHECKING
from
typing
import
Collection
from
typing
import
FrozenSet
from
typing
import
Tuple
from
typing
import
TypeVar
...
...
@@ -21,6 +20,7 @@ from poetry.puzzle.provider import Provider
if
TYPE_CHECKING
:
from
collections.abc
import
Collection
from
collections.abc
import
Iterator
from
cleo.io.io
import
IO
...
...
src/poetry/repositories/pypi_repository.py
View file @
5a9da19f
...
...
@@ -17,7 +17,7 @@ from poetry.core.version.exceptions import InvalidVersion
from
poetry.repositories.exceptions
import
PackageNotFound
from
poetry.repositories.http_repository
import
HTTPRepository
from
poetry.repositories.link_sources.json
import
SimpleJsonPage
from
poetry.utils._compat
import
to_str
from
poetry.utils._compat
import
decode
from
poetry.utils.constants
import
REQUESTS_TIMEOUT
...
...
@@ -82,7 +82,7 @@ class PyPiRepository(HTTPRepository):
try
:
package
=
Package
(
name
,
version
)
package
.
description
=
to_str
(
description
.
strip
())
package
.
description
=
decode
(
description
.
strip
())
results
.
append
(
package
)
except
InvalidVersion
:
self
.
_log
(
...
...
src/poetry/utils/_compat.py
View file @
5a9da19f
...
...
@@ -56,16 +56,11 @@ def encode(string: str, encodings: list[str] | None = None) -> bytes:
return
string
.
encode
(
encodings
[
0
],
errors
=
"ignore"
)
def
to_str
(
string
:
str
)
->
str
:
return
decode
(
string
)
__all__
=
[
"WINDOWS"
,
"cached_property"
,
"decode"
,
"encode"
,
"metadata"
,
"to_str"
,
"tomllib"
,
]
src/poetry/utils/cache.py
View file @
5a9da19f
...
...
@@ -10,7 +10,6 @@ import time
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
Any
from
typing
import
Callable
from
typing
import
Generic
from
typing
import
TypeVar
...
...
@@ -21,6 +20,8 @@ from poetry.utils.wheel import Wheel
if
TYPE_CHECKING
:
from
collections.abc
import
Callable
from
poetry.core.packages.utils.link
import
Link
from
poetry.utils.env
import
Env
...
...
@@ -108,7 +109,7 @@ class FileCache(Generic[T]):
)
path
=
self
.
_path
(
key
)
path
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
with
open
(
path
,
"wb"
)
as
f
:
with
path
.
open
(
"wb"
)
as
f
:
f
.
write
(
self
.
_serialize
(
payload
))
def
forget
(
self
,
key
:
str
)
->
None
:
...
...
@@ -149,7 +150,7 @@ class FileCache(Generic[T]):
if
not
path
.
exists
():
return
None
with
open
(
path
,
"rb"
)
as
f
:
with
path
.
open
(
"rb"
)
as
f
:
file_content
=
f
.
read
()
try
:
...
...
src/poetry/utils/env.py
View file @
5a9da19f
...
...
@@ -1234,10 +1234,7 @@ class Env:
path
=
get_real_windows_path
(
path
)
base
=
get_real_windows_path
(
base
)
if
base
else
None
if
not
self
.
_is_windows
or
self
.
_is_mingw
:
bin_dir
=
"bin"
else
:
bin_dir
=
"Scripts"
bin_dir
=
"bin"
if
not
self
.
_is_windows
or
self
.
_is_mingw
else
"Scripts"
self
.
_path
=
path
self
.
_bin_dir
=
self
.
_path
/
bin_dir
...
...
@@ -1268,8 +1265,9 @@ class Env:
return
self
.
_base
@property
def
version_info
(
self
)
->
tuple
[
Any
,
...
]:
return
tuple
(
self
.
marker_env
[
"version_info"
])
def
version_info
(
self
)
->
tuple
[
int
,
int
,
int
,
str
,
int
]:
version_info
:
tuple
[
int
,
int
,
int
,
str
,
int
]
=
self
.
marker_env
[
"version_info"
]
return
version_info
@property
def
python_implementation
(
self
)
->
str
:
...
...
src/poetry/utils/extras.py
View file @
5a9da19f
...
...
@@ -6,7 +6,7 @@ from typing import TYPE_CHECKING
if
TYPE_CHECKING
:
from
collections.abc
import
Collection
from
collections.abc
import
Iterable
from
typing
import
Mapping
from
collections.abc
import
Mapping
from
packaging.utils
import
NormalizedName
from
poetry.core.packages.package
import
Package
...
...
src/poetry/utils/helpers.py
View file @
5a9da19f
...
...
@@ -8,18 +8,18 @@ import stat
import
sys
import
tempfile
from
collections.abc
import
Mapping
from
contextlib
import
contextmanager
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
Any
from
typing
import
Iterator
from
typing
import
Mapping
from
poetry.utils.constants
import
REQUESTS_TIMEOUT
if
TYPE_CHECKING
:
from
collections.abc
import
Callable
from
collections.abc
import
Iterator
from
io
import
BufferedWriter
from
poetry.core.packages.package
import
Package
...
...
@@ -82,7 +82,7 @@ def remove_directory(
def
merge_dicts
(
d1
:
dict
[
str
,
Any
],
d2
:
dict
[
str
,
Any
])
->
None
:
for
k
in
d2
.
keys
()
:
for
k
in
d2
:
if
k
in
d1
and
isinstance
(
d1
[
k
],
dict
)
and
isinstance
(
d2
[
k
],
Mapping
):
merge_dicts
(
d1
[
k
],
d2
[
k
])
else
:
...
...
@@ -121,7 +121,7 @@ def download_file(
# but skip the updating
set_indicator
=
total_size
>
1024
*
1024
with
open
(
dest
,
"wb"
)
as
f
:
with
dest
.
open
(
"wb"
)
as
f
:
for
chunk
in
response
.
iter_content
(
chunk_size
=
chunk_size
):
if
chunk
:
f
.
write
(
chunk
)
...
...
src/poetry/utils/setup_reader.py
View file @
5a9da19f
...
...
@@ -39,7 +39,7 @@ class SetupReader:
read_file_func
=
getattr
(
cls
(),
"read_"
+
filename
.
replace
(
"."
,
"_"
))
new_result
=
read_file_func
(
filepath
)
for
key
in
result
.
keys
()
:
for
key
in
result
:
if
new_result
[
key
]:
result
[
key
]
=
new_result
[
key
]
...
...
tests/compat.py
View file @
5a9da19f
...
...
@@ -8,6 +8,8 @@ if sys.version_info < (3, 8):
from
typing_extensions
import
Protocol
# nopycln: import
else
:
import
zipfile
# noqa: F401
import
zipfile
from
typing
import
Protocol
# noqa: F401
from
typing
import
Protocol
__all__
=
[
"zipfile"
,
"Protocol"
]
tests/conftest.py
View file @
5a9da19f
...
...
@@ -11,7 +11,6 @@ from contextlib import suppress
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
Any
from
typing
import
TextIO
import
httpretty
import
pytest
...
...
@@ -41,6 +40,7 @@ from tests.helpers import mock_download
if
TYPE_CHECKING
:
from
collections.abc
import
Iterator
from
collections.abc
import
Mapping
from
_pytest.config
import
Config
as
PyTestConfig
from
_pytest.config.argparsing
import
Parser
...
...
@@ -70,6 +70,9 @@ def pytest_configure(config: PyTestConfig) -> None:
class
Config
(
BaseConfig
):
_config_source
:
DictConfigSource
_auth_config_source
:
DictConfigSource
def
get
(
self
,
setting_name
:
str
,
default
:
Any
=
None
)
->
Any
:
self
.
merge
(
self
.
_config_source
.
config
)
self
.
merge
(
self
.
_auth_config_source
.
config
)
...
...
@@ -91,7 +94,7 @@ class Config(BaseConfig):
class
DummyBackend
(
KeyringBackend
):
def
__init__
(
self
)
->
None
:
self
.
_passwords
=
{}
self
.
_passwords
:
dict
[
str
,
dict
[
str
|
None
,
str
|
None
]]
=
{}
@classmethod
def
priority
(
cls
)
->
int
:
...
...
@@ -303,30 +306,15 @@ def tmp_dir() -> Iterator[str]:
@pytest.fixture
def
mocked_open_files
(
mocker
:
MockerFixture
)
->
list
:
files
=
[]
original
=
Path
.
open
def
mocked_open
(
self
:
Path
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
TextIO
:
if
self
.
name
in
{
"pyproject.toml"
}:
return
mocker
.
MagicMock
()
return
original
(
self
,
*
args
,
**
kwargs
)
mocker
.
patch
(
"pathlib.Path.open"
,
mocked_open
)
return
files
@pytest.fixture
def
tmp_venv
(
tmp_dir
:
str
)
->
Iterator
[
VirtualEnv
]:
venv_path
=
Path
(
tmp_dir
)
/
"venv"
EnvManager
.
build_venv
(
str
(
venv_path
)
)
EnvManager
.
build_venv
(
venv_path
)
venv
=
VirtualEnv
(
venv_path
)
yield
venv
shutil
.
rmtree
(
str
(
venv
.
path
)
)
shutil
.
rmtree
(
venv
.
path
)
@pytest.fixture
...
...
@@ -371,8 +359,8 @@ def project_factory(
def
_factory
(
name
:
str
|
None
=
None
,
dependencies
:
dict
[
str
,
str
]
|
None
=
None
,
dev_dependencies
:
dict
[
str
,
str
]
|
None
=
None
,
dependencies
:
Mapping
[
str
,
str
]
|
None
=
None
,
dev_dependencies
:
Mapping
[
str
,
str
]
|
None
=
None
,
pyproject_content
:
str
|
None
=
None
,
poetry_lock_content
:
str
|
None
=
None
,
install_deps
:
bool
=
True
,
...
...
@@ -397,6 +385,7 @@ def project_factory(
)
as
f
:
f
.
write
(
pyproject_content
)
else
:
assert
name
is
not
None
layout
(
"src"
)(
name
,
"0.1.0"
,
...
...
tests/console/commands/source/test_add.py
View file @
5a9da19f
...
...
@@ -43,7 +43,7 @@ def test_source_add_simple(
source_existing
:
Source
,
source_one
:
Source
,
poetry_with_source
:
Poetry
,
):
)
->
None
:
tester
.
execute
(
f
"{source_one.name} {source_one.url}"
)
assert_source_added
(
tester
,
poetry_with_source
,
source_existing
,
source_one
)
...
...
@@ -53,7 +53,7 @@ def test_source_add_default(
source_existing
:
Source
,
source_default
:
Source
,
poetry_with_source
:
Poetry
,
):
)
->
None
:
tester
.
execute
(
f
"--default {source_default.name} {source_default.url}"
)
assert_source_added
(
tester
,
poetry_with_source
,
source_existing
,
source_default
)
...
...
@@ -63,12 +63,12 @@ def test_source_add_secondary(
source_existing
:
Source
,
source_secondary
:
Source
,
poetry_with_source
:
Poetry
,
):
)
->
None
:
tester
.
execute
(
f
"--secondary {source_secondary.name} {source_secondary.url}"
)
assert_source_added
(
tester
,
poetry_with_source
,
source_existing
,
source_secondary
)
def
test_source_add_error_default_and_secondary
(
tester
:
CommandTester
):
def
test_source_add_error_default_and_secondary
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
(
"--default --secondary error https://error.com"
)
assert
(
tester
.
io
.
fetch_error
()
.
strip
()
...
...
@@ -77,7 +77,7 @@ def test_source_add_error_default_and_secondary(tester: CommandTester):
assert
tester
.
status_code
==
1
def
test_source_add_error_pypi
(
tester
:
CommandTester
):
def
test_source_add_error_pypi
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
(
"pypi https://test.pypi.org/simple/"
)
assert
(
tester
.
io
.
fetch_error
()
.
strip
()
...
...
@@ -89,7 +89,7 @@ def test_source_add_error_pypi(tester: CommandTester):
def
test_source_add_existing
(
tester
:
CommandTester
,
source_existing
:
Source
,
poetry_with_source
:
Poetry
):
)
->
None
:
tester
.
execute
(
f
"--default {source_existing.name} {source_existing.url}"
)
assert
(
tester
.
io
.
fetch_output
()
.
strip
()
...
...
tests/console/commands/source/test_remove.py
View file @
5a9da19f
...
...
@@ -28,7 +28,7 @@ def test_source_remove_simple(
source_existing
:
Source
,
source_one
:
Source
,
source_two
:
Source
,
):
)
->
None
:
tester
.
execute
(
f
"{source_existing.name}"
)
assert
(
tester
.
io
.
fetch_output
()
.
strip
()
...
...
@@ -42,7 +42,7 @@ def test_source_remove_simple(
assert
tester
.
status_code
==
0
def
test_source_remove_error
(
tester
:
CommandTester
):
def
test_source_remove_error
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
(
"error"
)
assert
tester
.
io
.
fetch_error
()
.
strip
()
==
"Source with name error was not found."
assert
tester
.
status_code
==
1
tests/console/commands/source/test_show.py
View file @
5a9da19f
...
...
@@ -22,7 +22,7 @@ def tester(
return
command_tester_factory
(
"source show"
,
poetry
=
poetry_with_source
)
def
test_source_show_simple
(
tester
:
CommandTester
):
def
test_source_show_simple
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
(
""
)
expected
=
"""
\
...
...
@@ -47,7 +47,7 @@ secondary : no
assert
tester
.
status_code
==
0
def
test_source_show_one
(
tester
:
CommandTester
,
source_one
:
Source
):
def
test_source_show_one
(
tester
:
CommandTester
,
source_one
:
Source
)
->
None
:
tester
.
execute
(
f
"{source_one.name}"
)
expected
=
"""
\
...
...
@@ -62,7 +62,9 @@ secondary : no
assert
tester
.
status_code
==
0
def
test_source_show_two
(
tester
:
CommandTester
,
source_one
:
Source
,
source_two
:
Source
):
def
test_source_show_two
(
tester
:
CommandTester
,
source_one
:
Source
,
source_two
:
Source
)
->
None
:
tester
.
execute
(
f
"{source_one.name} {source_two.name}"
)
expected
=
"""
\
...
...
@@ -82,7 +84,7 @@ secondary : no
assert
tester
.
status_code
==
0
def
test_source_show_error
(
tester
:
CommandTester
):
def
test_source_show_error
(
tester
:
CommandTester
)
->
None
:
tester
.
execute
(
"error"
)
assert
tester
.
io
.
fetch_error
()
.
strip
()
==
"No source found with name(s): error"
assert
tester
.
status_code
==
1
tests/console/commands/test_init.py
View file @
5a9da19f
...
...
@@ -16,7 +16,6 @@ from packaging.utils import canonicalize_name
from
poetry.console.commands.init
import
InitCommand
from
poetry.repositories
import
RepositoryPool
from
poetry.utils._compat
import
decode
from
tests.helpers
import
PoetryTestApplication
from
tests.helpers
import
get_package
...
...
@@ -896,7 +895,7 @@ def test_init_existing_pyproject_simple(
[tool.black]
line-length = 88
"""
pyproject_file
.
write_text
(
decode
(
existing_section
)
)
pyproject_file
.
write_text
(
existing_section
)
tester
.
execute
(
inputs
=
init_basic_inputs
)
assert
f
"{existing_section}
\n
{init_basic_toml}"
in
pyproject_file
.
read_text
()
...
...
@@ -936,7 +935,7 @@ def test_init_non_interactive_existing_pyproject_add_dependency(
[tool.black]
line-length = 88
"""
pyproject_file
.
write_text
(
decode
(
existing_section
)
)
pyproject_file
.
write_text
(
existing_section
)
repo
.
add_package
(
get_package
(
"foo"
,
"1.19.2"
))
...
...
@@ -975,7 +974,7 @@ def test_init_existing_pyproject_with_build_system_fails(
requires = ["setuptools >= 40.6.0", "wheel"]
build-backend = "setuptools.build_meta"
"""
pyproject_file
.
write_text
(
decode
(
existing_section
)
)
pyproject_file
.
write_text
(
existing_section
)
tester
.
execute
(
inputs
=
init_basic_inputs
)
assert
(
tester
.
io
.
fetch_error
()
.
strip
()
...
...
tests/console/commands/test_show.py
View file @
5a9da19f
This diff is collapsed.
Click to expand it.
tests/helpers.py
View file @
5a9da19f
...
...
@@ -305,7 +305,7 @@ def flatten_dict(obj: Mapping[str, Any], delimiter: str = ".") -> Mapping[str, A
:return: dict
"""
if
isinstance
(
obj
,
dict
):
for
key
in
obj
.
keys
()
:
for
key
in
obj
:
for
leaf
in
recurse_keys
(
obj
[
key
]):
leaf_path
,
leaf_value
=
leaf
leaf_path
.
insert
(
0
,
key
)
...
...
tests/inspection/test_info.py
View file @
5a9da19f
...
...
@@ -8,7 +8,6 @@ import pytest
from
poetry.inspection.info
import
PackageInfo
from
poetry.inspection.info
import
PackageInfoError
from
poetry.utils._compat
import
decode
from
poetry.utils.env
import
EnvCommandError
from
poetry.utils.env
import
VirtualEnv
...
...
@@ -21,7 +20,7 @@ FIXTURE_DIR_INSPECTIONS = FIXTURE_DIR_BASE / "inspection"
@pytest.fixture
(
autouse
=
True
)
def
pep517_metadata_mock
():
def
pep517_metadata_mock
()
->
None
:
pass
...
...
@@ -44,13 +43,11 @@ def source_dir(tmp_path: Path) -> Path:
def
demo_setup
(
source_dir
:
Path
)
->
Path
:
setup_py
=
source_dir
/
"setup.py"
setup_py
.
write_text
(
decode
(
"from setuptools import setup; "
'setup(name="demo", '
'version="0.1.0", '
'install_requires=["package"])'
)
)
return
source_dir
...
...
@@ -58,7 +55,6 @@ def demo_setup(source_dir: Path) -> Path:
def
demo_setup_cfg
(
source_dir
:
Path
)
->
Path
:
setup_cfg
=
source_dir
/
"setup.cfg"
setup_cfg
.
write_text
(
decode
(
"
\n
"
.
join
(
[
"[metadata]"
,
...
...
@@ -69,7 +65,6 @@ def demo_setup_cfg(source_dir: Path) -> Path:
]
)
)
)
return
source_dir
...
...
@@ -77,26 +72,22 @@ def demo_setup_cfg(source_dir: Path) -> Path:
def
demo_setup_complex
(
source_dir
:
Path
)
->
Path
:
setup_py
=
source_dir
/
"setup.py"
setup_py
.
write_text
(
decode
(
"from setuptools import setup; "
'setup(name="demo", '
'version="0.1.0", '
'install_requires=[i for i in ["package"]])'
)
)
return
source_dir
@pytest.fixture
def
demo_setup_complex_pep517_legacy
(
demo_setup_complex
:
Path
)
->
Path
:
pyproject_toml
=
demo_setup_complex
/
"pyproject.toml"
pyproject_toml
.
write_text
(
decode
(
'[build-system]
\n
requires = ["setuptools", "wheel"]'
)
)
pyproject_toml
.
write_text
(
'[build-system]
\n
requires = ["setuptools", "wheel"]'
)
return
demo_setup_complex
def
demo_check_info
(
info
:
PackageInfo
,
requires_dist
:
set
[
str
]
=
None
)
->
None
:
def
demo_check_info
(
info
:
PackageInfo
,
requires_dist
:
set
[
str
]
|
None
=
None
)
->
None
:
assert
info
.
name
==
"demo"
assert
info
.
version
==
"0.1.0"
assert
info
.
requires_dist
...
...
@@ -120,22 +111,22 @@ def demo_check_info(info: PackageInfo, requires_dist: set[str] = None) -> None:
)
def
test_info_from_sdist
(
demo_sdist
:
Path
):
def
test_info_from_sdist
(
demo_sdist
:
Path
)
->
None
:
info
=
PackageInfo
.
from_sdist
(
demo_sdist
)
demo_check_info
(
info
)
def
test_info_from_wheel
(
demo_wheel
:
Path
):
def
test_info_from_wheel
(
demo_wheel
:
Path
)
->
None
:
info
=
PackageInfo
.
from_wheel
(
demo_wheel
)
demo_check_info
(
info
)
def
test_info_from_bdist
(
demo_wheel
:
Path
):
def
test_info_from_bdist
(
demo_wheel
:
Path
)
->
None
:
info
=
PackageInfo
.
from_bdist
(
demo_wheel
)
demo_check_info
(
info
)
def
test_info_from_poetry_directory
():
def
test_info_from_poetry_directory
()
->
None
:
info
=
PackageInfo
.
from_directory
(
FIXTURE_DIR_INSPECTIONS
/
"demo"
,
disable_build
=
True
)
...
...
@@ -144,7 +135,7 @@ def test_info_from_poetry_directory():
def
test_info_from_poetry_directory_fallback_on_poetry_create_error
(
mocker
:
MockerFixture
,
):
)
->
None
:
mock_create_poetry
=
mocker
.
patch
(
"poetry.inspection.info.Factory.create_poetry"
,
side_effect
=
RuntimeError
)
...
...
@@ -160,24 +151,25 @@ def test_info_from_poetry_directory_fallback_on_poetry_create_error(
assert
mock_get_pep517_metadata
.
call_count
==
1
def
test_info_from_requires_txt
():
def
test_info_from_requires_txt
()
->
None
:
info
=
PackageInfo
.
from_metadata
(
FIXTURE_DIR_INSPECTIONS
/
"demo_only_requires_txt.egg-info"
)
assert
info
is
not
None
demo_check_info
(
info
)
def
test_info_from_setup_py
(
demo_setup
:
Path
):
def
test_info_from_setup_py
(
demo_setup
:
Path
)
->
None
:
info
=
PackageInfo
.
from_setup_files
(
demo_setup
)
demo_check_info
(
info
,
requires_dist
=
{
"package"
})
def
test_info_from_setup_cfg
(
demo_setup_cfg
:
Path
):
def
test_info_from_setup_cfg
(
demo_setup_cfg
:
Path
)
->
None
:
info
=
PackageInfo
.
from_setup_files
(
demo_setup_cfg
)
demo_check_info
(
info
,
requires_dist
=
{
"package"
})
def
test_info_no_setup_pkg_info_no_deps
():
def
test_info_no_setup_pkg_info_no_deps
()
->
None
:
info
=
PackageInfo
.
from_directory
(
FIXTURE_DIR_INSPECTIONS
/
"demo_no_setup_pkg_info_no_deps"
,
disable_build
=
True
,
...
...
@@ -187,28 +179,28 @@ def test_info_no_setup_pkg_info_no_deps():
assert
info
.
requires_dist
is
None
def
test_info_setup_simple
(
mocker
:
MockerFixture
,
demo_setup
:
Path
):
def
test_info_setup_simple
(
mocker
:
MockerFixture
,
demo_setup
:
Path
)
->
None
:
spy
=
mocker
.
spy
(
VirtualEnv
,
"run"
)
info
=
PackageInfo
.
from_directory
(
demo_setup
)
assert
spy
.
call_count
==
0
demo_check_info
(
info
,
requires_dist
=
{
"package"
})
def
test_info_setup_cfg
(
mocker
:
MockerFixture
,
demo_setup_cfg
:
Path
):
def
test_info_setup_cfg
(
mocker
:
MockerFixture
,
demo_setup_cfg
:
Path
)
->
None
:
spy
=
mocker
.
spy
(
VirtualEnv
,
"run"
)
info
=
PackageInfo
.
from_directory
(
demo_setup_cfg
)
assert
spy
.
call_count
==
0
demo_check_info
(
info
,
requires_dist
=
{
"package"
})
def
test_info_setup_complex
(
demo_setup_complex
:
Path
):
def
test_info_setup_complex
(
demo_setup_complex
:
Path
)
->
None
:
info
=
PackageInfo
.
from_directory
(
demo_setup_complex
)
demo_check_info
(
info
,
requires_dist
=
{
"package"
})
def
test_info_setup_complex_pep517_error
(
mocker
:
MockerFixture
,
demo_setup_complex
:
Path
):
)
->
None
:
mocker
.
patch
(
"poetry.utils.env.VirtualEnv.run"
,
autospec
=
True
,
...
...
@@ -219,14 +211,16 @@ def test_info_setup_complex_pep517_error(
PackageInfo
.
from_directory
(
demo_setup_complex
)
def
test_info_setup_complex_pep517_legacy
(
demo_setup_complex_pep517_legacy
:
Path
):
def
test_info_setup_complex_pep517_legacy
(
demo_setup_complex_pep517_legacy
:
Path
,
)
->
None
:
info
=
PackageInfo
.
from_directory
(
demo_setup_complex_pep517_legacy
)
demo_check_info
(
info
,
requires_dist
=
{
"package"
})
def
test_info_setup_complex_disable_build
(
mocker
:
MockerFixture
,
demo_setup_complex
:
Path
):
)
->
None
:
spy
=
mocker
.
spy
(
VirtualEnv
,
"run"
)
info
=
PackageInfo
.
from_directory
(
demo_setup_complex
,
disable_build
=
True
)
assert
spy
.
call_count
==
0
...
...
@@ -238,7 +232,7 @@ def test_info_setup_complex_disable_build(
@pytest.mark.parametrize
(
"missing"
,
[
"version"
,
"name"
,
"install_requires"
])
def
test_info_setup_missing_mandatory_should_trigger_pep517
(
mocker
:
MockerFixture
,
source_dir
:
Path
,
missing
:
str
):
)
->
None
:
setup
=
"from setuptools import setup; "
setup
+=
"setup("
setup
+=
'name="demo", '
if
missing
!=
"name"
else
""
...
...
@@ -247,14 +241,14 @@ def test_info_setup_missing_mandatory_should_trigger_pep517(
setup
+=
")"
setup_py
=
source_dir
/
"setup.py"
setup_py
.
write_text
(
decode
(
setup
)
)
setup_py
.
write_text
(
setup
)
spy
=
mocker
.
spy
(
VirtualEnv
,
"run"
)
_
=
PackageInfo
.
from_directory
(
source_dir
)
assert
spy
.
call_count
==
1
def
test_info_prefer_poetry_config_over_egg_info
():
def
test_info_prefer_poetry_config_over_egg_info
()
->
None
:
info
=
PackageInfo
.
from_directory
(
FIXTURE_DIR_INSPECTIONS
/
"demo_with_obsolete_egg_info"
)
...
...
tests/installation/test_chooser.py
View file @
5a9da19f
...
...
@@ -58,7 +58,7 @@ def mock_pypi(http: type[httpretty.httpretty]) -> None:
fixture
=
JSON_FIXTURES
/
(
name
+
".json"
)
if
not
fixture
.
exists
():
return
return
None
with
fixture
.
open
(
encoding
=
"utf-8"
)
as
f
:
return
[
200
,
headers
,
f
.
read
()]
...
...
@@ -132,7 +132,7 @@ def test_chooser_chooses_universal_wheel_link_if_available(
mock_legacy
:
None
,
source_type
:
str
,
pool
:
RepositoryPool
,
):
)
->
None
:
chooser
=
Chooser
(
pool
,
env
)
package
=
Package
(
"pytest"
,
"3.5.0"
)
...
...
@@ -170,7 +170,7 @@ def test_chooser_no_binary_policy(
policy
:
str
,
filename
:
str
,
config
:
Config
,
):
)
->
None
:
config
.
merge
({
"installer"
:
{
"no-binary"
:
policy
.
split
(
","
)}})
chooser
=
Chooser
(
pool
,
env
,
config
)
...
...
@@ -197,7 +197,7 @@ def test_chooser_chooses_specific_python_universal_wheel_link_if_available(
mock_legacy
:
None
,
source_type
:
str
,
pool
:
RepositoryPool
,
):
)
->
None
:
chooser
=
Chooser
(
pool
,
env
)
package
=
Package
(
"isort"
,
"4.3.4"
)
...
...
@@ -218,7 +218,7 @@ def test_chooser_chooses_specific_python_universal_wheel_link_if_available(
@pytest.mark.parametrize
(
"source_type"
,
[
""
,
"legacy"
])
def
test_chooser_chooses_system_specific_wheel_link_if_available
(
mock_pypi
:
None
,
mock_legacy
:
None
,
source_type
:
str
,
pool
:
RepositoryPool
):
)
->
None
:
env
=
MockEnv
(
supported_tags
=
[
Tag
(
"cp37"
,
"cp37m"
,
"win32"
),
Tag
(
"py3"
,
"none"
,
"any"
)]
)
...
...
@@ -246,7 +246,7 @@ def test_chooser_chooses_sdist_if_no_compatible_wheel_link_is_available(
mock_legacy
:
None
,
source_type
:
str
,
pool
:
RepositoryPool
,
):
)
->
None
:
chooser
=
Chooser
(
pool
,
env
)
package
=
Package
(
"pyyaml"
,
"3.13.0"
)
...
...
@@ -271,7 +271,7 @@ def test_chooser_chooses_distributions_that_match_the_package_hashes(
mock_legacy
:
None
,
source_type
:
str
,
pool
:
RepositoryPool
,
):
)
->
None
:
chooser
=
Chooser
(
pool
,
env
)
package
=
Package
(
"isort"
,
"4.3.4"
)
...
...
@@ -381,7 +381,7 @@ def test_chooser_throws_an_error_if_package_hashes_do_not_match(
mock_legacy
:
None
,
source_type
:
None
,
pool
:
RepositoryPool
,
):
)
->
None
:
chooser
=
Chooser
(
pool
,
env
)
package
=
Package
(
"isort"
,
"4.3.4"
)
...
...
tests/mixology/helpers.py
View file @
5a9da19f
...
...
@@ -10,11 +10,13 @@ from poetry.mixology.version_solver import VersionSolver
if
TYPE_CHECKING
:
from
collections.abc
import
Mapping
from
packaging.utils
import
NormalizedName
from
poetry.core.factory
import
DependencyConstraint
from
poetry.core.packages.project_package
import
ProjectPackage
from
poetry.mixology
import
SolverResult
from
poetry.mixology
.result
import
SolverResult
from
poetry.repositories
import
Repository
from
tests.mixology.version_solver.conftest
import
Provider
...
...
@@ -23,7 +25,7 @@ def add_to_repo(
repository
:
Repository
,
name
:
str
,
version
:
str
,
deps
:
dict
[
str
,
DependencyConstraint
]
|
None
=
None
,
deps
:
Mapping
[
str
,
DependencyConstraint
]
|
None
=
None
,
python
:
str
|
None
=
None
,
yanked
:
bool
=
False
,
)
->
None
:
...
...
@@ -62,7 +64,7 @@ def check_solver_result(
except
AssertionError
as
e
:
if
error
:
assert
str
(
e
)
==
error
return
return
None
raise
packages
=
{}
...
...
tests/mixology/version_solver/test_backtracking.py
View file @
5a9da19f
...
...
@@ -16,7 +16,7 @@ if TYPE_CHECKING:
def
test_circular_dependency_on_older_version
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"a"
,
">=1.0.0"
))
add_to_repo
(
repo
,
"a"
,
"1.0.0"
)
...
...
@@ -28,7 +28,7 @@ def test_circular_dependency_on_older_version(
def
test_diamond_dependency_graph
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"a"
,
"*"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"b"
,
"*"
))
...
...
@@ -47,7 +47,7 @@ def test_diamond_dependency_graph(
def
test_backjumps_after_partial_satisfier
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
# c 2.0.0 is incompatible with y 2.0.0 because it requires x 1.0.0, but that
# requirement only exists because of both a and b. The solver should be able
# to deduce c 2.0.0's incompatibility and select c 1.0.0 instead.
...
...
@@ -72,7 +72,7 @@ def test_backjumps_after_partial_satisfier(
def
test_rolls_back_leaf_versions_first
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
# The latest versions of a and b disagree on c. An older version of either
# will resolve the problem. This test validates that b, which is farther
# in the dependency graph from myapp is downgraded first.
...
...
@@ -88,7 +88,9 @@ def test_rolls_back_leaf_versions_first(
check_solver_result
(
root
,
provider
,
{
"a"
:
"2.0.0"
,
"b"
:
"1.0.0"
,
"c"
:
"2.0.0"
})
def
test_simple_transitive
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
def
test_simple_transitive
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
)
->
None
:
# Only one version of baz, so foo and bar will have to downgrade
# until they reach it
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"*"
))
...
...
@@ -110,7 +112,7 @@ def test_simple_transitive(root: ProjectPackage, provider: Provider, repo: Repos
def
test_backjump_to_nearer_unsatisfied_package
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
# This ensures it doesn't exhaustively search all versions of b when it's
# a-2.0.0 whose dependency on c-2.0.0-nonexistent led to the problem. We
# make sure b has more versions than a so that the solver tries a first
...
...
@@ -132,7 +134,7 @@ def test_backjump_to_nearer_unsatisfied_package(
def
test_traverse_into_package_with_fewer_versions_first
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
# Dependencies are ordered so that packages with fewer versions are tried
# first. Here, there are two valid solutions (either a or b must be
# downgraded once). The chosen one depends on which dep is traversed first.
...
...
@@ -158,7 +160,7 @@ def test_traverse_into_package_with_fewer_versions_first(
def
test_backjump_past_failed_package_on_disjoint_constraint
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"a"
,
"*"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
">2.0.0"
))
...
...
tests/mixology/version_solver/test_basic_graph.py
View file @
5a9da19f
...
...
@@ -18,7 +18,7 @@ if TYPE_CHECKING:
def
test_simple_dependencies
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"a"
,
"1.0.0"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"b"
,
"1.0.0"
))
...
...
@@ -45,7 +45,7 @@ def test_simple_dependencies(
def
test_shared_dependencies_with_overlapping_constraints
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"a"
,
"1.0.0"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"b"
,
"1.0.0"
))
...
...
@@ -62,7 +62,7 @@ def test_shared_dependencies_with_overlapping_constraints(
def
test_shared_dependency_where_dependent_version_affects_other_dependencies
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"<=1.0.2"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"bar"
,
"1.0.0"
))
...
...
@@ -82,7 +82,7 @@ def test_shared_dependency_where_dependent_version_affects_other_dependencies(
def
test_circular_dependency
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"1.0.0"
))
add_to_repo
(
repo
,
"foo"
,
"1.0.0"
,
deps
=
{
"bar"
:
"1.0.0"
})
...
...
tests/mixology/version_solver/test_dependency_cache.py
View file @
5a9da19f
...
...
@@ -18,7 +18,7 @@ if TYPE_CHECKING:
def
test_solver_dependency_cache_respects_source_type
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
dependency_pypi
=
Factory
.
create_dependency
(
"demo"
,
">=0.1.0"
)
dependency_git
=
Factory
.
create_dependency
(
"demo"
,
{
"git"
:
"https://github.com/demo/demo.git"
},
groups
=
[
"dev"
]
...
...
@@ -62,7 +62,7 @@ def test_solver_dependency_cache_respects_source_type(
def
test_solver_dependency_cache_respects_subdirectories
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
dependency_one
=
Factory
.
create_dependency
(
"one"
,
{
...
...
tests/mixology/version_solver/test_python_constraint.py
View file @
5a9da19f
...
...
@@ -16,7 +16,7 @@ if TYPE_CHECKING:
def
test_dependency_does_not_match_root_python_constraint
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
provider
.
set_package_python_versions
(
"^3.6"
)
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"*"
))
...
...
tests/mixology/version_solver/test_unsolvable.py
View file @
5a9da19f
...
...
@@ -17,7 +17,7 @@ if TYPE_CHECKING:
def
test_no_version_matching_constraint
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"^1.0"
))
add_to_repo
(
repo
,
"foo"
,
"2.0.0"
)
...
...
@@ -35,7 +35,7 @@ def test_no_version_matching_constraint(
def
test_no_version_that_matches_combined_constraints
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"1.0.0"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"bar"
,
"1.0.0"
))
...
...
@@ -58,7 +58,7 @@ So, because myapp depends on both foo (1.0.0) and bar (1.0.0), version solving f
def
test_disjoint_constraints
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"1.0.0"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"bar"
,
"1.0.0"
))
...
...
@@ -80,7 +80,7 @@ So, because myapp depends on both foo (1.0.0) and bar (1.0.0), version solving f
def
test_disjoint_root_constraints
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"1.0.0"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"2.0.0"
))
...
...
@@ -95,7 +95,7 @@ Because myapp depends on both foo (1.0.0) and foo (2.0.0), version solving faile
def
test_disjoint_root_constraints_path_dependencies
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
provider
.
set_package_python_versions
(
"^3.7"
)
fixtures
=
Path
(
__file__
)
.
parent
.
parent
.
parent
/
"fixtures"
project_dir
=
fixtures
.
joinpath
(
"with_conditional_path_deps"
)
...
...
@@ -112,7 +112,9 @@ def test_disjoint_root_constraints_path_dependencies(
check_solver_result
(
root
,
provider
,
error
=
error
)
def
test_no_valid_solution
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
def
test_no_valid_solution
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"a"
,
"*"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"b"
,
"*"
))
...
...
@@ -135,7 +137,7 @@ So, because myapp depends on b (*), version solving failed."""
def
test_package_with_the_same_name_gives_clear_error_message
(
root
:
ProjectPackage
,
provider
:
Provider
,
repo
:
Repository
):
)
->
None
:
pkg_name
=
"a"
root
.
add_dependency
(
Factory
.
create_dependency
(
pkg_name
,
"*"
))
add_to_repo
(
repo
,
pkg_name
,
"1.0.0"
,
deps
=
{
pkg_name
:
"1.0.0"
})
...
...
tests/mixology/version_solver/test_with_lock.py
View file @
5a9da19f
...
...
@@ -22,7 +22,7 @@ if TYPE_CHECKING:
def
test_with_compatible_locked_dependencies
(
root
:
ProjectPackage
,
repo
:
Repository
,
pool
:
RepositoryPool
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"*"
))
add_to_repo
(
repo
,
"foo"
,
"1.0.0"
,
deps
=
{
"bar"
:
"1.0.0"
})
...
...
@@ -44,7 +44,7 @@ def test_with_compatible_locked_dependencies(
def
test_with_incompatible_locked_dependencies
(
root
:
ProjectPackage
,
repo
:
Repository
,
pool
:
RepositoryPool
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
">1.0.1"
))
add_to_repo
(
repo
,
"foo"
,
"1.0.0"
,
deps
=
{
"bar"
:
"1.0.0"
})
...
...
@@ -66,7 +66,7 @@ def test_with_incompatible_locked_dependencies(
def
test_with_unrelated_locked_dependencies
(
root
:
ProjectPackage
,
repo
:
Repository
,
pool
:
RepositoryPool
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"*"
))
add_to_repo
(
repo
,
"foo"
,
"1.0.0"
,
deps
=
{
"bar"
:
"1.0.0"
})
...
...
@@ -89,7 +89,7 @@ def test_with_unrelated_locked_dependencies(
def
test_unlocks_dependencies_if_necessary_to_ensure_that_a_new_dependency_is_satisfied
(
root
:
ProjectPackage
,
repo
:
Repository
,
pool
:
RepositoryPool
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"*"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"newdep"
,
"2.0.0"
))
...
...
@@ -126,7 +126,7 @@ def test_unlocks_dependencies_if_necessary_to_ensure_that_a_new_dependency_is_sa
def
test_with_compatible_locked_dependencies_use_latest
(
root
:
ProjectPackage
,
repo
:
Repository
,
pool
:
RepositoryPool
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"*"
))
root
.
add_dependency
(
Factory
.
create_dependency
(
"baz"
,
"*"
))
...
...
@@ -156,7 +156,7 @@ def test_with_compatible_locked_dependencies_use_latest(
def
test_with_compatible_locked_dependencies_with_extras
(
root
:
ProjectPackage
,
repo
:
Repository
,
pool
:
RepositoryPool
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"^1.0"
))
package_foo_0
=
get_package
(
"foo"
,
"1.0.0"
)
...
...
@@ -190,7 +190,7 @@ def test_with_compatible_locked_dependencies_with_extras(
def
test_with_yanked_package_in_lock
(
root
:
ProjectPackage
,
repo
:
Repository
,
pool
:
RepositoryPool
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"*"
))
add_to_repo
(
repo
,
"foo"
,
"1"
)
...
...
@@ -205,6 +205,7 @@ def test_with_yanked_package_in_lock(
provider
,
result
=
{
"foo"
:
"2"
},
)
assert
result
is
not
None
foo
=
result
.
packages
[
0
]
assert
foo
.
yanked
...
...
@@ -219,7 +220,7 @@ def test_with_yanked_package_in_lock(
def
test_no_update_is_respected_for_legacy_repository
(
root
:
ProjectPackage
,
repo
:
Repository
,
pool
:
RepositoryPool
):
)
->
None
:
root
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
"^1.0"
))
foo_100
=
Package
(
...
...
tests/publishing/test_publisher.py
View file @
5a9da19f
...
...
@@ -23,7 +23,7 @@ if TYPE_CHECKING:
def
test_publish_publishes_to_pypi_by_default
(
fixture_dir
:
FixtureDirGetter
,
mocker
:
MockerFixture
,
config
:
Config
):
)
->
None
:
uploader_auth
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.auth"
)
uploader_upload
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.upload"
)
poetry
=
Factory
()
.
create_poetry
(
fixture_dir
(
"sample_project"
))
...
...
@@ -48,7 +48,7 @@ def test_publish_can_publish_to_given_repository(
mocker
:
MockerFixture
,
config
:
Config
,
fixture_name
:
str
,
):
)
->
None
:
uploader_auth
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.auth"
)
uploader_upload
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.upload"
)
...
...
@@ -77,7 +77,7 @@ def test_publish_can_publish_to_given_repository(
def
test_publish_raises_error_for_undefined_repository
(
fixture_dir
:
FixtureDirGetter
,
config
:
Config
):
)
->
None
:
poetry
=
Factory
()
.
create_poetry
(
fixture_dir
(
"sample_project"
))
poetry
.
_config
=
config
poetry
.
config
.
merge
(
...
...
@@ -91,7 +91,7 @@ def test_publish_raises_error_for_undefined_repository(
def
test_publish_uses_token_if_it_exists
(
fixture_dir
:
FixtureDirGetter
,
mocker
:
MockerFixture
,
config
:
Config
):
)
->
None
:
uploader_auth
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.auth"
)
uploader_upload
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.upload"
)
poetry
=
Factory
()
.
create_poetry
(
fixture_dir
(
"sample_project"
))
...
...
@@ -110,7 +110,7 @@ def test_publish_uses_token_if_it_exists(
def
test_publish_uses_cert
(
fixture_dir
:
FixtureDirGetter
,
mocker
:
MockerFixture
,
config
:
Config
):
)
->
None
:
cert
=
"path/to/ca.pem"
uploader_auth
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.auth"
)
uploader_upload
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.upload"
)
...
...
@@ -141,7 +141,7 @@ def test_publish_uses_cert(
def
test_publish_uses_client_cert
(
fixture_dir
:
FixtureDirGetter
,
mocker
:
MockerFixture
,
config
:
Config
):
)
->
None
:
client_cert
=
"path/to/client.pem"
uploader_upload
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader.upload"
)
poetry
=
Factory
()
.
create_poetry
(
fixture_dir
(
"sample_project"
))
...
...
@@ -172,7 +172,7 @@ def test_publish_read_from_environment_variable(
environ
:
None
,
mocker
:
MockerFixture
,
config
:
Config
,
):
)
->
None
:
os
.
environ
[
"POETRY_REPOSITORIES_FOO_URL"
]
=
"https://foo.bar"
os
.
environ
[
"POETRY_HTTP_BASIC_FOO_USERNAME"
]
=
"bar"
os
.
environ
[
"POETRY_HTTP_BASIC_FOO_PASSWORD"
]
=
"baz"
...
...
tests/publishing/test_uploader.py
View file @
5a9da19f
...
...
@@ -26,7 +26,7 @@ def uploader(fixture_dir: FixtureDirGetter) -> Uploader:
def
test_uploader_properly_handles_400_errors
(
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
):
)
->
None
:
http
.
register_uri
(
http
.
POST
,
"https://foo.com"
,
status
=
400
,
body
=
"Bad request"
)
with
pytest
.
raises
(
UploadError
)
as
e
:
...
...
@@ -37,7 +37,7 @@ def test_uploader_properly_handles_400_errors(
def
test_uploader_properly_handles_403_errors
(
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
):
)
->
None
:
http
.
register_uri
(
http
.
POST
,
"https://foo.com"
,
status
=
403
,
body
=
"Unauthorized"
)
with
pytest
.
raises
(
UploadError
)
as
e
:
...
...
@@ -48,7 +48,7 @@ def test_uploader_properly_handles_403_errors(
def
test_uploader_properly_handles_nonstandard_errors
(
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
):
)
->
None
:
# content based off a true story.
# Message changed to protect the ~~innocent~~ guilty.
content
=
(
...
...
@@ -62,7 +62,7 @@ def test_uploader_properly_handles_nonstandard_errors(
with
pytest
.
raises
(
UploadError
)
as
e
:
uploader
.
upload
(
"https://foo.com"
)
assert
str
(
e
.
value
)
==
f
"HTTP Error 400: Bad Request | {content}"
assert
str
(
e
.
value
)
==
f
"HTTP Error 400: Bad Request | {content
!r
}"
@pytest.mark.parametrize
(
...
...
@@ -79,7 +79,7 @@ def test_uploader_properly_handles_nonstandard_errors(
)
def
test_uploader_properly_handles_redirects
(
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
,
status
:
int
,
body
:
str
):
)
->
None
:
http
.
register_uri
(
http
.
POST
,
"https://foo.com"
,
status
=
status
,
body
=
body
)
with
pytest
.
raises
(
UploadError
)
as
e
:
...
...
@@ -93,7 +93,7 @@ def test_uploader_properly_handles_redirects(
def
test_uploader_properly_handles_301_redirects
(
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
):
)
->
None
:
http
.
register_uri
(
http
.
POST
,
"https://foo.com"
,
status
=
301
,
body
=
"Redirect"
)
with
pytest
.
raises
(
UploadError
)
as
e
:
...
...
@@ -107,7 +107,7 @@ def test_uploader_properly_handles_301_redirects(
def
test_uploader_registers_for_appropriate_400_errors
(
mocker
:
MockerFixture
,
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
):
)
->
None
:
register
=
mocker
.
patch
(
"poetry.publishing.uploader.Uploader._register"
)
http
.
register_uri
(
http
.
POST
,
"https://foo.com"
,
status
=
400
,
body
=
"No package was ever registered"
...
...
@@ -131,7 +131,7 @@ def test_uploader_registers_for_appropriate_400_errors(
)
def
test_uploader_skips_existing
(
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
,
status
:
int
,
body
:
str
):
)
->
None
:
http
.
register_uri
(
http
.
POST
,
"https://foo.com"
,
status
=
status
,
body
=
body
)
# should not raise
...
...
@@ -140,7 +140,7 @@ def test_uploader_skips_existing(
def
test_uploader_skip_existing_bubbles_unskippable_errors
(
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
):
)
->
None
:
http
.
register_uri
(
http
.
POST
,
"https://foo.com"
,
status
=
403
,
body
=
"Unauthorized"
)
with
pytest
.
raises
(
UploadError
):
...
...
@@ -149,7 +149,7 @@ def test_uploader_skip_existing_bubbles_unskippable_errors(
def
test_uploader_properly_handles_file_not_existing
(
mocker
:
MockerFixture
,
http
:
type
[
httpretty
.
httpretty
],
uploader
:
Uploader
):
)
->
None
:
mocker
.
patch
(
"pathlib.Path.is_file"
,
return_value
=
False
)
with
pytest
.
raises
(
UploadError
)
as
e
:
...
...
tests/puzzle/test_provider.py
View file @
5a9da19f
...
...
@@ -93,17 +93,7 @@ def test_search_for(
repository
.
add_package
(
foo2a
)
repository
.
add_package
(
foo2
)
repository
.
add_package
(
foo3a
)
# TODO: remove workaround when poetry-core with
# https://github.com/python-poetry/poetry-core/pull/543 is available
if
str
(
dependency
.
constraint
)
==
">=1a"
:
result
=
provider
.
search_for
(
dependency
)
assert
result
==
expected
or
result
==
[
Package
(
"foo"
,
"3a"
),
Package
(
"foo"
,
"2"
),
Package
(
"foo"
,
"2a"
),
Package
(
"foo"
,
"1"
),
]
return
assert
provider
.
search_for
(
dependency
)
==
expected
...
...
tests/repositories/test_legacy_repository.py
View file @
5a9da19f
...
...
@@ -3,6 +3,7 @@ from __future__ import annotations
import
base64
import
re
import
shutil
import
urllib.parse
as
urlparse
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
...
...
@@ -21,11 +22,6 @@ from poetry.repositories.legacy_repository import LegacyRepository
from
poetry.repositories.link_sources.html
import
SimpleRepositoryPage
try
:
import
urllib.parse
as
urlparse
except
ImportError
:
import
urlparse
if
TYPE_CHECKING
:
import
httpretty
...
...
tests/repositories/test_pypi_repository.py
View file @
5a9da19f
...
...
@@ -19,7 +19,6 @@ from poetry.factory import Factory
from
poetry.repositories.exceptions
import
PackageNotFound
from
poetry.repositories.link_sources.json
import
SimpleJsonPage
from
poetry.repositories.pypi_repository
import
PyPiRepository
from
poetry.utils._compat
import
encode
if
TYPE_CHECKING
:
...
...
@@ -302,10 +301,8 @@ def test_pypi_repository_supports_reading_bz2_files() -> None:
]
}
for
name
in
expected_extras
.
keys
():
assert
(
sorted
(
package
.
extras
[
name
],
key
=
lambda
r
:
r
.
name
)
==
expected_extras
[
name
]
)
for
name
,
expected_extra
in
expected_extras
.
items
():
assert
sorted
(
package
.
extras
[
name
],
key
=
lambda
r
:
r
.
name
)
==
expected_extra
def
test_invalid_versions_ignored
()
->
None
:
...
...
@@ -325,7 +322,7 @@ def test_get_should_invalid_cache_on_too_many_redirects_error(
response
=
Response
()
response
.
status_code
=
200
response
.
encoding
=
"utf-8"
response
.
raw
=
BytesIO
(
encode
(
'{"foo": "bar"}'
)
)
response
.
raw
=
BytesIO
(
b
'{"foo": "bar"}'
)
mocker
.
patch
(
"poetry.utils.authenticator.Authenticator.get"
,
side_effect
=
[
TooManyRedirects
(),
response
],
...
...
tests/types.py
View file @
5a9da19f
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
from
typing
import
Any
from
tests.compat
import
Protocol
...
...
@@ -46,6 +47,7 @@ class ProjectFactory(Protocol):
poetry_lock_content
:
str
|
None
=
None
,
install_deps
:
bool
=
True
,
source
:
Path
|
None
=
None
,
locker_config
:
dict
[
str
,
Any
]
|
None
=
None
,
use_test_locker
:
bool
=
True
,
)
->
Poetry
:
...
...
...
tests/utils/test_env_site.py
View file @
5a9da19f
...
...
@@ -5,7 +5,6 @@ import uuid
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
poetry.utils._compat
import
decode
from
poetry.utils.env
import
SitePackages
...
...
@@ -23,7 +22,7 @@ def test_env_site_simple(tmp_dir: str, mocker: MockerFixture):
assert
len
(
candidates
)
==
1
assert
candidates
[
0
]
.
as_posix
()
==
hello
.
as_posix
()
content
=
decode
(
str
(
uuid
.
uuid4
()
))
content
=
str
(
uuid
.
uuid4
(
))
site_packages
.
write_text
(
Path
(
"hello.txt"
),
content
,
encoding
=
"utf-8"
)
assert
hello
.
read_text
(
encoding
=
"utf-8"
)
==
content
...
...
@@ -42,7 +41,7 @@ def test_env_site_select_first(tmp_dir: str):
assert
len
(
candidates
)
==
2
assert
len
(
site_packages
.
find
(
Path
(
"hello.txt"
)))
==
0
content
=
decode
(
str
(
uuid
.
uuid4
()
))
content
=
str
(
uuid
.
uuid4
(
))
site_packages
.
write_text
(
Path
(
"hello.txt"
),
content
,
encoding
=
"utf-8"
)
assert
(
site_packages
.
path
/
"hello.txt"
)
.
exists
()
...
...
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