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
73794792
Commit
73794792
authored
Mar 30, 2021
by
Arun Babu Neelicattu
Committed by
Steph Samson
Mar 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: remove duplicated code for plugin commands
parent
71708c6e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
192 deletions
+66
-192
tests/console/commands/plugin/conftest.py
+35
-0
tests/console/commands/plugin/test_add.py
+26
-90
tests/console/commands/plugin/test_remove.py
+5
-71
tests/console/commands/plugin/test_show.py
+0
-31
No files found.
tests/console/commands/plugin/conftest.py
0 → 100644
View file @
73794792
import
pytest
from
poetry.__version__
import
__version__
from
poetry.core.packages.package
import
Package
from
poetry.factory
import
Factory
from
poetry.repositories.installed_repository
import
InstalledRepository
from
poetry.repositories.pool
import
Pool
from
poetry.utils.env
import
EnvManager
@pytest.fixture
()
def
installed
():
repository
=
InstalledRepository
()
repository
.
add_package
(
Package
(
"poetry"
,
__version__
))
return
repository
def
configure_sources_factory
(
repo
):
def
_configure_sources
(
poetry
,
sources
,
config
,
io
):
# noqa
pool
=
Pool
()
pool
.
add_repository
(
repo
)
poetry
.
set_pool
(
pool
)
return
_configure_sources
@pytest.fixture
(
autouse
=
True
)
def
setup_mocks
(
mocker
,
env
,
repo
,
installed
):
mocker
.
patch
.
object
(
EnvManager
,
"get_system_env"
,
return_value
=
env
)
mocker
.
patch
.
object
(
InstalledRepository
,
"load"
,
return_value
=
installed
)
mocker
.
patch
.
object
(
Factory
,
"configure_sources"
,
side_effect
=
configure_sources_factory
(
repo
)
)
tests/console/commands/plugin/test_add.py
View file @
73794792
import
pytest
import
pytest
from
poetry.__version__
import
__version__
from
poetry.core.packages.package
import
Package
from
poetry.core.packages.package
import
Package
from
poetry.factory
import
Factory
from
poetry.factory
import
Factory
from
poetry.repositories.installed_repository
import
InstalledRepository
from
poetry.repositories.pool
import
Pool
from
poetry.utils.env
import
EnvManager
@pytest.fixture
()
@pytest.fixture
()
...
@@ -13,31 +9,17 @@ def tester(command_tester_factory):
...
@@ -13,31 +9,17 @@ def tester(command_tester_factory):
return
command_tester_factory
(
"plugin add"
)
return
command_tester_factory
(
"plugin add"
)
@pytest.fixture
()
def
assert_plugin_add_result
(
tester
,
app
,
env
,
expected
,
constraint
):
def
installed
():
assert
tester
.
io
.
fetch_output
()
==
expected
repository
=
InstalledRepository
()
repository
.
add_package
(
Package
(
"poetry"
,
__version__
))
return
repository
def
configure_sources_factory
(
repo
):
def
_configure_sources
(
poetry
,
sources
,
config
,
io
):
pool
=
Pool
()
pool
.
add_repository
(
repo
)
poetry
.
set_pool
(
pool
)
return
_configure_sources
update_command
=
app
.
find
(
"update"
)
assert
update_command
.
poetry
.
file
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
exists
()
@pytest.fixture
(
autouse
=
True
)
content
=
update_command
.
poetry
.
file
.
read
()[
"tool"
][
"poetry"
]
def
setup_mocks
(
mocker
,
env
,
repo
,
installed
):
assert
"poetry-plugin"
in
content
[
"dependencies"
]
mocker
.
patch
.
object
(
EnvManager
,
"get_system_env"
,
return_value
=
env
)
assert
content
[
"dependencies"
][
"poetry-plugin"
]
==
constraint
mocker
.
patch
.
object
(
InstalledRepository
,
"load"
,
return_value
=
installed
)
mocker
.
patch
.
object
(
Factory
,
"configure_sources"
,
side_effect
=
configure_sources_factory
(
repo
)
)
def
test_add_no_constraint
(
app
,
repo
,
tester
,
env
,
installed
):
def
test_add_no_constraint
(
app
,
repo
,
tester
,
env
,
installed
):
...
@@ -56,17 +38,7 @@ Package operations: 1 install, 0 updates, 0 removals
...
@@ -56,17 +38,7 @@ Package operations: 1 install, 0 updates, 0 removals
• Installing poetry-plugin (0.1.0)
• Installing poetry-plugin (0.1.0)
"""
"""
assert_plugin_add_result
(
tester
,
app
,
env
,
expected
,
"^0.1.0"
)
assert
tester
.
io
.
fetch_output
()
==
expected
update_command
=
app
.
find
(
"update"
)
assert
update_command
.
poetry
.
file
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
exists
()
content
=
update_command
.
poetry
.
file
.
read
()[
"tool"
][
"poetry"
]
assert
"poetry-plugin"
in
content
[
"dependencies"
]
assert
content
[
"dependencies"
][
"poetry-plugin"
]
==
"^0.1.0"
def
test_add_with_constraint
(
app
,
repo
,
tester
,
env
,
installed
):
def
test_add_with_constraint
(
app
,
repo
,
tester
,
env
,
installed
):
...
@@ -86,15 +58,7 @@ Package operations: 1 install, 0 updates, 0 removals
...
@@ -86,15 +58,7 @@ Package operations: 1 install, 0 updates, 0 removals
• Installing poetry-plugin (0.2.0)
• Installing poetry-plugin (0.2.0)
"""
"""
assert
tester
.
io
.
fetch_output
()
==
expected
assert_plugin_add_result
(
tester
,
app
,
env
,
expected
,
"^0.2.0"
)
update_command
=
app
.
find
(
"update"
)
assert
update_command
.
poetry
.
file
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
parent
==
env
.
path
content
=
update_command
.
poetry
.
file
.
read
()[
"tool"
][
"poetry"
]
assert
"poetry-plugin"
in
content
[
"dependencies"
]
assert
content
[
"dependencies"
][
"poetry-plugin"
]
==
"^0.2.0"
def
test_add_with_git_constraint
(
app
,
repo
,
tester
,
env
,
installed
):
def
test_add_with_git_constraint
(
app
,
repo
,
tester
,
env
,
installed
):
...
@@ -114,17 +78,9 @@ Package operations: 2 installs, 0 updates, 0 removals
...
@@ -114,17 +78,9 @@ Package operations: 2 installs, 0 updates, 0 removals
• Installing poetry-plugin (0.1.2 9cf87a2)
• Installing poetry-plugin (0.1.2 9cf87a2)
"""
"""
assert
tester
.
io
.
fetch_output
()
==
expected
assert_plugin_add_result
(
tester
,
app
,
env
,
expected
,
{
"git"
:
"https://github.com/demo/poetry-plugin.git"
}
update_command
=
app
.
find
(
"update"
)
)
assert
update_command
.
poetry
.
file
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
parent
==
env
.
path
content
=
update_command
.
poetry
.
file
.
read
()[
"tool"
][
"poetry"
]
assert
"poetry-plugin"
in
content
[
"dependencies"
]
assert
content
[
"dependencies"
][
"poetry-plugin"
]
==
{
"git"
:
"https://github.com/demo/poetry-plugin.git"
}
def
test_add_with_git_constraint_with_extras
(
app
,
repo
,
tester
,
env
,
installed
):
def
test_add_with_git_constraint_with_extras
(
app
,
repo
,
tester
,
env
,
installed
):
...
@@ -146,18 +102,16 @@ Package operations: 3 installs, 0 updates, 0 removals
...
@@ -146,18 +102,16 @@ Package operations: 3 installs, 0 updates, 0 removals
• Installing poetry-plugin (0.1.2 9cf87a2)
• Installing poetry-plugin (0.1.2 9cf87a2)
"""
"""
assert
tester
.
io
.
fetch_output
()
==
expected
assert_plugin_add_result
(
tester
,
update_command
=
app
.
find
(
"update"
)
app
,
assert
update_command
.
poetry
.
file
.
parent
==
env
.
path
env
,
assert
update_command
.
poetry
.
locker
.
lock
.
parent
==
env
.
path
expected
,
{
content
=
update_command
.
poetry
.
file
.
read
()[
"tool"
][
"poetry"
]
"git"
:
"https://github.com/demo/poetry-plugin.git"
,
assert
"poetry-plugin"
in
content
[
"dependencies"
]
"extras"
:
[
"foo"
],
assert
content
[
"dependencies"
][
"poetry-plugin"
]
==
{
},
"git"
:
"https://github.com/demo/poetry-plugin.git"
,
)
"extras"
:
[
"foo"
],
}
def
test_add_existing_plugin_warns_about_no_operation
(
def
test_add_existing_plugin_warns_about_no_operation
(
...
@@ -242,16 +196,7 @@ Package operations: 0 installs, 1 update, 0 removals
...
@@ -242,16 +196,7 @@ Package operations: 0 installs, 1 update, 0 removals
• Updating poetry-plugin (1.2.3 -> 2.3.4)
• Updating poetry-plugin (1.2.3 -> 2.3.4)
"""
"""
assert
tester
.
io
.
fetch_output
()
==
expected
assert_plugin_add_result
(
tester
,
app
,
env
,
expected
,
"^2.3.4"
)
update_command
=
app
.
find
(
"update"
)
assert
update_command
.
poetry
.
file
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
exists
()
content
=
update_command
.
poetry
.
file
.
read
()[
"tool"
][
"poetry"
]
assert
"poetry-plugin"
in
content
[
"dependencies"
]
assert
content
[
"dependencies"
][
"poetry-plugin"
]
==
"^2.3.4"
def
test_adding_a_plugin_can_update_poetry_dependencies_if_needed
(
def
test_adding_a_plugin_can_update_poetry_dependencies_if_needed
(
...
@@ -285,13 +230,4 @@ Package operations: 1 install, 1 update, 0 removals
...
@@ -285,13 +230,4 @@ Package operations: 1 install, 1 update, 0 removals
• Installing poetry-plugin (1.2.3)
• Installing poetry-plugin (1.2.3)
"""
"""
assert
tester
.
io
.
fetch_output
()
==
expected
assert_plugin_add_result
(
tester
,
app
,
env
,
expected
,
"^1.2.3"
)
update_command
=
app
.
find
(
"update"
)
assert
update_command
.
poetry
.
file
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
parent
==
env
.
path
assert
update_command
.
poetry
.
locker
.
lock
.
exists
()
content
=
update_command
.
poetry
.
file
.
read
()[
"tool"
][
"poetry"
]
assert
"poetry-plugin"
in
content
[
"dependencies"
]
assert
content
[
"dependencies"
][
"poetry-plugin"
]
==
"^1.2.3"
tests/console/commands/plugin/test_remove.py
View file @
73794792
...
@@ -3,11 +3,7 @@ import tomlkit
...
@@ -3,11 +3,7 @@ import tomlkit
from
poetry.__version__
import
__version__
from
poetry.__version__
import
__version__
from
poetry.core.packages.package
import
Package
from
poetry.core.packages.package
import
Package
from
poetry.factory
import
Factory
from
poetry.layouts.layout
import
POETRY_DEFAULT
from
poetry.layouts.layout
import
POETRY_DEFAULT
from
poetry.repositories.installed_repository
import
InstalledRepository
from
poetry.repositories.pool
import
Pool
from
poetry.utils.env
import
EnvManager
@pytest.fixture
()
@pytest.fixture
()
...
@@ -16,33 +12,6 @@ def tester(command_tester_factory):
...
@@ -16,33 +12,6 @@ def tester(command_tester_factory):
@pytest.fixture
()
@pytest.fixture
()
def
installed
():
repository
=
InstalledRepository
()
repository
.
add_package
(
Package
(
"poetry"
,
__version__
))
return
repository
def
configure_sources_factory
(
repo
):
def
_configure_sources
(
poetry
,
sources
,
config
,
io
):
pool
=
Pool
()
pool
.
add_repository
(
repo
)
poetry
.
set_pool
(
pool
)
return
_configure_sources
@pytest.fixture
(
autouse
=
True
)
def
setup_mocks
(
mocker
,
env
,
repo
,
installed
):
mocker
.
patch
.
object
(
EnvManager
,
"get_system_env"
,
return_value
=
env
)
mocker
.
patch
.
object
(
InstalledRepository
,
"load"
,
return_value
=
installed
)
mocker
.
patch
.
object
(
Factory
,
"configure_sources"
,
side_effect
=
configure_sources_factory
(
repo
)
)
@pytest.fixture
()
def
pyproject
(
env
):
def
pyproject
(
env
):
pyproject
=
tomlkit
.
loads
(
POETRY_DEFAULT
)
pyproject
=
tomlkit
.
loads
(
POETRY_DEFAULT
)
content
=
pyproject
[
"tool"
][
"poetry"
]
content
=
pyproject
[
"tool"
][
"poetry"
]
...
@@ -60,7 +29,8 @@ def pyproject(env):
...
@@ -60,7 +29,8 @@ def pyproject(env):
)
)
def
test_remove_installed_package
(
app
,
repo
,
tester
,
env
,
installed
,
pyproject
):
@pytest.fixture
(
autouse
=
True
)
def
install_plugin
(
env
,
installed
,
pyproject
):
lock_content
=
{
lock_content
=
{
"package"
:
[
"package"
:
[
{
{
...
@@ -99,6 +69,8 @@ def test_remove_installed_package(app, repo, tester, env, installed, pyproject):
...
@@ -99,6 +69,8 @@ def test_remove_installed_package(app, repo, tester, env, installed, pyproject):
installed
.
add_package
(
Package
(
"poetry-plugin"
,
"1.2.3"
))
installed
.
add_package
(
Package
(
"poetry-plugin"
,
"1.2.3"
))
def
test_remove_installed_package
(
app
,
tester
,
env
):
tester
.
execute
(
"poetry-plugin"
)
tester
.
execute
(
"poetry-plugin"
)
expected
=
"""
\
expected
=
"""
\
...
@@ -124,45 +96,7 @@ Package operations: 0 installs, 0 updates, 1 removal
...
@@ -124,45 +96,7 @@ Package operations: 0 installs, 0 updates, 1 removal
assert
"poetry-plugin"
not
in
content
[
"dependencies"
]
assert
"poetry-plugin"
not
in
content
[
"dependencies"
]
def
test_remove_installed_package_dry_run
(
app
,
repo
,
tester
,
env
,
installed
,
pyproject
):
def
test_remove_installed_package_dry_run
(
app
,
tester
,
env
):
lock_content
=
{
"package"
:
[
{
"name"
:
"poetry-plugin"
,
"version"
:
"1.2.3"
,
"category"
:
"main"
,
"optional"
:
False
,
"platform"
:
"*"
,
"python-versions"
:
"*"
,
"checksum"
:
[],
},
],
"metadata"
:
{
"python-versions"
:
"^3.6"
,
"platform"
:
"*"
,
"content-hash"
:
"123456789"
,
"hashes"
:
{
"poetry-plugin"
:
[]},
},
}
env
.
path
.
joinpath
(
"poetry.lock"
)
.
write_text
(
tomlkit
.
dumps
(
lock_content
),
encoding
=
"utf-8"
)
pyproject
=
tomlkit
.
loads
(
env
.
path
.
joinpath
(
"pyproject.toml"
)
.
read_text
(
encoding
=
"utf-8"
)
)
content
=
pyproject
[
"tool"
][
"poetry"
]
dependency_section
=
content
[
"dependencies"
]
dependency_section
[
"poetry-plugin"
]
=
"^1.2.3"
env
.
path
.
joinpath
(
"pyproject.toml"
)
.
write_text
(
tomlkit
.
dumps
(
pyproject
),
encoding
=
"utf-8"
)
installed
.
add_package
(
Package
(
"poetry-plugin"
,
"1.2.3"
))
tester
.
execute
(
"poetry-plugin --dry-run"
)
tester
.
execute
(
"poetry-plugin --dry-run"
)
expected
=
"""
\
expected
=
"""
\
...
...
tests/console/commands/plugin/test_show.py
View file @
73794792
...
@@ -2,14 +2,10 @@ import pytest
...
@@ -2,14 +2,10 @@ import pytest
from
entrypoints
import
EntryPoint
as
_EntryPoint
from
entrypoints
import
EntryPoint
as
_EntryPoint
from
poetry.__version__
import
__version__
from
poetry.core.packages.package
import
Package
from
poetry.core.packages.package
import
Package
from
poetry.factory
import
Factory
from
poetry.factory
import
Factory
from
poetry.plugins.application_plugin
import
ApplicationPlugin
from
poetry.plugins.application_plugin
import
ApplicationPlugin
from
poetry.plugins.plugin
import
Plugin
from
poetry.plugins.plugin
import
Plugin
from
poetry.repositories.installed_repository
import
InstalledRepository
from
poetry.repositories.pool
import
Pool
from
poetry.utils.env
import
EnvManager
class
EntryPoint
(
_EntryPoint
):
class
EntryPoint
(
_EntryPoint
):
...
@@ -25,33 +21,6 @@ def tester(command_tester_factory):
...
@@ -25,33 +21,6 @@ def tester(command_tester_factory):
return
command_tester_factory
(
"plugin show"
)
return
command_tester_factory
(
"plugin show"
)
@pytest.fixture
()
def
installed
():
repository
=
InstalledRepository
()
repository
.
add_package
(
Package
(
"poetry"
,
__version__
))
return
repository
def
configure_sources_factory
(
repo
):
def
_configure_sources
(
poetry
,
sources
,
config
,
io
):
pool
=
Pool
()
pool
.
add_repository
(
repo
)
poetry
.
set_pool
(
pool
)
return
_configure_sources
@pytest.fixture
(
autouse
=
True
)
def
setup_mocks
(
mocker
,
env
,
repo
,
installed
):
mocker
.
patch
.
object
(
EnvManager
,
"get_system_env"
,
return_value
=
env
)
mocker
.
patch
.
object
(
InstalledRepository
,
"load"
,
return_value
=
installed
)
mocker
.
patch
.
object
(
Factory
,
"configure_sources"
,
side_effect
=
configure_sources_factory
(
repo
)
)
def
test_show_displays_installed_plugins
(
app
,
tester
,
installed
,
mocker
):
def
test_show_displays_installed_plugins
(
app
,
tester
,
installed
,
mocker
):
mocker
.
patch
(
mocker
.
patch
(
"entrypoints.get_group_all"
,
"entrypoints.get_group_all"
,
...
...
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