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
5fce9d52
Commit
5fce9d52
authored
May 29, 2022
by
Mathieu Kniewallner
Committed by
Bjorn Neergaard
May 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests(console): add tests for `--dry-run` option
parent
3ee8584c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
142 additions
and
13 deletions
+142
-13
tests/console/commands/test_add.py
+48
-13
tests/console/commands/test_remove.py
+37
-0
tests/console/commands/test_update.py
+57
-0
No files found.
tests/console/commands/test_add.py
View file @
5fce9d52
...
@@ -25,6 +25,21 @@ if TYPE_CHECKING:
...
@@ -25,6 +25,21 @@ if TYPE_CHECKING:
from
tests.helpers
import
PoetryTestApplication
from
tests.helpers
import
PoetryTestApplication
from
tests.helpers
import
TestRepository
from
tests.helpers
import
TestRepository
from
tests.types
import
CommandTesterFactory
from
tests.types
import
CommandTesterFactory
from
tests.types
import
FixtureDirGetter
from
tests.types
import
ProjectFactory
@pytest.fixture
def
poetry_with_up_to_date_lockfile
(
project_factory
:
ProjectFactory
,
fixture_dir
:
FixtureDirGetter
)
->
Poetry
:
source
=
fixture_dir
(
"up_to_date_lock"
)
return
project_factory
(
name
=
"foobar"
,
pyproject_content
=
(
source
/
"pyproject.toml"
)
.
read_text
(
encoding
=
"utf-8"
),
poetry_lock_content
=
(
source
/
"poetry.lock"
)
.
read_text
(
encoding
=
"utf-8"
),
)
@pytest.fixture
()
@pytest.fixture
()
...
@@ -1999,34 +2014,54 @@ Writing lock file
...
@@ -1999,34 +2014,54 @@ Writing lock file
def
test_add_keyboard_interrupt_restore_content
(
def
test_add_keyboard_interrupt_restore_content
(
app
:
PoetryTestApplication
,
poetry_with_up_to_date_lockfile
:
Poetry
,
repo
:
TestRepository
,
repo
:
TestRepository
,
installer
:
NoopInstaller
,
command_tester_factory
:
CommandTesterFactory
,
tester
:
CommandTester
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
):
):
tester
=
command_tester_factory
(
"add"
,
poetry
=
poetry_with_up_to_date_lockfile
)
mocker
.
patch
(
mocker
.
patch
(
"poetry.installation.installer.Installer.run"
,
side_effect
=
KeyboardInterrupt
()
"poetry.installation.installer.Installer.run"
,
side_effect
=
KeyboardInterrupt
()
)
)
original_content
=
app
.
poetry
.
file
.
read
()
original_pyproject_content
=
poetry_with_up_to_date_lockfile
.
file
.
read
()
original_lockfile_content
=
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
repo
.
add_package
(
get_package
(
"cachy"
,
"0.2.0"
))
repo
.
add_package
(
get_package
(
"cachy"
,
"0.2.0"
))
repo
.
add_package
(
get_package
(
"docker"
,
"4.3.1"
))
tester
.
execute
(
"cachy
--dry-run
"
)
tester
.
execute
(
"cachy"
)
assert
original_content
==
app
.
poetry
.
file
.
read
()
assert
poetry_with_up_to_date_lockfile
.
file
.
read
()
==
original_pyproject_content
assert
(
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
==
original_lockfile_content
)
def
test_dry_run_restore_original_content
(
@pytest.mark.parametrize
(
app
:
PoetryTestApplication
,
"command"
,
[
"cachy --dry-run"
,
"cachy --lock --dry-run"
,
],
)
def
test_add_with_dry_run_keep_files_intact
(
command
:
str
,
poetry_with_up_to_date_lockfile
:
Poetry
,
repo
:
TestRepository
,
repo
:
TestRepository
,
installer
:
NoopInstaller
,
command_tester_factory
:
CommandTesterFactory
,
tester
:
CommandTester
,
):
):
original_content
=
app
.
poetry
.
file
.
read
()
tester
=
command_tester_factory
(
"add"
,
poetry
=
poetry_with_up_to_date_lockfile
)
original_pyproject_content
=
poetry_with_up_to_date_lockfile
.
file
.
read
()
original_lockfile_content
=
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
repo
.
add_package
(
get_package
(
"cachy"
,
"0.2.0"
))
repo
.
add_package
(
get_package
(
"cachy"
,
"0.2.0"
))
repo
.
add_package
(
get_package
(
"docker"
,
"4.3.1"
))
tester
.
execute
(
"cachy --dry-run"
)
tester
.
execute
(
command
)
assert
original_content
==
app
.
poetry
.
file
.
read
()
assert
poetry_with_up_to_date_lockfile
.
file
.
read
()
==
original_pyproject_content
assert
(
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
==
original_lockfile_content
)
tests/console/commands/test_remove.py
View file @
5fce9d52
...
@@ -8,16 +8,33 @@ import tomlkit
...
@@ -8,16 +8,33 @@ import tomlkit
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
tests.helpers
import
get_package
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
cleo.testers.command_tester
import
CommandTester
from
cleo.testers.command_tester
import
CommandTester
from
pytest_mock
import
MockerFixture
from
pytest_mock
import
MockerFixture
from
poetry.poetry
import
Poetry
from
poetry.repositories
import
Repository
from
poetry.repositories
import
Repository
from
tests.helpers
import
PoetryTestApplication
from
tests.helpers
import
PoetryTestApplication
from
tests.helpers
import
TestRepository
from
tests.helpers
import
TestRepository
from
tests.types
import
CommandTesterFactory
from
tests.types
import
CommandTesterFactory
from
tests.types
import
FixtureDirGetter
from
tests.types
import
ProjectFactory
@pytest.fixture
def
poetry_with_up_to_date_lockfile
(
project_factory
:
ProjectFactory
,
fixture_dir
:
FixtureDirGetter
)
->
Poetry
:
source
=
fixture_dir
(
"up_to_date_lock"
)
return
project_factory
(
name
=
"foobar"
,
pyproject_content
=
(
source
/
"pyproject.toml"
)
.
read_text
(
encoding
=
"utf-8"
),
poetry_lock_content
=
(
source
/
"poetry.lock"
)
.
read_text
(
encoding
=
"utf-8"
),
)
@pytest.fixture
()
@pytest.fixture
()
...
@@ -256,3 +273,23 @@ def test_remove_command_should_not_write_changes_upon_installer_errors(
...
@@ -256,3 +273,23 @@ def test_remove_command_should_not_write_changes_upon_installer_errors(
tester
.
execute
(
"foo"
)
tester
.
execute
(
"foo"
)
assert
app
.
poetry
.
file
.
read
()
.
as_string
()
==
original_content
assert
app
.
poetry
.
file
.
read
()
.
as_string
()
==
original_content
def
test_remove_with_dry_run_keep_files_intact
(
poetry_with_up_to_date_lockfile
:
Poetry
,
repo
:
TestRepository
,
command_tester_factory
:
CommandTesterFactory
,
):
tester
=
command_tester_factory
(
"remove"
,
poetry
=
poetry_with_up_to_date_lockfile
)
original_pyproject_content
=
poetry_with_up_to_date_lockfile
.
file
.
read
()
original_lockfile_content
=
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
repo
.
add_package
(
get_package
(
"docker"
,
"4.3.1"
))
tester
.
execute
(
"docker --dry-run"
)
assert
poetry_with_up_to_date_lockfile
.
file
.
read
()
==
original_pyproject_content
assert
(
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
==
original_lockfile_content
)
tests/console/commands/test_update.py
0 → 100644
View file @
5fce9d52
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
import
pytest
from
tests.helpers
import
get_package
if
TYPE_CHECKING
:
from
poetry.poetry
import
Poetry
from
tests.helpers
import
TestRepository
from
tests.types
import
CommandTesterFactory
from
tests.types
import
FixtureDirGetter
from
tests.types
import
ProjectFactory
@pytest.fixture
def
poetry_with_up_to_date_lockfile
(
project_factory
:
ProjectFactory
,
fixture_dir
:
FixtureDirGetter
)
->
Poetry
:
source
=
fixture_dir
(
"outdated_lock"
)
return
project_factory
(
name
=
"foobar"
,
pyproject_content
=
(
source
/
"pyproject.toml"
)
.
read_text
(
encoding
=
"utf-8"
),
poetry_lock_content
=
(
source
/
"poetry.lock"
)
.
read_text
(
encoding
=
"utf-8"
),
)
@pytest.mark.parametrize
(
"command"
,
[
"--dry-run"
,
"docker --dry-run"
,
],
)
def
test_update_with_dry_run_keep_files_intact
(
command
:
str
,
poetry_with_up_to_date_lockfile
:
Poetry
,
repo
:
TestRepository
,
command_tester_factory
:
CommandTesterFactory
,
):
tester
=
command_tester_factory
(
"update"
,
poetry
=
poetry_with_up_to_date_lockfile
)
original_pyproject_content
=
poetry_with_up_to_date_lockfile
.
file
.
read
()
original_lockfile_content
=
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
repo
.
add_package
(
get_package
(
"docker"
,
"4.3.0"
))
repo
.
add_package
(
get_package
(
"docker"
,
"4.3.1"
))
tester
.
execute
(
command
)
assert
poetry_with_up_to_date_lockfile
.
file
.
read
()
==
original_pyproject_content
assert
(
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
==
original_lockfile_content
)
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