-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces a new cache sub-command that lists all available caches. Relates-to: #1162
- Loading branch information
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
|
||
from ..command import Command | ||
|
||
|
||
class CacheListCommand(Command): | ||
|
||
name = "list" | ||
description = "List Poetry's caches." | ||
|
||
def handle(self): | ||
from poetry.locations import REPOSITORY_CACHE_DIR | ||
|
||
if os.path.exists(str(REPOSITORY_CACHE_DIR)): | ||
caches = list(sorted(REPOSITORY_CACHE_DIR.iterdir())) | ||
if caches: | ||
for cache in caches: | ||
self.line("<info>{}</>".format(cache.name)) | ||
return 0 | ||
|
||
self.line("<warning>No caches found</>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import uuid | ||
|
||
import pytest | ||
|
||
from cleo.testers import CommandTester | ||
|
||
|
||
@pytest.fixture | ||
def repository_cache_dir(monkeypatch, tmpdir): | ||
import poetry.locations | ||
from poetry.utils._compat import Path | ||
|
||
path = Path(tmpdir) | ||
monkeypatch.setattr(poetry.locations, "REPOSITORY_CACHE_DIR", path) | ||
return path | ||
|
||
|
||
@pytest.fixture | ||
def repository_one(): | ||
return "01_{}".format(uuid.uuid4()) | ||
|
||
|
||
@pytest.fixture | ||
def repository_two(): | ||
return "02_{}".format(uuid.uuid4()) | ||
|
||
|
||
@pytest.fixture | ||
def mock_caches(repository_cache_dir, repository_one, repository_two): | ||
(repository_cache_dir / repository_one).mkdir() | ||
(repository_cache_dir / repository_two).mkdir() | ||
|
||
|
||
def test_cache_list(app, mock_caches, repository_one, repository_two): | ||
command = app.find("cache list") | ||
tester = CommandTester(command) | ||
|
||
tester.execute() | ||
|
||
expected = """\ | ||
{} | ||
{} | ||
""".format( | ||
repository_one, repository_two | ||
) | ||
|
||
assert expected == tester.io.fetch_output() | ||
|
||
|
||
def test_cache_list_empty(app, repository_cache_dir): | ||
command = app.find("cache list") | ||
tester = CommandTester(command) | ||
|
||
tester.execute() | ||
|
||
expected = """\ | ||
No caches found | ||
""" | ||
|
||
assert expected == tester.io.fetch_output() |