Skip to content

Commit 751cfd0

Browse files
JohananOppongAmoatengadamghill
authored andcommitted
fix linting
1 parent d7fe5cc commit 751cfd0

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/django_unicorn/components/unicorn_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def __init__(self, component_args: list | None = None, **kwargs):
241241
# Apply Meta.component_key as a class-level default when the template
242242
# tag has not provided a key (i.e. self.component_key is still empty).
243243
if not self.component_key and hasattr(self, "Meta") and hasattr(self.Meta, "component_key"):
244-
self.component_key = self.Meta.component_key
244+
self.component_key = cast(str, self.Meta.component_key)
245245

246246
self._set_default_template_name()
247247
self._set_caches()

tests/components/test_component.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from tests.views.fake_components import (
77
FakeAuthenticationComponent,
88
FakeValidationComponent,
9+
FakeValidationForm,
910
)
1011

1112
from django_unicorn.components import UnicornView
@@ -433,7 +434,7 @@ class TestComponent(UnicornView):
433434
class Meta:
434435
template_name = 123
435436

436-
with pytest.raises(AssertionError, match="Meta.template_name should be a str"):
437+
with pytest.raises(AssertionError, match=r"Meta\.template_name should be a str"):
437438
TestComponent(component_id="test_meta_template_name_invalid", component_name="test")
438439

439440

@@ -454,9 +455,9 @@ class Meta:
454455
def test_meta_template_html_invalid_type():
455456
class TestComponent(UnicornView):
456457
class Meta:
457-
template_html = ["<div>oops</div>"]
458+
template_html = 123
458459

459-
with pytest.raises(AssertionError, match="Meta.template_html should be a str"):
460+
with pytest.raises(AssertionError, match=r"Meta\.template_html should be a str"):
460461
TestComponent(component_id="test_meta_template_html_invalid", component_name="test")
461462

462463

@@ -470,9 +471,7 @@ class TestComponent(UnicornView):
470471
class Meta:
471472
component_key = "default-key"
472473

473-
component = TestComponent(
474-
component_id="test_meta_component_key", component_name="test", component_key=""
475-
)
474+
component = TestComponent(component_id="test_meta_component_key", component_name="test", component_key="")
476475
assert component.component_key == "default-key"
477476

478477

@@ -498,16 +497,14 @@ class TestComponent(UnicornView):
498497
class Meta:
499498
component_key = 42
500499

501-
with pytest.raises(AssertionError, match="Meta.component_key should be a str"):
500+
with pytest.raises(AssertionError, match=r"Meta\.component_key should be a str"):
502501
TestComponent(component_id="test_meta_component_key_invalid", component_name="test")
503502

504503

505504
# ── Meta: form_class ──────────────────────────────────────────────────────────
506505

507506

508507
def test_meta_form_class_validates():
509-
from tests.views.fake_components import FakeValidationForm
510-
511508
class TestComponent(UnicornView):
512509
template_name = "unicorn/test.html"
513510
text = "hi"
@@ -526,11 +523,6 @@ class Meta:
526523

527524
def test_meta_form_class_not_in_frontend_context():
528525
"""form_class must never appear in the component's public attributes."""
529-
from tests.views.fake_components import FakeValidationComponent
530526

531-
component = FakeValidationComponent(
532-
component_id="test_form_class_not_in_context", component_name="example"
533-
)
527+
component = FakeValidationComponent(component_id="test_form_class_not_in_context", component_name="example")
534528
assert "form_class" not in component._attributes()
535-
536-

0 commit comments

Comments
 (0)