feat: add a command to list all components (#1041)

* feat: add a command to list all components

* refactor: fix tests

* refactor: fix linter errors

* refactor: fix the tests for tests running within tox

* temp: print out test outputs

* refactor: fix tests for windows

* refactor: remove escape from slash?

* refactor: fixes to regex

* refactor: remove print statements

* docs: update API reference
This commit is contained in:
Juro Oravec 2025-03-19 09:38:25 +01:00 committed by GitHub
parent 107284f474
commit 0f41a62592
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 647 additions and 63 deletions

View file

@ -91,40 +91,57 @@ class TestExtensionsCommand:
@djc_test
class TestExtensionsListCommand:
def test_list_command_default(self):
def test_list_default_extensions(self):
out = StringIO()
with patch("sys.stdout", new=out):
call_command("components", "ext", "list")
output = out.getvalue()
assert "Installed extensions:\nview\n" == output
# Check that it omits the title when verbose is 0
out = StringIO()
with patch("sys.stdout", new=out):
call_command("components", "ext", "list", "-v", "0")
output = out.getvalue()
assert "view\n" == output
assert output.strip() == "name\n====\nview"
@djc_test(
components_settings={"extensions": [EmptyExtension, DummyExtension]},
)
def test_list_command_extra(self):
def test_list_extra_extensions(self):
out = StringIO()
with patch("sys.stdout", new=out):
call_command("components", "ext", "list")
output = out.getvalue()
assert "Installed extensions:\nview\nempty\ndummy\n" == output
assert output.strip() == "name \n=====\nview \nempty\ndummy"
# Check that it omits the title when verbose is 0
@djc_test(
components_settings={"extensions": [EmptyExtension, DummyExtension]},
)
def test_list_all(self):
out = StringIO()
with patch("sys.stdout", new=out):
call_command("components", "ext", "list", "-v", "0")
call_command("components", "ext", "list", "--all")
output = out.getvalue()
assert "view\nempty\ndummy\n" == output
assert output.strip() == "name \n=====\nview \nempty\ndummy"
@djc_test(
components_settings={"extensions": [EmptyExtension, DummyExtension]},
)
def test_list_specific_columns(self):
out = StringIO()
with patch("sys.stdout", new=out):
call_command("components", "ext", "list", "--columns", "name")
output = out.getvalue()
assert output.strip() == "name \n=====\nview \nempty\ndummy"
@djc_test(
components_settings={"extensions": [EmptyExtension, DummyExtension]},
)
def test_list_simple(self):
out = StringIO()
with patch("sys.stdout", new=out):
call_command("components", "ext", "list", "--simple")
output = out.getvalue()
assert output.strip() == "view \nempty\ndummy"
@djc_test