mirror of
https://github.com/django-components/django-components.git
synced 2025-08-30 18:57:20 +00:00
feat: on_slot_rendered extension hook + refactor debug highlight as extension (#1209)
* feat: on_slot_rendered extension hook + refactor debug highlight as extension * refactor: fix whitespace in test output
This commit is contained in:
parent
223fc2c68c
commit
6ff2d78a2f
12 changed files with 560 additions and 77 deletions
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
import sys
|
||||
from io import StringIO
|
||||
from textwrap import dedent
|
||||
|
@ -97,7 +98,14 @@ class TestExtensionsListCommand:
|
|||
call_command("components", "ext", "list")
|
||||
output = out.getvalue()
|
||||
|
||||
assert output.strip() == "name \n========\ncache \ndefaults\nview"
|
||||
assert output.strip() == (
|
||||
"name \n"
|
||||
"===============\n"
|
||||
"cache \n"
|
||||
"defaults \n"
|
||||
"view \n"
|
||||
"debug_highlight"
|
||||
)
|
||||
|
||||
@djc_test(
|
||||
components_settings={"extensions": [EmptyExtension, DummyExtension]},
|
||||
|
@ -108,7 +116,16 @@ class TestExtensionsListCommand:
|
|||
call_command("components", "ext", "list")
|
||||
output = out.getvalue()
|
||||
|
||||
assert output.strip() == "name \n========\ncache \ndefaults\nview \nempty \ndummy"
|
||||
assert output.strip() == (
|
||||
"name \n"
|
||||
"===============\n"
|
||||
"cache \n"
|
||||
"defaults \n"
|
||||
"view \n"
|
||||
"debug_highlight\n"
|
||||
"empty \n"
|
||||
"dummy"
|
||||
)
|
||||
|
||||
@djc_test(
|
||||
components_settings={"extensions": [EmptyExtension, DummyExtension]},
|
||||
|
@ -119,7 +136,16 @@ class TestExtensionsListCommand:
|
|||
call_command("components", "ext", "list", "--all")
|
||||
output = out.getvalue()
|
||||
|
||||
assert output.strip() == "name \n========\ncache \ndefaults\nview \nempty \ndummy"
|
||||
assert output.strip() == (
|
||||
"name \n"
|
||||
"===============\n"
|
||||
"cache \n"
|
||||
"defaults \n"
|
||||
"view \n"
|
||||
"debug_highlight\n"
|
||||
"empty \n"
|
||||
"dummy"
|
||||
)
|
||||
|
||||
@djc_test(
|
||||
components_settings={"extensions": [EmptyExtension, DummyExtension]},
|
||||
|
@ -130,7 +156,16 @@ class TestExtensionsListCommand:
|
|||
call_command("components", "ext", "list", "--columns", "name")
|
||||
output = out.getvalue()
|
||||
|
||||
assert output.strip() == "name \n========\ncache \ndefaults\nview \nempty \ndummy"
|
||||
assert output.strip() == (
|
||||
"name \n"
|
||||
"===============\n"
|
||||
"cache \n"
|
||||
"defaults \n"
|
||||
"view \n"
|
||||
"debug_highlight\n"
|
||||
"empty \n"
|
||||
"dummy"
|
||||
)
|
||||
|
||||
@djc_test(
|
||||
components_settings={"extensions": [EmptyExtension, DummyExtension]},
|
||||
|
@ -141,7 +176,14 @@ class TestExtensionsListCommand:
|
|||
call_command("components", "ext", "list", "--simple")
|
||||
output = out.getvalue()
|
||||
|
||||
assert output.strip() == "cache \ndefaults\nview \nempty \ndummy"
|
||||
assert output.strip() == (
|
||||
"cache \n"
|
||||
"defaults \n"
|
||||
"view \n"
|
||||
"debug_highlight\n"
|
||||
"empty \n"
|
||||
"dummy"
|
||||
)
|
||||
|
||||
|
||||
@djc_test
|
||||
|
@ -155,11 +197,16 @@ class TestExtensionsRunCommand:
|
|||
call_command("components", "ext", "run")
|
||||
output = out.getvalue()
|
||||
|
||||
# Fix line breaking in CI on the first line between the `[-h]` and `{{cmd_name}}`
|
||||
output = re.compile(r"\]\s+\{").sub("] {", output)
|
||||
# Fix line breaking in CI on the first line between the `{{cmd_name}}` and `...`
|
||||
output = re.compile(r"\}\s+\.\.\.").sub("} ...", output)
|
||||
|
||||
assert (
|
||||
output
|
||||
== dedent(
|
||||
f"""
|
||||
usage: components ext run [-h] {{cache,defaults,view,empty,dummy}} ...
|
||||
usage: components ext run [-h] {{cache,defaults,view,debug_highlight,empty,dummy}} ...
|
||||
|
||||
Run a command added by an extension.
|
||||
|
||||
|
@ -167,10 +214,11 @@ class TestExtensionsRunCommand:
|
|||
-h, --help show this help message and exit
|
||||
|
||||
subcommands:
|
||||
{{cache,defaults,view,empty,dummy}}
|
||||
{{cache,defaults,view,debug_highlight,empty,dummy}}
|
||||
cache Run commands added by the 'cache' extension.
|
||||
defaults Run commands added by the 'defaults' extension.
|
||||
view Run commands added by the 'view' extension.
|
||||
debug_highlight Run commands added by the 'debug_highlight' extension.
|
||||
empty Run commands added by the 'empty' extension.
|
||||
dummy Run commands added by the 'dummy' extension.
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue