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
3a31f2de
Unverified
Commit
3a31f2de
authored
Apr 15, 2023
by
martin-kokos
Committed by
GitHub
Apr 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: stop using tmp_dir fixture in favor of pytest.tmp_path fixture (#7412)
parent
5a9da19f
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
232 additions
and
239 deletions
+232
-239
.github/workflows/main.yml
+6
-0
src/poetry/utils/pip.py
+1
-1
tests/conftest.py
+14
-26
tests/console/commands/env/conftest.py
+4
-4
tests/console/commands/env/test_list.py
+2
-4
tests/console/commands/self/test_show_plugins.py
+3
-3
tests/console/commands/test_new.py
+10
-8
tests/console/conftest.py
+2
-2
tests/inspection/test_info.py
+3
-1
tests/installation/test_executor.py
+23
-27
tests/integration/test_utils_vcs_git.py
+3
-3
tests/masonry/builders/test_editable_builder.py
+6
-6
tests/plugins/test_plugin_manager.py
+1
-1
tests/repositories/test_installed_repository.py
+2
-2
tests/utils/test_env.py
+142
-142
tests/utils/test_env_site.py
+6
-7
tests/utils/test_pip.py
+4
-2
No files found.
.github/workflows/main.yml
View file @
3a31f2de
...
@@ -64,6 +64,12 @@ jobs:
...
@@ -64,6 +64,12 @@ jobs:
if
:
${{ matrix.os == 'Windows' }}
if
:
${{ matrix.os == 'Windows' }}
run
:
echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH
run
:
echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH
-
name
:
Enable long paths for git on Windows
if
:
${{ matrix.os == 'Windows' }}
# Enable handling long path names (+260 char) on the Windows platform
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
run
:
git config --system core.longpaths
true
-
name
:
Configure poetry
-
name
:
Configure poetry
run
:
poetry config virtualenvs.in-project
true
run
:
poetry config virtualenvs.in-project
true
...
...
src/poetry/utils/pip.py
View file @
3a31f2de
...
@@ -55,4 +55,4 @@ def pip_install(
...
@@ -55,4 +55,4 @@ def pip_install(
try
:
try
:
return
environment
.
run_pip
(
*
args
)
return
environment
.
run_pip
(
*
args
)
except
EnvCommandError
as
e
:
except
EnvCommandError
as
e
:
raise
PoetryException
(
f
"Failed to install {path
.as_posix()
}"
)
from
e
raise
PoetryException
(
f
"Failed to install {path}"
)
from
e
tests/conftest.py
View file @
3a31f2de
...
@@ -5,7 +5,6 @@ import os
...
@@ -5,7 +5,6 @@ import os
import
re
import
re
import
shutil
import
shutil
import
sys
import
sys
import
tempfile
from
contextlib
import
suppress
from
contextlib
import
suppress
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -28,7 +27,6 @@ from poetry.repositories import RepositoryPool
...
@@ -28,7 +27,6 @@ from poetry.repositories import RepositoryPool
from
poetry.utils.env
import
EnvManager
from
poetry.utils.env
import
EnvManager
from
poetry.utils.env
import
SystemEnv
from
poetry.utils.env
import
SystemEnv
from
poetry.utils.env
import
VirtualEnv
from
poetry.utils.env
import
VirtualEnv
from
poetry.utils.helpers
import
remove_directory
from
tests.helpers
import
MOCK_DEFAULT_GIT_REVISION
from
tests.helpers
import
MOCK_DEFAULT_GIT_REVISION
from
tests.helpers
import
TestLocker
from
tests.helpers
import
TestLocker
from
tests.helpers
import
TestRepository
from
tests.helpers
import
TestRepository
...
@@ -169,8 +167,8 @@ def with_chained_null_keyring(mocker: MockerFixture) -> None:
...
@@ -169,8 +167,8 @@ def with_chained_null_keyring(mocker: MockerFixture) -> None:
@pytest.fixture
@pytest.fixture
def
config_cache_dir
(
tmp_
dir
:
str
)
->
Path
:
def
config_cache_dir
(
tmp_
path
:
Path
)
->
Path
:
path
=
Path
(
tmp_dir
)
/
".cache"
/
"pypoetry"
path
=
tmp_path
/
".cache"
/
"pypoetry"
path
.
mkdir
(
parents
=
True
)
path
.
mkdir
(
parents
=
True
)
return
path
return
path
...
@@ -219,8 +217,10 @@ def config(
...
@@ -219,8 +217,10 @@ def config(
@pytest.fixture
()
@pytest.fixture
()
def
config_dir
(
tmp_dir
:
str
)
->
Path
:
def
config_dir
(
tmp_path
:
Path
)
->
Path
:
return
Path
(
tempfile
.
mkdtemp
(
prefix
=
"poetry_config_"
,
dir
=
tmp_dir
))
path
=
tmp_path
/
"config"
path
.
mkdir
()
return
path
@pytest.fixture
(
autouse
=
True
)
@pytest.fixture
(
autouse
=
True
)
...
@@ -296,18 +296,8 @@ def fixture_dir(fixture_base: Path) -> FixtureDirGetter:
...
@@ -296,18 +296,8 @@ def fixture_dir(fixture_base: Path) -> FixtureDirGetter:
@pytest.fixture
@pytest.fixture
def
tmp_dir
()
->
Iterator
[
str
]:
def
tmp_venv
(
tmp_path
:
Path
)
->
Iterator
[
VirtualEnv
]:
dir_
=
tempfile
.
mkdtemp
(
prefix
=
"poetry_"
)
venv_path
=
tmp_path
/
"venv"
path
=
Path
(
dir_
)
yield
path
.
resolve
()
.
as_posix
()
remove_directory
(
path
,
force
=
True
)
@pytest.fixture
def
tmp_venv
(
tmp_dir
:
str
)
->
Iterator
[
VirtualEnv
]:
venv_path
=
Path
(
tmp_dir
)
/
"venv"
EnvManager
.
build_venv
(
venv_path
)
EnvManager
.
build_venv
(
venv_path
)
...
@@ -348,14 +338,14 @@ def repo(http: type[httpretty.httpretty]) -> TestRepository:
...
@@ -348,14 +338,14 @@ def repo(http: type[httpretty.httpretty]) -> TestRepository:
@pytest.fixture
@pytest.fixture
def
project_factory
(
def
project_factory
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
config
:
Config
,
config
:
Config
,
repo
:
TestRepository
,
repo
:
TestRepository
,
installed
:
Repository
,
installed
:
Repository
,
default_python
:
str
,
default_python
:
str
,
load_required_fixtures
:
None
,
load_required_fixtures
:
None
,
)
->
ProjectFactory
:
)
->
ProjectFactory
:
workspace
=
Path
(
tmp_dir
)
workspace
=
tmp_path
def
_factory
(
def
_factory
(
name
:
str
|
None
=
None
,
name
:
str
|
None
=
None
,
...
@@ -380,9 +370,7 @@ def project_factory(
...
@@ -380,9 +370,7 @@ def project_factory(
project_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
project_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
if
pyproject_content
:
if
pyproject_content
:
with
project_dir
.
joinpath
(
"pyproject.toml"
)
.
open
(
with
(
project_dir
/
"pyproject.toml"
)
.
open
(
"w"
,
encoding
=
"utf-8"
)
as
f
:
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
pyproject_content
)
f
.
write
(
pyproject_content
)
else
:
else
:
assert
name
is
not
None
assert
name
is
not
None
...
@@ -446,10 +434,10 @@ def set_simple_log_formatter() -> None:
...
@@ -446,10 +434,10 @@ def set_simple_log_formatter() -> None:
@pytest.fixture
@pytest.fixture
def
fixture_copier
(
fixture_base
:
Path
,
tmp_
dir
:
str
)
->
FixtureCopier
:
def
fixture_copier
(
fixture_base
:
Path
,
tmp_
path
:
Path
)
->
FixtureCopier
:
def
_copy
(
relative_path
:
str
,
target
:
Path
|
None
=
None
)
->
Path
:
def
_copy
(
relative_path
:
str
,
target
:
Path
|
None
=
None
)
->
Path
:
path
=
fixture_base
.
joinpath
(
relative_path
)
path
=
fixture_base
/
relative_path
target
=
target
or
Path
(
tmp_dir
,
relative_path
)
target
=
target
or
(
tmp_path
/
relative_path
)
target
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
target
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
if
target
.
exists
():
if
target
.
exists
():
...
...
tests/console/commands/env/conftest.py
View file @
3a31f2de
...
@@ -2,7 +2,6 @@ from __future__ import annotations
...
@@ -2,7 +2,6 @@ from __future__ import annotations
import
os
import
os
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
TYPE_CHECKING
import
pytest
import
pytest
...
@@ -12,6 +11,7 @@ from poetry.utils.env import EnvManager
...
@@ -12,6 +11,7 @@ from poetry.utils.env import EnvManager
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
collections.abc
import
Iterator
from
collections.abc
import
Iterator
from
pathlib
import
Path
from
tests.helpers
import
PoetryTestApplication
from
tests.helpers
import
PoetryTestApplication
...
@@ -25,8 +25,8 @@ def venv_name(app: PoetryTestApplication) -> str:
...
@@ -25,8 +25,8 @@ def venv_name(app: PoetryTestApplication) -> str:
@pytest.fixture
@pytest.fixture
def
venv_cache
(
tmp_
dir
:
str
)
->
Path
:
def
venv_cache
(
tmp_
path
:
Path
)
->
Path
:
return
Path
(
tmp_dir
)
return
tmp_path
@pytest.fixture
(
scope
=
"module"
)
@pytest.fixture
(
scope
=
"module"
)
...
@@ -49,7 +49,7 @@ def venvs_in_cache_dirs(
...
@@ -49,7 +49,7 @@ def venvs_in_cache_dirs(
)
->
list
[
str
]:
)
->
list
[
str
]:
directories
=
[]
directories
=
[]
for
version
in
python_versions
:
for
version
in
python_versions
:
directory
=
venv_cache
.
joinpath
(
f
"{venv_name}-py{version}"
)
directory
=
venv_cache
/
f
"{venv_name}-py{version}"
directory
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
directory
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
directories
.
append
(
directory
.
name
)
directories
.
append
(
directory
.
name
)
return
directories
return
directories
...
...
tests/console/commands/env/test_list.py
View file @
3a31f2de
...
@@ -39,7 +39,7 @@ def test_none_activated(
...
@@ -39,7 +39,7 @@ def test_none_activated(
):
):
mocker
.
patch
(
"poetry.utils.env.EnvManager.get"
,
return_value
=
env
)
mocker
.
patch
(
"poetry.utils.env.EnvManager.get"
,
return_value
=
env
)
tester
.
execute
()
tester
.
execute
()
expected
=
"
\n
"
.
join
(
venvs_in_cache_dirs
)
.
strip
()
expected
=
"
\n
"
.
join
(
venvs_in_cache_dirs
)
assert
tester
.
io
.
fetch_output
()
.
strip
()
==
expected
assert
tester
.
io
.
fetch_output
()
.
strip
()
==
expected
...
@@ -50,9 +50,7 @@ def test_activated(
...
@@ -50,9 +50,7 @@ def test_activated(
venv_activate_37
:
None
,
venv_activate_37
:
None
,
):
):
tester
.
execute
()
tester
.
execute
()
expected
=
(
expected
=
"
\n
"
.
join
(
venvs_in_cache_dirs
)
.
replace
(
"py3.7"
,
"py3.7 (Activated)"
)
"
\n
"
.
join
(
venvs_in_cache_dirs
)
.
strip
()
.
replace
(
"py3.7"
,
"py3.7 (Activated)"
)
)
assert
tester
.
io
.
fetch_output
()
.
strip
()
==
expected
assert
tester
.
io
.
fetch_output
()
.
strip
()
==
expected
...
...
tests/console/commands/self/test_show_plugins.py
View file @
3a31f2de
from
__future__
import
annotations
from
__future__
import
annotations
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
TYPE_CHECKING
from
typing
import
Any
from
typing
import
Any
from
typing
import
Callable
from
typing
import
Callable
...
@@ -17,6 +16,7 @@ from poetry.utils._compat import metadata
...
@@ -17,6 +16,7 @@ from poetry.utils._compat import metadata
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
os
import
PathLike
from
os
import
PathLike
from
pathlib
import
Path
from
cleo.io.io
import
IO
from
cleo.io.io
import
IO
from
cleo.testers.command_tester
import
CommandTester
from
cleo.testers.command_tester
import
CommandTester
...
@@ -64,7 +64,7 @@ def plugin_package(plugin_package_requires_dist: list[str]) -> Package:
...
@@ -64,7 +64,7 @@ def plugin_package(plugin_package_requires_dist: list[str]) -> Package:
@pytest.fixture
()
@pytest.fixture
()
def
plugin_distro
(
plugin_package
:
Package
,
tmp_
dir
:
str
)
->
metadata
.
Distribution
:
def
plugin_distro
(
plugin_package
:
Package
,
tmp_
path
:
Path
)
->
metadata
.
Distribution
:
class
MockDistribution
(
metadata
.
Distribution
):
class
MockDistribution
(
metadata
.
Distribution
):
def
read_text
(
self
,
filename
:
str
)
->
str
|
None
:
def
read_text
(
self
,
filename
:
str
)
->
str
|
None
:
if
filename
==
"METADATA"
:
if
filename
==
"METADATA"
:
...
@@ -81,7 +81,7 @@ def plugin_distro(plugin_package: Package, tmp_dir: str) -> metadata.Distributio
...
@@ -81,7 +81,7 @@ def plugin_distro(plugin_package: Package, tmp_dir: str) -> metadata.Distributio
return
None
return
None
def
locate_file
(
self
,
path
:
PathLike
[
str
])
->
PathLike
[
str
]:
def
locate_file
(
self
,
path
:
PathLike
[
str
])
->
PathLike
[
str
]:
return
Path
(
tmp_dir
,
path
)
return
tmp_path
/
path
return
MockDistribution
()
return
MockDistribution
()
...
...
tests/console/commands/test_new.py
View file @
3a31f2de
...
@@ -155,18 +155,20 @@ def test_command_new(
...
@@ -155,18 +155,20 @@ def test_command_new(
package_path
:
str
,
package_path
:
str
,
include_from
:
str
|
None
,
include_from
:
str
|
None
,
tester
:
CommandTester
,
tester
:
CommandTester
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
):
):
path
=
Path
(
tmp_dir
)
/
directory
path
=
tmp_path
/
directory
options
.
append
(
path
.
as_posix
(
))
options
.
append
(
str
(
path
))
tester
.
execute
(
" "
.
join
(
options
))
tester
.
execute
(
" "
.
join
(
options
))
verify_project_directory
(
path
,
package_name
,
package_path
,
include_from
)
verify_project_directory
(
path
,
package_name
,
package_path
,
include_from
)
@pytest.mark.parametrize
((
"fmt"
,),
[(
None
,),
(
"md"
,),
(
"rst"
,),
(
"adoc"
,),
(
"creole"
,)])
@pytest.mark.parametrize
((
"fmt"
,),
[(
None
,),
(
"md"
,),
(
"rst"
,),
(
"adoc"
,),
(
"creole"
,)])
def
test_command_new_with_readme
(
fmt
:
str
|
None
,
tester
:
CommandTester
,
tmp_dir
:
str
):
def
test_command_new_with_readme
(
fmt
:
str
|
None
,
tester
:
CommandTester
,
tmp_path
:
Path
):
package
=
"package"
package
=
"package"
path
=
Path
(
tmp_dir
)
/
package
path
=
tmp_path
/
package
options
=
[
path
.
as_posix
()]
options
=
[
path
.
as_posix
()]
if
fmt
:
if
fmt
:
...
@@ -191,7 +193,7 @@ def test_respect_prefer_active_on_new(
...
@@ -191,7 +193,7 @@ def test_respect_prefer_active_on_new(
config
:
Config
,
config
:
Config
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
tester
:
CommandTester
,
tester
:
CommandTester
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
):
):
from
poetry.utils.env
import
GET_PYTHON_VERSION_ONELINER
from
poetry.utils.env
import
GET_PYTHON_VERSION_ONELINER
...
@@ -208,8 +210,8 @@ def test_respect_prefer_active_on_new(
...
@@ -208,8 +210,8 @@ def test_respect_prefer_active_on_new(
config
.
config
[
"virtualenvs"
][
"prefer-active-python"
]
=
prefer_active
config
.
config
[
"virtualenvs"
][
"prefer-active-python"
]
=
prefer_active
package
=
"package"
package
=
"package"
path
=
Path
(
tmp_dir
)
/
package
path
=
tmp_path
/
package
options
=
[
path
.
as_posix
(
)]
options
=
[
str
(
path
)]
tester
.
execute
(
" "
.
join
(
options
))
tester
.
execute
(
" "
.
join
(
options
))
pyproject_file
=
path
/
"pyproject.toml"
pyproject_file
=
path
/
"pyproject.toml"
...
...
tests/console/conftest.py
View file @
3a31f2de
...
@@ -40,8 +40,8 @@ def installer() -> NoopInstaller:
...
@@ -40,8 +40,8 @@ def installer() -> NoopInstaller:
@pytest.fixture
@pytest.fixture
def
env
(
tmp_
dir
:
str
)
->
MockEnv
:
def
env
(
tmp_
path
:
Path
)
->
MockEnv
:
path
=
Path
(
tmp_dir
)
/
".venv"
path
=
tmp_path
/
".venv"
path
.
mkdir
(
parents
=
True
)
path
.
mkdir
(
parents
=
True
)
return
MockEnv
(
path
=
path
,
is_venv
=
True
)
return
MockEnv
(
path
=
path
,
is_venv
=
True
)
...
...
tests/inspection/test_info.py
View file @
3a31f2de
...
@@ -36,7 +36,9 @@ def demo_wheel() -> Path:
...
@@ -36,7 +36,9 @@ def demo_wheel() -> Path:
@pytest.fixture
@pytest.fixture
def
source_dir
(
tmp_path
:
Path
)
->
Path
:
def
source_dir
(
tmp_path
:
Path
)
->
Path
:
return
Path
(
tmp_path
.
as_posix
())
path
=
tmp_path
/
"source"
path
.
mkdir
()
return
path
@pytest.fixture
@pytest.fixture
...
...
tests/installation/test_executor.py
View file @
3a31f2de
...
@@ -91,8 +91,8 @@ class Chef(BaseChef):
...
@@ -91,8 +91,8 @@ class Chef(BaseChef):
@pytest.fixture
@pytest.fixture
def
env
(
tmp_
dir
:
str
)
->
MockEnv
:
def
env
(
tmp_
path
:
Path
)
->
MockEnv
:
path
=
Path
(
tmp_dir
)
/
".venv"
path
=
tmp_path
/
".venv"
path
.
mkdir
(
parents
=
True
)
path
.
mkdir
(
parents
=
True
)
return
MockEnv
(
path
=
path
,
is_venv
=
True
)
return
MockEnv
(
path
=
path
,
is_venv
=
True
)
...
@@ -169,19 +169,16 @@ def mock_file_downloads(
...
@@ -169,19 +169,16 @@ def mock_file_downloads(
@pytest.fixture
@pytest.fixture
def
copy_wheel
(
tmp_
dir
:
Path
,
fixture_dir
:
FixtureDirGetter
)
->
Callable
[[],
Path
]:
def
copy_wheel
(
tmp_
path
:
Path
,
fixture_dir
:
FixtureDirGetter
)
->
Callable
[[],
Path
]:
def
_copy_wheel
()
->
Path
:
def
_copy_wheel
()
->
Path
:
tmp_name
=
tempfile
.
mktemp
()
tmp_name
=
tempfile
.
mktemp
()
Path
(
tmp_dir
)
.
joinpath
(
tmp_name
)
.
mkdir
()
(
tmp_path
/
tmp_name
)
.
mkdir
()
shutil
.
copyfile
(
shutil
.
copyfile
(
(
fixture_dir
(
"distributions"
)
/
"demo-0.1.2-py2.py3-none-any.whl"
,
fixture_dir
(
"distributions"
)
/
"demo-0.1.2-py2.py3-none-any.whl"
tmp_path
/
tmp_name
/
"demo-0.1.2-py2.py3-none-any.whl"
,
)
.
as_posix
(),
(
Path
(
tmp_dir
)
/
tmp_name
/
"demo-0.1.2-py2.py3-none-any.whl"
)
.
as_posix
(),
)
)
return
tmp_path
/
tmp_name
/
"demo-0.1.2-py2.py3-none-any.whl"
return
Path
(
tmp_dir
)
/
tmp_name
/
"demo-0.1.2-py2.py3-none-any.whl"
return
_copy_wheel
return
_copy_wheel
...
@@ -201,7 +198,7 @@ def test_execute_executes_a_batch_of_operations(
...
@@ -201,7 +198,7 @@ def test_execute_executes_a_batch_of_operations(
config
:
Config
,
config
:
Config
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
io
:
BufferedIO
,
io
:
BufferedIO
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
mock_file_downloads
:
None
,
mock_file_downloads
:
None
,
env
:
MockEnv
,
env
:
MockEnv
,
copy_wheel
:
Callable
[[],
Path
],
copy_wheel
:
Callable
[[],
Path
],
...
@@ -209,7 +206,7 @@ def test_execute_executes_a_batch_of_operations(
...
@@ -209,7 +206,7 @@ def test_execute_executes_a_batch_of_operations(
):
):
wheel_install
=
mocker
.
patch
.
object
(
WheelInstaller
,
"install"
)
wheel_install
=
mocker
.
patch
.
object
(
WheelInstaller
,
"install"
)
config
.
merge
({
"cache-dir"
:
tmp_dir
})
config
.
merge
({
"cache-dir"
:
str
(
tmp_path
)
})
artifact_cache
=
ArtifactCache
(
cache_dir
=
config
.
artifacts_cache_directory
)
artifact_cache
=
ArtifactCache
(
cache_dir
=
config
.
artifacts_cache_directory
)
prepare_spy
=
mocker
.
spy
(
Chef
,
"_prepare"
)
prepare_spy
=
mocker
.
spy
(
Chef
,
"_prepare"
)
...
@@ -312,13 +309,13 @@ def test_execute_prints_warning_for_yanked_package(
...
@@ -312,13 +309,13 @@ def test_execute_prints_warning_for_yanked_package(
config
:
Config
,
config
:
Config
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
io
:
BufferedIO
,
io
:
BufferedIO
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
mock_file_downloads
:
None
,
mock_file_downloads
:
None
,
env
:
MockEnv
,
env
:
MockEnv
,
operations
:
list
[
Operation
],
operations
:
list
[
Operation
],
has_warning
:
bool
,
has_warning
:
bool
,
):
):
config
.
merge
({
"cache-dir"
:
tmp_dir
})
config
.
merge
({
"cache-dir"
:
str
(
tmp_path
)
})
executor
=
Executor
(
env
,
pool
,
config
,
io
)
executor
=
Executor
(
env
,
pool
,
config
,
io
)
...
@@ -345,11 +342,11 @@ def test_execute_prints_warning_for_invalid_wheels(
...
@@ -345,11 +342,11 @@ def test_execute_prints_warning_for_invalid_wheels(
config
:
Config
,
config
:
Config
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
io
:
BufferedIO
,
io
:
BufferedIO
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
mock_file_downloads
:
None
,
mock_file_downloads
:
None
,
env
:
MockEnv
,
env
:
MockEnv
,
):
):
config
.
merge
({
"cache-dir"
:
tmp_dir
})
config
.
merge
({
"cache-dir"
:
str
(
tmp_path
)
})
executor
=
Executor
(
env
,
pool
,
config
,
io
)
executor
=
Executor
(
env
,
pool
,
config
,
io
)
...
@@ -460,11 +457,11 @@ def test_execute_works_with_ansi_output(
...
@@ -460,11 +457,11 @@ def test_execute_works_with_ansi_output(
config
:
Config
,
config
:
Config
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
io_decorated
:
BufferedIO
,
io_decorated
:
BufferedIO
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
mock_file_downloads
:
None
,
mock_file_downloads
:
None
,
env
:
MockEnv
,
env
:
MockEnv
,
):
):
config
.
merge
({
"cache-dir"
:
tmp_dir
})
config
.
merge
({
"cache-dir"
:
str
(
tmp_path
)
})
executor
=
Executor
(
env
,
pool
,
config
,
io_decorated
)
executor
=
Executor
(
env
,
pool
,
config
,
io_decorated
)
...
@@ -497,11 +494,11 @@ def test_execute_works_with_no_ansi_output(
...
@@ -497,11 +494,11 @@ def test_execute_works_with_no_ansi_output(
config
:
Config
,
config
:
Config
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
io_not_decorated
:
BufferedIO
,
io_not_decorated
:
BufferedIO
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
mock_file_downloads
:
None
,
mock_file_downloads
:
None
,
env
:
MockEnv
,
env
:
MockEnv
,
):
):
config
.
merge
({
"cache-dir"
:
tmp_dir
})
config
.
merge
({
"cache-dir"
:
str
(
tmp_path
)
})
executor
=
Executor
(
env
,
pool
,
config
,
io_not_decorated
)
executor
=
Executor
(
env
,
pool
,
config
,
io_not_decorated
)
...
@@ -581,7 +578,7 @@ Package operations: 1 install, 0 updates, 0 removals
...
@@ -581,7 +578,7 @@ Package operations: 1 install, 0 updates, 0 removals
def
test_executor_should_delete_incomplete_downloads
(
def
test_executor_should_delete_incomplete_downloads
(
config
:
Config
,
config
:
Config
,
io
:
BufferedIO
,
io
:
BufferedIO
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
mock_file_downloads
:
None
,
mock_file_downloads
:
None
,
...
@@ -589,7 +586,7 @@ def test_executor_should_delete_incomplete_downloads(
...
@@ -589,7 +586,7 @@ def test_executor_should_delete_incomplete_downloads(
fixture_dir
:
FixtureDirGetter
,
fixture_dir
:
FixtureDirGetter
,
):
):
fixture
=
fixture_dir
(
"distributions"
)
/
"demo-0.1.0-py2.py3-none-any.whl"
fixture
=
fixture_dir
(
"distributions"
)
/
"demo-0.1.0-py2.py3-none-any.whl"
destination_fixture
=
Path
(
tmp_dir
)
/
"tomlkit-0.5.3-py2.py3-none-any.whl"
destination_fixture
=
tmp_path
/
"tomlkit-0.5.3-py2.py3-none-any.whl"
shutil
.
copyfile
(
str
(
fixture
),
str
(
destination_fixture
))
shutil
.
copyfile
(
str
(
fixture
),
str
(
destination_fixture
))
mocker
.
patch
(
mocker
.
patch
(
"poetry.installation.executor.Executor._download_archive"
,
"poetry.installation.executor.Executor._download_archive"
,
...
@@ -601,10 +598,10 @@ def test_executor_should_delete_incomplete_downloads(
...
@@ -601,10 +598,10 @@ def test_executor_should_delete_incomplete_downloads(
)
)
mocker
.
patch
(
mocker
.
patch
(
"poetry.installation.executor.ArtifactCache.get_cache_directory_for_link"
,
"poetry.installation.executor.ArtifactCache.get_cache_directory_for_link"
,
return_value
=
Path
(
tmp_dir
)
,
return_value
=
tmp_path
,
)
)
config
.
merge
({
"cache-dir"
:
tmp_dir
})
config
.
merge
({
"cache-dir"
:
str
(
tmp_path
)
})
executor
=
Executor
(
env
,
pool
,
config
,
io
)
executor
=
Executor
(
env
,
pool
,
config
,
io
)
...
@@ -1177,7 +1174,7 @@ def test_executor_fallback_on_poetry_create_error_without_wheel_installer(
...
@@ -1177,7 +1174,7 @@ def test_executor_fallback_on_poetry_create_error_without_wheel_installer(
config
:
Config
,
config
:
Config
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
io
:
BufferedIO
,
io
:
BufferedIO
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
mock_file_downloads
:
None
,
mock_file_downloads
:
None
,
env
:
MockEnv
,
env
:
MockEnv
,
fixture_dir
:
FixtureDirGetter
,
fixture_dir
:
FixtureDirGetter
,
...
@@ -1193,7 +1190,7 @@ def test_executor_fallback_on_poetry_create_error_without_wheel_installer(
...
@@ -1193,7 +1190,7 @@ def test_executor_fallback_on_poetry_create_error_without_wheel_installer(
config
.
merge
(
config
.
merge
(
{
{
"cache-dir"
:
tmp_dir
,
"cache-dir"
:
str
(
tmp_path
)
,
"installer"
:
{
"modern-installation"
:
False
},
"installer"
:
{
"modern-installation"
:
False
},
}
}
)
)
...
@@ -1346,7 +1343,6 @@ def test_build_system_requires_not_available(
...
@@ -1346,7 +1343,6 @@ def test_build_system_requires_not_available(
config
:
Config
,
config
:
Config
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
io
:
BufferedIO
,
io
:
BufferedIO
,
tmp_dir
:
str
,
mock_file_downloads
:
None
,
mock_file_downloads
:
None
,
env
:
MockEnv
,
env
:
MockEnv
,
fixture_dir
:
FixtureDirGetter
,
fixture_dir
:
FixtureDirGetter
,
...
...
tests/integration/test_utils_vcs_git.py
View file @
3a31f2de
...
@@ -23,7 +23,7 @@ from poetry.vcs.git.backend import GitRefSpec
...
@@ -23,7 +23,7 @@ from poetry.vcs.git.backend import GitRefSpec
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
_pytest.tmpdir
import
Temp
dir
Factory
from
_pytest.tmpdir
import
Temp
Path
Factory
from
dulwich.client
import
FetchPackResult
from
dulwich.client
import
FetchPackResult
from
dulwich.client
import
GitClient
from
dulwich.client
import
GitClient
from
pytest_mock
import
MockerFixture
from
pytest_mock
import
MockerFixture
...
@@ -79,9 +79,9 @@ def source_directory_name(source_url: str) -> str:
...
@@ -79,9 +79,9 @@ def source_directory_name(source_url: str) -> str:
@pytest.fixture
(
scope
=
"module"
)
@pytest.fixture
(
scope
=
"module"
)
def
local_repo
(
tmp
dir_factory
:
Tempdir
Factory
,
source_directory_name
:
str
)
->
Repo
:
def
local_repo
(
tmp
_path_factory
:
TempPath
Factory
,
source_directory_name
:
str
)
->
Repo
:
with
Repo
.
init
(
with
Repo
.
init
(
tmp
dir
_factory
.
mktemp
(
"src"
)
/
source_directory_name
,
mkdir
=
True
tmp
_path
_factory
.
mktemp
(
"src"
)
/
source_directory_name
,
mkdir
=
True
)
as
repo
:
)
as
repo
:
yield
repo
yield
repo
...
...
tests/masonry/builders/test_editable_builder.py
View file @
3a31f2de
...
@@ -83,8 +83,8 @@ def env_manager(simple_poetry: Poetry) -> EnvManager:
...
@@ -83,8 +83,8 @@ def env_manager(simple_poetry: Poetry) -> EnvManager:
@pytest.fixture
@pytest.fixture
def
tmp_venv
(
tmp_
dir
:
str
,
env_manager
:
EnvManager
)
->
VirtualEnv
:
def
tmp_venv
(
tmp_
path
:
Path
,
env_manager
:
EnvManager
)
->
VirtualEnv
:
venv_path
=
Path
(
tmp_dir
)
/
"venv"
venv_path
=
tmp_path
/
"venv"
env_manager
.
build_venv
(
venv_path
)
env_manager
.
build_venv
(
venv_path
)
...
@@ -222,10 +222,10 @@ if __name__ == '__main__':
...
@@ -222,10 +222,10 @@ if __name__ == '__main__':
def
test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts
(
def
test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts
(
mocker
:
MockerFixture
,
extended_poetry
:
Poetry
,
tmp_
dir
:
str
mocker
:
MockerFixture
,
extended_poetry
:
Poetry
,
tmp_
path
:
Path
)
->
None
:
)
->
None
:
pip_install
=
mocker
.
patch
(
"poetry.masonry.builders.editable.pip_install"
)
pip_install
=
mocker
.
patch
(
"poetry.masonry.builders.editable.pip_install"
)
env
=
MockEnv
(
path
=
Path
(
tmp_dir
)
/
"foo"
)
env
=
MockEnv
(
path
=
tmp_path
/
"foo"
)
builder
=
EditableBuilder
(
extended_poetry
,
env
,
NullIO
())
builder
=
EditableBuilder
(
extended_poetry
,
env
,
NullIO
())
builder
.
build
()
builder
.
build
()
...
@@ -235,10 +235,10 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
...
@@ -235,10 +235,10 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
assert
[]
==
env
.
executed
assert
[]
==
env
.
executed
def
test_builder_setup_generation_runs_with_pip_editable
(
tmp_
dir
:
str
)
->
None
:
def
test_builder_setup_generation_runs_with_pip_editable
(
tmp_
path
:
Path
)
->
None
:
# create an isolated copy of the project
# create an isolated copy of the project
fixture
=
Path
(
__file__
)
.
parent
.
parent
.
parent
/
"fixtures"
/
"extended_project"
fixture
=
Path
(
__file__
)
.
parent
.
parent
.
parent
/
"fixtures"
/
"extended_project"
extended_project
=
Path
(
tmp_dir
)
/
"extended_project"
extended_project
=
tmp_path
/
"extended_project"
shutil
.
copytree
(
fixture
,
extended_project
)
shutil
.
copytree
(
fixture
,
extended_project
)
assert
extended_project
.
exists
()
assert
extended_project
.
exists
()
...
...
tests/plugins/test_plugin_manager.py
View file @
3a31f2de
...
@@ -47,7 +47,7 @@ class InvalidPlugin:
...
@@ -47,7 +47,7 @@ class InvalidPlugin:
@pytest.fixture
()
@pytest.fixture
()
def
poetry
(
tmp_
dir
:
str
,
config
:
Config
)
->
Poetry
:
def
poetry
(
tmp_
path
:
Path
,
config
:
Config
)
->
Poetry
:
poetry
=
Poetry
(
poetry
=
Poetry
(
CWD
/
"pyproject.toml"
,
CWD
/
"pyproject.toml"
,
{},
{},
...
...
tests/repositories/test_installed_repository.py
View file @
3a31f2de
...
@@ -101,9 +101,9 @@ def test_load_successful(repository: InstalledRepository):
...
@@ -101,9 +101,9 @@ def test_load_successful(repository: InstalledRepository):
def
test_load_successful_with_invalid_distribution
(
def
test_load_successful_with_invalid_distribution
(
caplog
:
LogCaptureFixture
,
mocker
:
MockerFixture
,
env
:
MockEnv
,
tmp_
dir
:
str
caplog
:
LogCaptureFixture
,
mocker
:
MockerFixture
,
env
:
MockEnv
,
tmp_
path
:
Path
)
->
None
:
)
->
None
:
invalid_dist_info
=
Path
(
tmp_dir
)
/
"site-packages"
/
"invalid-0.1.0.dist-info"
invalid_dist_info
=
tmp_path
/
"site-packages"
/
"invalid-0.1.0.dist-info"
invalid_dist_info
.
mkdir
(
parents
=
True
)
invalid_dist_info
.
mkdir
(
parents
=
True
)
mocker
.
patch
(
mocker
.
patch
(
"poetry.utils._compat.metadata.Distribution.discover"
,
"poetry.utils._compat.metadata.Distribution.discover"
,
...
...
tests/utils/test_env.py
View file @
3a31f2de
...
@@ -88,9 +88,9 @@ def manager(poetry: Poetry) -> EnvManager:
...
@@ -88,9 +88,9 @@ def manager(poetry: Poetry) -> EnvManager:
def
test_virtualenvs_with_spaces_in_their_path_work_as_expected
(
def
test_virtualenvs_with_spaces_in_their_path_work_as_expected
(
tmp_
dir
:
str
,
manager
:
EnvManager
tmp_
path
:
Path
,
manager
:
EnvManager
)
->
None
:
)
->
None
:
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
venv_path
=
tmp_path
/
"Virtual Env"
manager
.
build_venv
(
venv_path
)
manager
.
build_venv
(
venv_path
)
...
@@ -100,10 +100,10 @@ def test_virtualenvs_with_spaces_in_their_path_work_as_expected(
...
@@ -100,10 +100,10 @@ def test_virtualenvs_with_spaces_in_their_path_work_as_expected(
@pytest.mark.skipif
(
sys
.
platform
!=
"darwin"
,
reason
=
"requires darwin"
)
@pytest.mark.skipif
(
sys
.
platform
!=
"darwin"
,
reason
=
"requires darwin"
)
def
test_venv_backup_exclusion
(
tmp_
dir
:
str
,
manager
:
EnvManager
)
->
None
:
def
test_venv_backup_exclusion
(
tmp_
path
:
Path
,
manager
:
EnvManager
)
:
import
xattr
import
xattr
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
venv_path
=
tmp_path
/
"Virtual Env"
manager
.
build_venv
(
venv_path
)
manager
.
build_venv
(
venv_path
)
...
@@ -121,9 +121,9 @@ def test_venv_backup_exclusion(tmp_dir: str, manager: EnvManager) -> None:
...
@@ -121,9 +121,9 @@ def test_venv_backup_exclusion(tmp_dir: str, manager: EnvManager) -> None:
def
test_env_commands_with_spaces_in_their_arg_work_as_expected
(
def
test_env_commands_with_spaces_in_their_arg_work_as_expected
(
tmp_
dir
:
str
,
manager
:
EnvManager
tmp_
path
:
Path
,
manager
:
EnvManager
)
->
None
:
)
->
None
:
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
venv_path
=
tmp_path
/
"Virtual Env"
manager
.
build_venv
(
venv_path
)
manager
.
build_venv
(
venv_path
)
venv
=
VirtualEnv
(
venv_path
)
venv
=
VirtualEnv
(
venv_path
)
assert
venv
.
run
(
"python"
,
str
(
venv
.
pip
),
"--version"
)
.
startswith
(
assert
venv
.
run
(
"python"
,
str
(
venv
.
pip
),
"--version"
)
.
startswith
(
...
@@ -132,9 +132,9 @@ def test_env_commands_with_spaces_in_their_arg_work_as_expected(
...
@@ -132,9 +132,9 @@ def test_env_commands_with_spaces_in_their_arg_work_as_expected(
def
test_env_shell_commands_with_stdinput_in_their_arg_work_as_expected
(
def
test_env_shell_commands_with_stdinput_in_their_arg_work_as_expected
(
tmp_
dir
:
str
,
manager
:
EnvManager
tmp_
path
:
Path
,
manager
:
EnvManager
)
->
None
:
)
->
None
:
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
venv_path
=
tmp_path
/
"Virtual Env"
manager
.
build_venv
(
venv_path
)
manager
.
build_venv
(
venv_path
)
venv
=
VirtualEnv
(
venv_path
)
venv
=
VirtualEnv
(
venv_path
)
run_output_path
=
Path
(
venv
.
run
(
"python"
,
"-"
,
input_
=
GET_BASE_PREFIX
)
.
strip
())
run_output_path
=
Path
(
venv
.
run
(
"python"
,
"-"
,
input_
=
GET_BASE_PREFIX
)
.
strip
())
...
@@ -143,9 +143,9 @@ def test_env_shell_commands_with_stdinput_in_their_arg_work_as_expected(
...
@@ -143,9 +143,9 @@ def test_env_shell_commands_with_stdinput_in_their_arg_work_as_expected(
def
test_env_get_supported_tags_matches_inside_virtualenv
(
def
test_env_get_supported_tags_matches_inside_virtualenv
(
tmp_
dir
:
str
,
manager
:
EnvManager
tmp_
path
:
Path
,
manager
:
EnvManager
)
->
None
:
)
->
None
:
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
venv_path
=
tmp_path
/
"Virtual Env"
manager
.
build_venv
(
venv_path
)
manager
.
build_venv
(
venv_path
)
venv
=
VirtualEnv
(
venv_path
)
venv
=
VirtualEnv
(
venv_path
)
...
@@ -209,7 +209,7 @@ def check_output_wrapper(
...
@@ -209,7 +209,7 @@ def check_output_wrapper(
def
test_activate_activates_non_existing_virtualenv_no_envs_file
(
def
test_activate_activates_non_existing_virtualenv_no_envs_file
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -219,7 +219,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
...
@@ -219,7 +219,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
if
"VIRTUAL_ENV"
in
os
.
environ
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
del
os
.
environ
[
"VIRTUAL_ENV"
]
del
os
.
environ
[
"VIRTUAL_ENV"
]
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
mocker
.
patch
(
...
@@ -235,7 +235,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
...
@@ -235,7 +235,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
env
=
manager
.
activate
(
"python3.7"
)
env
=
manager
.
activate
(
"python3.7"
)
m
.
assert_called_with
(
m
.
assert_called_with
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
,
tmp_path
/
f
"{venv_name}-py3.7"
,
executable
=
Path
(
"/usr/bin/python3.7"
),
executable
=
Path
(
"/usr/bin/python3.7"
),
flags
=
{
flags
=
{
"always-copy"
:
False
,
"always-copy"
:
False
,
...
@@ -246,18 +246,18 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
...
@@ -246,18 +246,18 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
prompt
=
"simple-project-py3.7"
,
prompt
=
"simple-project-py3.7"
,
)
)
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
assert
envs_file
.
exists
()
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py3.7"
assert
env
.
base
==
Path
(
"/prefix"
)
assert
env
.
base
==
Path
(
"/prefix"
)
def
test_activate_fails_when_python_cannot_be_found
(
def
test_activate_fails_when_python_cannot_be_found
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -267,9 +267,9 @@ def test_activate_fails_when_python_cannot_be_found(
...
@@ -267,9 +267,9 @@ def test_activate_fails_when_python_cannot_be_found(
if
"VIRTUAL_ENV"
in
os
.
environ
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
del
os
.
environ
[
"VIRTUAL_ENV"
]
del
os
.
environ
[
"VIRTUAL_ENV"
]
os
.
mkdir
(
os
.
path
.
join
(
tmp_dir
,
f
"{venv_name}-py3.7"
)
)
os
.
mkdir
(
tmp_path
/
f
"{venv_name}-py3.7"
)
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
"shutil.which"
,
return_value
=
None
)
mocker
.
patch
(
"shutil.which"
,
return_value
=
None
)
...
@@ -281,7 +281,7 @@ def test_activate_fails_when_python_cannot_be_found(
...
@@ -281,7 +281,7 @@ def test_activate_fails_when_python_cannot_be_found(
def
test_activate_activates_existing_virtualenv_no_envs_file
(
def
test_activate_activates_existing_virtualenv_no_envs_file
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -291,9 +291,9 @@ def test_activate_activates_existing_virtualenv_no_envs_file(
...
@@ -291,9 +291,9 @@ def test_activate_activates_existing_virtualenv_no_envs_file(
if
"VIRTUAL_ENV"
in
os
.
environ
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
del
os
.
environ
[
"VIRTUAL_ENV"
]
del
os
.
environ
[
"VIRTUAL_ENV"
]
os
.
mkdir
(
os
.
path
.
join
(
tmp_dir
,
f
"{venv_name}-py3.7"
)
)
os
.
mkdir
(
tmp_path
/
f
"{venv_name}-py3.7"
)
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
mocker
.
patch
(
...
@@ -310,18 +310,18 @@ def test_activate_activates_existing_virtualenv_no_envs_file(
...
@@ -310,18 +310,18 @@ def test_activate_activates_existing_virtualenv_no_envs_file(
m
.
assert_not_called
()
m
.
assert_not_called
()
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
assert
envs_file
.
exists
()
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py3.7"
assert
env
.
base
==
Path
(
"/prefix"
)
assert
env
.
base
==
Path
(
"/prefix"
)
def
test_activate_activates_same_virtualenv_with_envs_file
(
def
test_activate_activates_same_virtualenv_with_envs_file
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -331,14 +331,14 @@ def test_activate_activates_same_virtualenv_with_envs_file(
...
@@ -331,14 +331,14 @@ def test_activate_activates_same_virtualenv_with_envs_file(
if
"VIRTUAL_ENV"
in
os
.
environ
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
del
os
.
environ
[
"VIRTUAL_ENV"
]
del
os
.
environ
[
"VIRTUAL_ENV"
]
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
doc
=
tomlkit
.
document
()
doc
=
tomlkit
.
document
()
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.1"
}
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.1"
}
envs_file
.
write
(
doc
)
envs_file
.
write
(
doc
)
os
.
mkdir
(
os
.
path
.
join
(
tmp_dir
,
f
"{venv_name}-py3.7"
)
)
os
.
mkdir
(
tmp_path
/
f
"{venv_name}-py3.7"
)
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
mocker
.
patch
(
...
@@ -360,12 +360,12 @@ def test_activate_activates_same_virtualenv_with_envs_file(
...
@@ -360,12 +360,12 @@ def test_activate_activates_same_virtualenv_with_envs_file(
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py3.7"
assert
env
.
base
==
Path
(
"/prefix"
)
assert
env
.
base
==
Path
(
"/prefix"
)
def
test_activate_activates_different_virtualenv_with_envs_file
(
def
test_activate_activates_different_virtualenv_with_envs_file
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -375,14 +375,14 @@ def test_activate_activates_different_virtualenv_with_envs_file(
...
@@ -375,14 +375,14 @@ def test_activate_activates_different_virtualenv_with_envs_file(
if
"VIRTUAL_ENV"
in
os
.
environ
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
del
os
.
environ
[
"VIRTUAL_ENV"
]
del
os
.
environ
[
"VIRTUAL_ENV"
]
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
doc
=
tomlkit
.
document
()
doc
=
tomlkit
.
document
()
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.1"
}
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.1"
}
envs_file
.
write
(
doc
)
envs_file
.
write
(
doc
)
os
.
mkdir
(
os
.
path
.
join
(
tmp_dir
,
f
"{venv_name}-py3.7"
)
)
os
.
mkdir
(
tmp_path
/
f
"{venv_name}-py3.7"
)
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
mocker
.
patch
(
...
@@ -398,7 +398,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
...
@@ -398,7 +398,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
env
=
manager
.
activate
(
"python3.6"
)
env
=
manager
.
activate
(
"python3.6"
)
m
.
assert_called_with
(
m
.
assert_called_with
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
,
tmp_path
/
f
"{venv_name}-py3.6"
,
executable
=
Path
(
"/usr/bin/python3.6"
),
executable
=
Path
(
"/usr/bin/python3.6"
),
flags
=
{
flags
=
{
"always-copy"
:
False
,
"always-copy"
:
False
,
...
@@ -414,12 +414,12 @@ def test_activate_activates_different_virtualenv_with_envs_file(
...
@@ -414,12 +414,12 @@ def test_activate_activates_different_virtualenv_with_envs_file(
assert
envs
[
venv_name
][
"minor"
]
==
"3.6"
assert
envs
[
venv_name
][
"minor"
]
==
"3.6"
assert
envs
[
venv_name
][
"patch"
]
==
"3.6.6"
assert
envs
[
venv_name
][
"patch"
]
==
"3.6.6"
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py3.6"
assert
env
.
base
==
Path
(
"/prefix"
)
assert
env
.
base
==
Path
(
"/prefix"
)
def
test_activate_activates_recreates_for_different_patch
(
def
test_activate_activates_recreates_for_different_patch
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -429,14 +429,14 @@ def test_activate_activates_recreates_for_different_patch(
...
@@ -429,14 +429,14 @@ def test_activate_activates_recreates_for_different_patch(
if
"VIRTUAL_ENV"
in
os
.
environ
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
del
os
.
environ
[
"VIRTUAL_ENV"
]
del
os
.
environ
[
"VIRTUAL_ENV"
]
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
doc
=
tomlkit
.
document
()
doc
=
tomlkit
.
document
()
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.0"
}
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.0"
}
envs_file
.
write
(
doc
)
envs_file
.
write
(
doc
)
os
.
mkdir
(
os
.
path
.
join
(
tmp_dir
,
f
"{venv_name}-py3.7"
)
)
os
.
mkdir
(
tmp_path
/
f
"{venv_name}-py3.7"
)
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
mocker
.
patch
(
...
@@ -463,7 +463,7 @@ def test_activate_activates_recreates_for_different_patch(
...
@@ -463,7 +463,7 @@ def test_activate_activates_recreates_for_different_patch(
env
=
manager
.
activate
(
"python3.7"
)
env
=
manager
.
activate
(
"python3.7"
)
build_venv_m
.
assert_called_with
(
build_venv_m
.
assert_called_with
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
,
tmp_path
/
f
"{venv_name}-py3.7"
,
executable
=
Path
(
"/usr/bin/python3.7"
),
executable
=
Path
(
"/usr/bin/python3.7"
),
flags
=
{
flags
=
{
"always-copy"
:
False
,
"always-copy"
:
False
,
...
@@ -473,20 +473,20 @@ def test_activate_activates_recreates_for_different_patch(
...
@@ -473,20 +473,20 @@ def test_activate_activates_recreates_for_different_patch(
},
},
prompt
=
"simple-project-py3.7"
,
prompt
=
"simple-project-py3.7"
,
)
)
remove_venv_m
.
assert_called_with
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
remove_venv_m
.
assert_called_with
(
tmp_path
/
f
"{venv_name}-py3.7"
)
assert
envs_file
.
exists
()
assert
envs_file
.
exists
()
envs
=
envs_file
.
read
()
envs
=
envs_file
.
read
()
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"minor"
]
==
"3.7"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
assert
envs
[
venv_name
][
"patch"
]
==
"3.7.1"
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py3.7"
assert
env
.
base
==
Path
(
"/prefix"
)
assert
env
.
base
==
Path
(
"/prefix"
)
assert
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
.
exists
()
assert
(
tmp_path
/
f
"{venv_name}-py3.7"
)
.
exists
()
def
test_activate_does_not_recreate_when_switching_minor
(
def
test_activate_does_not_recreate_when_switching_minor
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -496,15 +496,15 @@ def test_activate_does_not_recreate_when_switching_minor(
...
@@ -496,15 +496,15 @@ def test_activate_does_not_recreate_when_switching_minor(
if
"VIRTUAL_ENV"
in
os
.
environ
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
del
os
.
environ
[
"VIRTUAL_ENV"
]
del
os
.
environ
[
"VIRTUAL_ENV"
]
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
doc
=
tomlkit
.
document
()
doc
=
tomlkit
.
document
()
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.0"
}
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.0"
}
envs_file
.
write
(
doc
)
envs_file
.
write
(
doc
)
os
.
mkdir
(
os
.
path
.
join
(
tmp_dir
,
f
"{venv_name}-py3.7"
)
)
os
.
mkdir
(
tmp_path
/
f
"{venv_name}-py3.7"
)
os
.
mkdir
(
os
.
path
.
join
(
tmp_dir
,
f
"{venv_name}-py3.6"
)
)
os
.
mkdir
(
tmp_path
/
f
"{venv_name}-py3.6"
)
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
"shutil.which"
,
side_effect
=
lambda
py
:
f
"/usr/bin/{py}"
)
mocker
.
patch
(
mocker
.
patch
(
...
@@ -532,13 +532,13 @@ def test_activate_does_not_recreate_when_switching_minor(
...
@@ -532,13 +532,13 @@ def test_activate_does_not_recreate_when_switching_minor(
assert
envs
[
venv_name
][
"minor"
]
==
"3.6"
assert
envs
[
venv_name
][
"minor"
]
==
"3.6"
assert
envs
[
venv_name
][
"patch"
]
==
"3.6.6"
assert
envs
[
venv_name
][
"patch"
]
==
"3.6.6"
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py3.6"
assert
env
.
base
==
Path
(
"/prefix"
)
assert
env
.
base
==
Path
(
"/prefix"
)
assert
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
)
.
exists
()
assert
(
tmp_path
/
f
"{venv_name}-py3.6"
)
.
exists
()
def
test_deactivate_non_activated_but_existing
(
def
test_deactivate_non_activated_but_existing
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -549,9 +549,9 @@ def test_deactivate_non_activated_but_existing(
...
@@ -549,9 +549,9 @@ def test_deactivate_non_activated_but_existing(
del
os
.
environ
[
"VIRTUAL_ENV"
]
del
os
.
environ
[
"VIRTUAL_ENV"
]
python
=
"."
.
join
(
str
(
c
)
for
c
in
sys
.
version_info
[:
2
])
python
=
"."
.
join
(
str
(
c
)
for
c
in
sys
.
version_info
[:
2
])
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py{python}"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py{python}"
)
.
mkdir
()
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
mocker
.
patch
(
"subprocess.check_output"
,
"subprocess.check_output"
,
...
@@ -561,11 +561,11 @@ def test_deactivate_non_activated_but_existing(
...
@@ -561,11 +561,11 @@ def test_deactivate_non_activated_but_existing(
manager
.
deactivate
()
manager
.
deactivate
()
env
=
manager
.
get
()
env
=
manager
.
get
()
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py{python}"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py{python}"
def
test_deactivate_activated
(
def
test_deactivate_activated
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -577,12 +577,10 @@ def test_deactivate_activated(
...
@@ -577,12 +577,10 @@ def test_deactivate_activated(
version
=
Version
.
from_parts
(
*
sys
.
version_info
[:
3
])
version
=
Version
.
from_parts
(
*
sys
.
version_info
[:
3
])
other_version
=
Version
.
parse
(
"3.4"
)
if
version
.
major
==
2
else
version
.
next_minor
()
other_version
=
Version
.
parse
(
"3.4"
)
if
version
.
major
==
2
else
version
.
next_minor
()
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py{version.major}.{version.minor}"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py{version.major}.{version.minor}"
)
.
mkdir
()
(
(
tmp_path
/
f
"{venv_name}-py{other_version.major}.{other_version.minor}"
)
.
mkdir
()
Path
(
tmp_dir
)
/
f
"{venv_name}-py{other_version.major}.{other_version.minor}"
)
.
mkdir
()
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
doc
=
tomlkit
.
document
()
doc
=
tomlkit
.
document
()
doc
[
venv_name
]
=
{
doc
[
venv_name
]
=
{
"minor"
:
f
"{other_version.major}.{other_version.minor}"
,
"minor"
:
f
"{other_version.major}.{other_version.minor}"
,
...
@@ -590,7 +588,7 @@ def test_deactivate_activated(
...
@@ -590,7 +588,7 @@ def test_deactivate_activated(
}
}
envs_file
.
write
(
doc
)
envs_file
.
write
(
doc
)
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
mocker
.
patch
(
mocker
.
patch
(
"subprocess.check_output"
,
"subprocess.check_output"
,
...
@@ -600,14 +598,14 @@ def test_deactivate_activated(
...
@@ -600,14 +598,14 @@ def test_deactivate_activated(
manager
.
deactivate
()
manager
.
deactivate
()
env
=
manager
.
get
()
env
=
manager
.
get
()
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py{version.major}.{version.minor}"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py{version.major}.{version.minor}"
envs
=
envs_file
.
read
()
envs
=
envs_file
.
read
()
assert
len
(
envs
)
==
0
assert
len
(
envs
)
==
0
def
test_get_prefers_explicitly_activated_virtualenvs_over_env_var
(
def
test_get_prefers_explicitly_activated_virtualenvs_over_env_var
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -616,10 +614,10 @@ def test_get_prefers_explicitly_activated_virtualenvs_over_env_var(
...
@@ -616,10 +614,10 @@ def test_get_prefers_explicitly_activated_virtualenvs_over_env_var(
)
->
None
:
)
->
None
:
os
.
environ
[
"VIRTUAL_ENV"
]
=
"/environment/prefix"
os
.
environ
[
"VIRTUAL_ENV"
]
=
"/environment/prefix"
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
doc
=
tomlkit
.
document
()
doc
=
tomlkit
.
document
()
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.0"
}
doc
[
venv_name
]
=
{
"minor"
:
"3.7"
,
"patch"
:
"3.7.0"
}
envs_file
.
write
(
doc
)
envs_file
.
write
(
doc
)
...
@@ -635,41 +633,41 @@ def test_get_prefers_explicitly_activated_virtualenvs_over_env_var(
...
@@ -635,41 +633,41 @@ def test_get_prefers_explicitly_activated_virtualenvs_over_env_var(
env
=
manager
.
get
()
env
=
manager
.
get
()
assert
env
.
path
==
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
assert
env
.
path
==
tmp_path
/
f
"{venv_name}-py3.7"
assert
env
.
base
==
Path
(
"/prefix"
)
assert
env
.
base
==
Path
(
"/prefix"
)
def
test_list
(
def
test_list
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
venv_name
:
str
,
venv_name
:
str
,
)
->
None
:
)
->
None
:
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
venvs
=
manager
.
list
()
venvs
=
manager
.
list
()
assert
len
(
venvs
)
==
2
assert
len
(
venvs
)
==
2
assert
venvs
[
0
]
.
path
==
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
)
assert
venvs
[
0
]
.
path
==
tmp_path
/
f
"{venv_name}-py3.6"
assert
venvs
[
1
]
.
path
==
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
assert
venvs
[
1
]
.
path
==
tmp_path
/
f
"{venv_name}-py3.7"
def
test_remove_by_python_version
(
def
test_remove_by_python_version
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
venv_name
:
str
,
venv_name
:
str
,
)
->
None
:
)
->
None
:
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
mocker
.
patch
(
mocker
.
patch
(
"subprocess.check_output"
,
"subprocess.check_output"
,
...
@@ -678,23 +676,23 @@ def test_remove_by_python_version(
...
@@ -678,23 +676,23 @@ def test_remove_by_python_version(
venv
=
manager
.
remove
(
"3.6"
)
venv
=
manager
.
remove
(
"3.6"
)
expected_venv_path
=
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
expected_venv_path
=
tmp_path
/
f
"{venv_name}-py3.6"
assert
venv
.
path
==
expected_venv_path
assert
venv
.
path
==
expected_venv_path
assert
not
expected_venv_path
.
exists
()
assert
not
expected_venv_path
.
exists
()
def
test_remove_by_name
(
def
test_remove_by_name
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
venv_name
:
str
,
venv_name
:
str
,
)
->
None
:
)
->
None
:
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
mocker
.
patch
(
mocker
.
patch
(
"subprocess.check_output"
,
"subprocess.check_output"
,
...
@@ -703,23 +701,23 @@ def test_remove_by_name(
...
@@ -703,23 +701,23 @@ def test_remove_by_name(
venv
=
manager
.
remove
(
f
"{venv_name}-py3.6"
)
venv
=
manager
.
remove
(
f
"{venv_name}-py3.6"
)
expected_venv_path
=
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
expected_venv_path
=
tmp_path
/
f
"{venv_name}-py3.6"
assert
venv
.
path
==
expected_venv_path
assert
venv
.
path
==
expected_venv_path
assert
not
expected_venv_path
.
exists
()
assert
not
expected_venv_path
.
exists
()
def
test_remove_by_string_with_python_and_version
(
def
test_remove_by_string_with_python_and_version
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
venv_name
:
str
,
venv_name
:
str
,
)
->
None
:
)
->
None
:
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
mocker
.
patch
(
mocker
.
patch
(
"subprocess.check_output"
,
"subprocess.check_output"
,
...
@@ -728,30 +726,30 @@ def test_remove_by_string_with_python_and_version(
...
@@ -728,30 +726,30 @@ def test_remove_by_string_with_python_and_version(
venv
=
manager
.
remove
(
"python3.6"
)
venv
=
manager
.
remove
(
"python3.6"
)
expected_venv_path
=
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
expected_venv_path
=
tmp_path
/
f
"{venv_name}-py3.6"
assert
venv
.
path
==
expected_venv_path
assert
venv
.
path
==
expected_venv_path
assert
not
expected_venv_path
.
exists
()
assert
not
expected_venv_path
.
exists
()
def
test_remove_by_full_path_to_python
(
def
test_remove_by_full_path_to_python
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
venv_name
:
str
,
venv_name
:
str
,
)
->
None
:
)
->
None
:
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
mocker
.
patch
(
mocker
.
patch
(
"subprocess.check_output"
,
"subprocess.check_output"
,
side_effect
=
check_output_wrapper
(
Version
.
parse
(
"3.6.6"
)),
side_effect
=
check_output_wrapper
(
Version
.
parse
(
"3.6.6"
)),
)
)
expected_venv_path
=
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
expected_venv_path
=
tmp_path
/
f
"{venv_name}-py3.6"
python_path
=
expected_venv_path
/
"bin"
/
"python"
python_path
=
expected_venv_path
/
"bin"
/
"python"
venv
=
manager
.
remove
(
str
(
python_path
))
venv
=
manager
.
remove
(
str
(
python_path
))
...
@@ -761,16 +759,16 @@ def test_remove_by_full_path_to_python(
...
@@ -761,16 +759,16 @@ def test_remove_by_full_path_to_python(
def
test_raises_if_acting_on_different_project_by_full_path
(
def
test_raises_if_acting_on_different_project_by_full_path
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
)
->
None
:
)
->
None
:
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
different_venv_name
=
"different-project"
different_venv_name
=
"different-project"
different_venv_path
=
Path
(
tmp_dir
)
/
f
"{different_venv_name}-py3.6"
different_venv_path
=
tmp_path
/
f
"{different_venv_name}-py3.6"
different_venv_bin_path
=
different_venv_path
/
"bin"
different_venv_bin_path
=
different_venv_path
/
"bin"
different_venv_bin_path
.
mkdir
(
parents
=
True
)
different_venv_bin_path
.
mkdir
(
parents
=
True
)
...
@@ -788,12 +786,12 @@ def test_raises_if_acting_on_different_project_by_full_path(
...
@@ -788,12 +786,12 @@ def test_raises_if_acting_on_different_project_by_full_path(
def
test_raises_if_acting_on_different_project_by_name
(
def
test_raises_if_acting_on_different_project_by_name
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
)
->
None
:
)
->
None
:
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
different_venv_name
=
(
different_venv_name
=
(
EnvManager
.
generate_env_name
(
EnvManager
.
generate_env_name
(
...
@@ -802,7 +800,7 @@ def test_raises_if_acting_on_different_project_by_name(
...
@@ -802,7 +800,7 @@ def test_raises_if_acting_on_different_project_by_name(
)
)
+
"-py3.6"
+
"-py3.6"
)
)
different_venv_path
=
Path
(
tmp_dir
)
/
different_venv_name
different_venv_path
=
tmp_path
/
different_venv_name
different_venv_bin_path
=
different_venv_path
/
"bin"
different_venv_bin_path
=
different_venv_path
/
"bin"
different_venv_bin_path
.
mkdir
(
parents
=
True
)
different_venv_bin_path
.
mkdir
(
parents
=
True
)
...
@@ -814,7 +812,7 @@ def test_raises_if_acting_on_different_project_by_name(
...
@@ -814,7 +812,7 @@ def test_raises_if_acting_on_different_project_by_name(
def
test_raises_when_passing_old_env_after_dir_rename
(
def
test_raises_when_passing_old_env_after_dir_rename
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -824,17 +822,17 @@ def test_raises_when_passing_old_env_after_dir_rename(
...
@@ -824,17 +822,17 @@ def test_raises_when_passing_old_env_after_dir_rename(
# root directory of the project, which will create another venv with new name.
# root directory of the project, which will create another venv with new name.
# This is not ideal as you still "can't" remove it by name, but it at least doesn't
# This is not ideal as you still "can't" remove it by name, but it at least doesn't
# cause any unwanted side effects
# cause any unwanted side effects
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
previous_venv_name
=
EnvManager
.
generate_env_name
(
previous_venv_name
=
EnvManager
.
generate_env_name
(
poetry
.
package
.
name
,
poetry
.
package
.
name
,
"previous_dir_name"
,
"previous_dir_name"
,
)
)
venv_path
=
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
venv_path
=
tmp_path
/
f
"{venv_name}-py3.6"
venv_path
.
mkdir
()
venv_path
.
mkdir
()
previous_venv_name
=
f
"{previous_venv_name}-py3.6"
previous_venv_name
=
f
"{previous_venv_name}-py3.6"
previous_venv_path
=
Path
(
tmp_dir
)
/
previous_venv_name
previous_venv_path
=
tmp_path
/
previous_venv_name
previous_venv_path
.
mkdir
()
previous_venv_path
.
mkdir
()
with
pytest
.
raises
(
IncorrectEnvError
):
with
pytest
.
raises
(
IncorrectEnvError
):
...
@@ -842,31 +840,31 @@ def test_raises_when_passing_old_env_after_dir_rename(
...
@@ -842,31 +840,31 @@ def test_raises_when_passing_old_env_after_dir_rename(
def
test_remove_also_deactivates
(
def
test_remove_also_deactivates
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
venv_name
:
str
,
venv_name
:
str
,
)
->
None
:
)
->
None
:
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.7"
)
.
mkdir
()
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
(
tmp_path
/
f
"{venv_name}-py3.6"
)
.
mkdir
()
mocker
.
patch
(
mocker
.
patch
(
"subprocess.check_output"
,
"subprocess.check_output"
,
side_effect
=
check_output_wrapper
(
Version
.
parse
(
"3.6.6"
)),
side_effect
=
check_output_wrapper
(
Version
.
parse
(
"3.6.6"
)),
)
)
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"envs.toml"
)
doc
=
tomlkit
.
document
()
doc
=
tomlkit
.
document
()
doc
[
venv_name
]
=
{
"minor"
:
"3.6"
,
"patch"
:
"3.6.6"
}
doc
[
venv_name
]
=
{
"minor"
:
"3.6"
,
"patch"
:
"3.6.6"
}
envs_file
.
write
(
doc
)
envs_file
.
write
(
doc
)
venv
=
manager
.
remove
(
"python3.6"
)
venv
=
manager
.
remove
(
"python3.6"
)
expected_venv_path
=
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
expected_venv_path
=
tmp_path
/
f
"{venv_name}-py3.6"
assert
venv
.
path
==
expected_venv_path
assert
venv
.
path
==
expected_venv_path
assert
not
expected_venv_path
.
exists
()
assert
not
expected_venv_path
.
exists
()
...
@@ -875,7 +873,7 @@ def test_remove_also_deactivates(
...
@@ -875,7 +873,7 @@ def test_remove_also_deactivates(
def
test_remove_keeps_dir_if_not_deleteable
(
def
test_remove_keeps_dir_if_not_deleteable
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
...
@@ -884,9 +882,9 @@ def test_remove_keeps_dir_if_not_deleteable(
...
@@ -884,9 +882,9 @@ def test_remove_keeps_dir_if_not_deleteable(
)
->
None
:
)
->
None
:
# Ensure we empty rather than delete folder if its is an active mount point.
# Ensure we empty rather than delete folder if its is an active mount point.
# See https://github.com/python-poetry/poetry/pull/2064
# See https://github.com/python-poetry/poetry/pull/2064
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
dir
)}})
config
.
merge
({
"virtualenvs"
:
{
"path"
:
str
(
tmp_
path
)}})
venv_path
=
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.6"
venv_path
=
tmp_path
/
f
"{venv_name}-py3.6"
venv_path
.
mkdir
()
venv_path
.
mkdir
()
folder1_path
=
venv_path
/
"folder1"
folder1_path
=
venv_path
/
"folder1"
...
@@ -928,17 +926,17 @@ def test_remove_keeps_dir_if_not_deleteable(
...
@@ -928,17 +926,17 @@ def test_remove_keeps_dir_if_not_deleteable(
@pytest.mark.skipif
(
os
.
name
==
"nt"
,
reason
=
"Symlinks are not support for Windows"
)
@pytest.mark.skipif
(
os
.
name
==
"nt"
,
reason
=
"Symlinks are not support for Windows"
)
def
test_env_has_symlinks_on_nix
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
)
->
None
:
def
test_env_has_symlinks_on_nix
(
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
)
->
None
:
assert
os
.
path
.
islink
(
tmp_venv
.
python
)
assert
os
.
path
.
islink
(
tmp_venv
.
python
)
def
test_run_with_input
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
)
->
None
:
def
test_run_with_input
(
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
)
->
None
:
result
=
tmp_venv
.
run
(
"python"
,
"-"
,
input_
=
MINIMAL_SCRIPT
)
result
=
tmp_venv
.
run
(
"python"
,
"-"
,
input_
=
MINIMAL_SCRIPT
)
assert
result
==
"Minimal Output"
+
os
.
linesep
assert
result
==
"Minimal Output"
+
os
.
linesep
def
test_run_with_input_non_zero_return
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
)
->
None
:
def
test_run_with_input_non_zero_return
(
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
)
->
None
:
with
pytest
.
raises
(
EnvCommandError
)
as
process_error
:
with
pytest
.
raises
(
EnvCommandError
)
as
process_error
:
# Test command that will return non-zero returncode.
# Test command that will return non-zero returncode.
tmp_venv
.
run
(
"python"
,
"-"
,
input_
=
ERRORING_SCRIPT
)
tmp_venv
.
run
(
"python"
,
"-"
,
input_
=
ERRORING_SCRIPT
)
...
@@ -947,7 +945,7 @@ def test_run_with_input_non_zero_return(tmp_dir: str, tmp_venv: VirtualEnv) -> N
...
@@ -947,7 +945,7 @@ def test_run_with_input_non_zero_return(tmp_dir: str, tmp_venv: VirtualEnv) -> N
def
test_run_with_keyboard_interrupt
(
def
test_run_with_keyboard_interrupt
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
"subprocess.run"
,
side_effect
=
KeyboardInterrupt
())
mocker
.
patch
(
"subprocess.run"
,
side_effect
=
KeyboardInterrupt
())
with
pytest
.
raises
(
KeyboardInterrupt
):
with
pytest
.
raises
(
KeyboardInterrupt
):
...
@@ -956,7 +954,7 @@ def test_run_with_keyboard_interrupt(
...
@@ -956,7 +954,7 @@ def test_run_with_keyboard_interrupt(
def
test_call_with_input_and_keyboard_interrupt
(
def
test_call_with_input_and_keyboard_interrupt
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
"subprocess.run"
,
side_effect
=
KeyboardInterrupt
())
mocker
.
patch
(
"subprocess.run"
,
side_effect
=
KeyboardInterrupt
())
kwargs
=
{
"call"
:
True
}
kwargs
=
{
"call"
:
True
}
...
@@ -966,7 +964,7 @@ def test_call_with_input_and_keyboard_interrupt(
...
@@ -966,7 +964,7 @@ def test_call_with_input_and_keyboard_interrupt(
def
test_call_no_input_with_keyboard_interrupt
(
def
test_call_no_input_with_keyboard_interrupt
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
"subprocess.call"
,
side_effect
=
KeyboardInterrupt
())
mocker
.
patch
(
"subprocess.call"
,
side_effect
=
KeyboardInterrupt
())
kwargs
=
{
"call"
:
True
}
kwargs
=
{
"call"
:
True
}
...
@@ -976,7 +974,7 @@ def test_call_no_input_with_keyboard_interrupt(
...
@@ -976,7 +974,7 @@ def test_call_no_input_with_keyboard_interrupt(
def
test_run_with_called_process_error
(
def
test_run_with_called_process_error
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
mocker
.
patch
(
"subprocess.run"
,
"subprocess.run"
,
...
@@ -992,7 +990,7 @@ def test_run_with_called_process_error(
...
@@ -992,7 +990,7 @@ def test_run_with_called_process_error(
def
test_call_with_input_and_called_process_error
(
def
test_call_with_input_and_called_process_error
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
mocker
.
patch
(
"subprocess.run"
,
"subprocess.run"
,
...
@@ -1009,7 +1007,7 @@ def test_call_with_input_and_called_process_error(
...
@@ -1009,7 +1007,7 @@ def test_call_with_input_and_called_process_error(
def
test_call_no_input_with_called_process_error
(
def
test_call_no_input_with_called_process_error
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
mocker
.
patch
(
"subprocess.call"
,
"subprocess.call"
,
...
@@ -1026,7 +1024,7 @@ def test_call_no_input_with_called_process_error(
...
@@ -1026,7 +1024,7 @@ def test_call_no_input_with_called_process_error(
def
test_check_output_with_called_process_error
(
def
test_check_output_with_called_process_error
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
mocker
.
patch
(
"subprocess.check_output"
,
"subprocess.check_output"
,
...
@@ -1067,7 +1065,7 @@ for i in range(10000):
...
@@ -1067,7 +1065,7 @@ for i in range(10000):
def
test_run_python_script_called_process_error
(
def
test_run_python_script_called_process_error
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
mocker
.
patch
(
"subprocess.run"
,
"subprocess.run"
,
...
@@ -1081,7 +1079,7 @@ def test_run_python_script_called_process_error(
...
@@ -1081,7 +1079,7 @@ def test_run_python_script_called_process_error(
assert
"some error"
in
str
(
error
.
value
)
assert
"some error"
in
str
(
error
.
value
)
def
test_run_python_script_only_stdout
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
)
->
None
:
def
test_run_python_script_only_stdout
(
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
)
->
None
:
output
=
tmp_venv
.
run_python_script
(
output
=
tmp_venv
.
run_python_script
(
"import sys; print('some warning', file=sys.stderr); print('some output')"
"import sys; print('some warning', file=sys.stderr); print('some output')"
)
)
...
@@ -1358,7 +1356,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
...
@@ -1358,7 +1356,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
manager
:
EnvManager
,
manager
:
EnvManager
,
poetry
:
Poetry
,
poetry
:
Poetry
,
config
:
Config
,
config
:
Config
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
)
->
None
:
)
->
None
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
if
"VIRTUAL_ENV"
in
os
.
environ
:
...
@@ -1367,7 +1365,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
...
@@ -1367,7 +1365,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
config
.
merge
(
config
.
merge
(
{
{
"virtualenvs"
:
{
"virtualenvs"
:
{
"path"
:
str
(
Path
(
tmp_dir
)
/
"virtualenvs"
),
"path"
:
str
(
tmp_path
/
"virtualenvs"
),
"in-project"
:
True
,
"in-project"
:
True
,
}
}
}
}
...
@@ -1398,7 +1396,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
...
@@ -1398,7 +1396,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
prompt
=
"simple-project-py3.7"
,
prompt
=
"simple-project-py3.7"
,
)
)
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"virtualenvs"
/
"envs.toml"
)
envs_file
=
TOMLFile
(
tmp_path
/
"virtualenvs"
/
"envs.toml"
)
assert
not
envs_file
.
exists
()
assert
not
envs_file
.
exists
()
...
@@ -1479,8 +1477,8 @@ def test_env_no_pip(
...
@@ -1479,8 +1477,8 @@ def test_env_no_pip(
assert
installed_packages
==
packages
assert
installed_packages
==
packages
def
test_env_finds_the_correct_executables
(
tmp_
dir
:
str
,
manager
:
EnvManager
)
->
None
:
def
test_env_finds_the_correct_executables
(
tmp_
path
:
Path
,
manager
:
EnvManager
)
->
None
:
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
venv_path
=
tmp_path
/
"Virtual Env"
manager
.
build_venv
(
venv_path
,
with_pip
=
True
)
manager
.
build_venv
(
venv_path
,
with_pip
=
True
)
venv
=
VirtualEnv
(
venv_path
)
venv
=
VirtualEnv
(
venv_path
)
...
@@ -1510,10 +1508,10 @@ def test_env_finds_the_correct_executables(tmp_dir: str, manager: EnvManager) ->
...
@@ -1510,10 +1508,10 @@ def test_env_finds_the_correct_executables(tmp_dir: str, manager: EnvManager) ->
def
test_env_finds_the_correct_executables_for_generic_env
(
def
test_env_finds_the_correct_executables_for_generic_env
(
tmp_
dir
:
str
,
manager
:
EnvManager
tmp_
path
:
Path
,
manager
:
EnvManager
)
->
None
:
)
->
None
:
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
venv_path
=
tmp_path
/
"Virtual Env"
child_venv_path
=
Path
(
tmp_dir
)
/
"Child Virtual Env"
child_venv_path
=
tmp_path
/
"Child Virtual Env"
manager
.
build_venv
(
venv_path
,
with_pip
=
True
)
manager
.
build_venv
(
venv_path
,
with_pip
=
True
)
parent_venv
=
VirtualEnv
(
venv_path
)
parent_venv
=
VirtualEnv
(
venv_path
)
manager
.
build_venv
(
child_venv_path
,
executable
=
parent_venv
.
python
,
with_pip
=
True
)
manager
.
build_venv
(
child_venv_path
,
executable
=
parent_venv
.
python
,
with_pip
=
True
)
...
@@ -1535,10 +1533,10 @@ def test_env_finds_the_correct_executables_for_generic_env(
...
@@ -1535,10 +1533,10 @@ def test_env_finds_the_correct_executables_for_generic_env(
def
test_env_finds_fallback_executables_for_generic_env
(
def
test_env_finds_fallback_executables_for_generic_env
(
tmp_
dir
:
str
,
manager
:
EnvManager
tmp_
path
:
Path
,
manager
:
EnvManager
)
->
None
:
)
->
None
:
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
venv_path
=
tmp_path
/
"Virtual Env"
child_venv_path
=
Path
(
tmp_dir
)
/
"Child Virtual Env"
child_venv_path
=
tmp_path
/
"Child Virtual Env"
manager
.
build_venv
(
venv_path
,
with_pip
=
True
)
manager
.
build_venv
(
venv_path
,
with_pip
=
True
)
parent_venv
=
VirtualEnv
(
venv_path
)
parent_venv
=
VirtualEnv
(
venv_path
)
manager
.
build_venv
(
child_venv_path
,
executable
=
parent_venv
.
python
,
with_pip
=
True
)
manager
.
build_venv
(
child_venv_path
,
executable
=
parent_venv
.
python
,
with_pip
=
True
)
...
@@ -1646,7 +1644,7 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(
...
@@ -1646,7 +1644,7 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(
def
test_generate_env_name_ignores_case_for_case_insensitive_fs
(
def
test_generate_env_name_ignores_case_for_case_insensitive_fs
(
poetry
:
Poetry
,
poetry
:
Poetry
,
tmp_
dir
:
str
,
tmp_
path
:
Path
,
)
->
None
:
)
->
None
:
venv_name1
=
EnvManager
.
generate_env_name
(
poetry
.
package
.
name
,
"MyDiR"
)
venv_name1
=
EnvManager
.
generate_env_name
(
poetry
.
package
.
name
,
"MyDiR"
)
venv_name2
=
EnvManager
.
generate_env_name
(
poetry
.
package
.
name
,
"mYdIr"
)
venv_name2
=
EnvManager
.
generate_env_name
(
poetry
.
package
.
name
,
"mYdIr"
)
...
@@ -1656,7 +1654,9 @@ def test_generate_env_name_ignores_case_for_case_insensitive_fs(
...
@@ -1656,7 +1654,9 @@ def test_generate_env_name_ignores_case_for_case_insensitive_fs(
assert
venv_name1
!=
venv_name2
assert
venv_name1
!=
venv_name2
def
test_generate_env_name_uses_real_path
(
tmp_dir
:
str
,
mocker
:
MockerFixture
)
->
None
:
def
test_generate_env_name_uses_real_path
(
tmp_path
:
Path
,
mocker
:
MockerFixture
)
->
None
:
mocker
.
patch
(
"os.path.realpath"
,
return_value
=
"the_real_dir"
)
mocker
.
patch
(
"os.path.realpath"
,
return_value
=
"the_real_dir"
)
venv_name1
=
EnvManager
.
generate_env_name
(
"simple-project"
,
"the_real_dir"
)
venv_name1
=
EnvManager
.
generate_env_name
(
"simple-project"
,
"the_real_dir"
)
venv_name2
=
EnvManager
.
generate_env_name
(
"simple-project"
,
"linked_dir"
)
venv_name2
=
EnvManager
.
generate_env_name
(
"simple-project"
,
"linked_dir"
)
...
@@ -1673,10 +1673,10 @@ def extended_without_setup_poetry() -> Poetry:
...
@@ -1673,10 +1673,10 @@ def extended_without_setup_poetry() -> Poetry:
def
test_build_environment_called_build_script_specified
(
def
test_build_environment_called_build_script_specified
(
mocker
:
MockerFixture
,
extended_without_setup_poetry
:
Poetry
,
tmp_
dir
:
str
mocker
:
MockerFixture
,
extended_without_setup_poetry
:
Poetry
,
tmp_
path
:
Path
)
->
None
:
)
->
None
:
project_env
=
MockEnv
(
path
=
Path
(
tmp_dir
)
/
"project"
)
project_env
=
MockEnv
(
path
=
tmp_path
/
"project"
)
ephemeral_env
=
MockEnv
(
path
=
Path
(
tmp_dir
)
/
"ephemeral"
)
ephemeral_env
=
MockEnv
(
path
=
tmp_path
/
"ephemeral"
)
mocker
.
patch
(
mocker
.
patch
(
"poetry.utils.env.ephemeral_environment"
"poetry.utils.env.ephemeral_environment"
...
@@ -1698,10 +1698,10 @@ def test_build_environment_called_build_script_specified(
...
@@ -1698,10 +1698,10 @@ def test_build_environment_called_build_script_specified(
def
test_build_environment_not_called_without_build_script_specified
(
def
test_build_environment_not_called_without_build_script_specified
(
mocker
:
MockerFixture
,
poetry
:
Poetry
,
tmp_
dir
:
str
mocker
:
MockerFixture
,
poetry
:
Poetry
,
tmp_
path
:
Path
)
->
None
:
)
->
None
:
project_env
=
MockEnv
(
path
=
Path
(
tmp_dir
)
/
"project"
)
project_env
=
MockEnv
(
path
=
tmp_path
/
"project"
)
ephemeral_env
=
MockEnv
(
path
=
Path
(
tmp_dir
)
/
"ephemeral"
)
ephemeral_env
=
MockEnv
(
path
=
tmp_path
/
"ephemeral"
)
mocker
.
patch
(
mocker
.
patch
(
"poetry.utils.env.ephemeral_environment"
"poetry.utils.env.ephemeral_environment"
...
...
tests/utils/test_env_site.py
View file @
3a31f2de
...
@@ -12,12 +12,12 @@ if TYPE_CHECKING:
...
@@ -12,12 +12,12 @@ if TYPE_CHECKING:
from
pytest_mock
import
MockerFixture
from
pytest_mock
import
MockerFixture
def
test_env_site_simple
(
tmp_
dir
:
str
,
mocker
:
MockerFixture
):
def
test_env_site_simple
(
tmp_
path
:
Path
,
mocker
:
MockerFixture
):
# emulate permission error when creating directory
# emulate permission error when creating directory
mocker
.
patch
(
"pathlib.Path.mkdir"
,
side_effect
=
OSError
())
mocker
.
patch
(
"pathlib.Path.mkdir"
,
side_effect
=
OSError
())
site_packages
=
SitePackages
(
Path
(
"/non-existent"
),
fallbacks
=
[
Path
(
tmp_dir
)
])
site_packages
=
SitePackages
(
Path
(
"/non-existent"
),
fallbacks
=
[
tmp_path
])
candidates
=
site_packages
.
make_candidates
(
Path
(
"hello.txt"
),
writable_only
=
True
)
candidates
=
site_packages
.
make_candidates
(
Path
(
"hello.txt"
),
writable_only
=
True
)
hello
=
Path
(
tmp_dir
)
/
"hello.txt"
hello
=
tmp_path
/
"hello.txt"
assert
len
(
candidates
)
==
1
assert
len
(
candidates
)
==
1
assert
candidates
[
0
]
.
as_posix
()
==
hello
.
as_posix
()
assert
candidates
[
0
]
.
as_posix
()
==
hello
.
as_posix
()
...
@@ -30,12 +30,11 @@ def test_env_site_simple(tmp_dir: str, mocker: MockerFixture):
...
@@ -30,12 +30,11 @@ def test_env_site_simple(tmp_dir: str, mocker: MockerFixture):
assert
not
(
site_packages
.
path
/
"hello.txt"
)
.
exists
()
assert
not
(
site_packages
.
path
/
"hello.txt"
)
.
exists
()
def
test_env_site_select_first
(
tmp_dir
:
str
):
def
test_env_site_select_first
(
tmp_path
:
Path
):
path
=
Path
(
tmp_dir
)
fallback
=
tmp_path
/
"fallback"
fallback
=
path
/
"fallback"
fallback
.
mkdir
(
parents
=
True
)
fallback
.
mkdir
(
parents
=
True
)
site_packages
=
SitePackages
(
path
,
fallbacks
=
[
fallback
])
site_packages
=
SitePackages
(
tmp_
path
,
fallbacks
=
[
fallback
])
candidates
=
site_packages
.
make_candidates
(
Path
(
"hello.txt"
),
writable_only
=
True
)
candidates
=
site_packages
.
make_candidates
(
Path
(
"hello.txt"
),
writable_only
=
True
)
assert
len
(
candidates
)
==
2
assert
len
(
candidates
)
==
2
...
...
tests/utils/test_pip.py
View file @
3a31f2de
...
@@ -10,6 +10,8 @@ from poetry.utils.pip import pip_install
...
@@ -10,6 +10,8 @@ from poetry.utils.pip import pip_install
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
pathlib
import
Path
from
pytest_mock
import
MockerFixture
from
pytest_mock
import
MockerFixture
from
poetry.utils.env
import
VirtualEnv
from
poetry.utils.env
import
VirtualEnv
...
@@ -17,7 +19,7 @@ if TYPE_CHECKING:
...
@@ -17,7 +19,7 @@ if TYPE_CHECKING:
def
test_pip_install_successful
(
def
test_pip_install_successful
(
tmp_
dir
:
str
,
tmp_venv
:
VirtualEnv
,
fixture_dir
:
FixtureDirGetter
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
fixture_dir
:
FixtureDirGetter
):
):
file_path
=
fixture_dir
(
"distributions/demo-0.1.0-py2.py3-none-any.whl"
)
file_path
=
fixture_dir
(
"distributions/demo-0.1.0-py2.py3-none-any.whl"
)
result
=
pip_install
(
file_path
,
tmp_venv
)
result
=
pip_install
(
file_path
,
tmp_venv
)
...
@@ -26,7 +28,7 @@ def test_pip_install_successful(
...
@@ -26,7 +28,7 @@ def test_pip_install_successful(
def
test_pip_install_with_keyboard_interrupt
(
def
test_pip_install_with_keyboard_interrupt
(
tmp_
dir
:
str
,
tmp_
path
:
Path
,
tmp_venv
:
VirtualEnv
,
tmp_venv
:
VirtualEnv
,
fixture_dir
:
FixtureDirGetter
,
fixture_dir
:
FixtureDirGetter
,
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
...
...
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