Skip to content

Commit 91d7cb6

Browse files
erralclaude
andcommitted
Fix lint issues
- Fix line too long in docstrings - Remove unused variable - Add ClassVar annotation for mutable class attribute - Combine nested if statements - Use next(iter()) instead of list()[0] 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e01664a commit 91d7cb6

6 files changed

Lines changed: 69 additions & 33 deletions

File tree

src/cs_dynamicpages/tests/test_indexer_content_index_extender.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from cs_dynamicpages.indexers.content_index_extender import extract_text_value_to_index
22
from cs_dynamicpages.indexers.content_index_extender import FIELDS_TO_INDEX
33
from cs_dynamicpages.indexers.content_index_extender import FolderishItemTextExtender
4-
from cs_dynamicpages.indexers.content_index_extender import get_available_text_from_dynamic_pages
4+
from cs_dynamicpages.indexers.content_index_extender import (
5+
get_available_text_from_dynamic_pages,
6+
)
57
from cs_dynamicpages.indexers.content_index_extender import get_enabled_fields
68
from cs_dynamicpages.testing import CS_DYNAMICPAGES_INTEGRATION_TESTING
79
from plone import api

src/cs_dynamicpages/tests/test_upgrade_step_1002.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def setUp(self):
2323
self.original_values = {}
2424
for key in UPGRADEABLE_KEYS:
2525
record_name = f"cs_dynamicpages.dynamic_pages_control_panel.{key}"
26-
self.original_values[key] = list(api.portal.get_registry_record(record_name))
26+
self.original_values[key] = list(
27+
api.portal.get_registry_record(record_name)
28+
)
2729
# Clear any existing upgrade annotations
2830
self._clear_upgrade_annotations()
2931

@@ -44,7 +46,9 @@ def _clear_upgrade_annotations(self):
4446
"""Clear any upgrade annotations from the portal."""
4547
annotations = IAnnotations(self.portal)
4648
for key in UPGRADEABLE_KEYS:
47-
annotation_key = f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
49+
annotation_key = (
50+
f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
51+
)
4852
if annotation_key in annotations:
4953
del annotations[annotation_key]
5054

@@ -61,7 +65,9 @@ def test_pre_handler_saves_values_to_annotations(self):
6165
# Check annotations were created
6266
annotations = IAnnotations(self.portal)
6367
for key in UPGRADEABLE_KEYS:
64-
annotation_key = f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
68+
annotation_key = (
69+
f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
70+
)
6571
self.assertIn(annotation_key, annotations)
6672
# Value should be a JSON string
6773
value_str = annotations[annotation_key]
@@ -73,14 +79,17 @@ def test_pre_handler_saves_values_to_annotations(self):
7379
def test_post_handler_restores_values_from_annotations(self):
7480
"""Test that post_handler restores values from annotations.
7581
76-
Note: pre_handler reads from old typo registry key 'dynamica_pages_control_panel'
77-
which is typically empty. This test verifies the restore mechanism works
78-
by manually setting up annotations.
82+
Note: pre_handler reads from old typo registry key
83+
'dynamica_pages_control_panel' which is typically empty.
84+
This test verifies the restore mechanism works by manually
85+
setting up annotations.
7986
"""
8087
# Manually set up annotations with known values
8188
annotations = IAnnotations(self.portal)
8289
for key in UPGRADEABLE_KEYS:
83-
annotation_key = f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
90+
annotation_key = (
91+
f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
92+
)
8493
# Store current values in annotations
8594
current_values = api.portal.get_registry_record(
8695
f"cs_dynamicpages.dynamic_pages_control_panel.{key}", default=[]
@@ -105,23 +114,29 @@ def test_post_handler_removes_annotations(self):
105114
annotations = IAnnotations(self.portal)
106115
# Verify annotations exist
107116
for key in UPGRADEABLE_KEYS:
108-
annotation_key = f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
117+
annotation_key = (
118+
f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
119+
)
109120
self.assertIn(annotation_key, annotations)
110121

111122
# Run post_handler
112123
post_handler()
113124

114125
# Verify annotations were removed
115126
for key in UPGRADEABLE_KEYS:
116-
annotation_key = f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
127+
annotation_key = (
128+
f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
129+
)
117130
self.assertNotIn(annotation_key, annotations)
118131

119132
def test_post_handler_handles_invalid_json(self):
120133
"""Test that post_handler handles invalid JSON gracefully."""
121134
# Manually set invalid JSON in annotations
122135
annotations = IAnnotations(self.portal)
123136
for key in UPGRADEABLE_KEYS:
124-
annotation_key = f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
137+
annotation_key = (
138+
f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
139+
)
125140
annotations[annotation_key] = "invalid json {"
126141

127142
# Should not raise exception
@@ -139,7 +154,9 @@ def test_post_handler_handles_non_list_value(self):
139154
# Manually set a non-list JSON value
140155
annotations = IAnnotations(self.portal)
141156
for key in UPGRADEABLE_KEYS:
142-
annotation_key = f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
157+
annotation_key = (
158+
f"cs_dynamicpages.dynamic_pages_control_panel.{key}.UPGRADE"
159+
)
143160
annotations[annotation_key] = json.dumps({"not": "a list"})
144161

145162
# Should not raise exception

src/cs_dynamicpages/tests/test_upgrade_step_1005.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ def test_upgrade_adds_title_description_view_if_missing(self):
7777
"""Test that upgrade adds title-description-view if not present."""
7878
record_name = "cs_dynamicpages.dynamic_pages_control_panel.row_type_fields"
7979

80-
# Check if view exists before upgrade
81-
values = api.portal.get_registry_record(record_name)
82-
view_names = [v["row_type"] for v in values]
83-
8480
# Run upgrade
8581
upgrade()
8682

src/cs_dynamicpages/tests/test_upgrade_step_1007.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from plone import api
44
from plone.app.testing import setRoles
55
from plone.app.testing import TEST_USER_ID
6+
from typing import ClassVar
67

78
import unittest
89

@@ -13,7 +14,7 @@ class UpgradeStep1007IntegrationTest(unittest.TestCase):
1314
layer = CS_DYNAMICPAGES_INTEGRATION_TESTING
1415

1516
# Row types that should get the fetchpriority_image field
16-
TARGET_ROW_TYPES = [
17+
TARGET_ROW_TYPES: ClassVar[list[str]] = [
1718
"cs_dynamicpages-slider-view",
1819
"cs_dynamicpages-features-view",
1920
"cs_dynamicpages-query-columns-view",
@@ -75,13 +76,15 @@ def test_upgrade_does_not_add_field_to_other_row_types(self):
7576
# Check non-target row types do not have the field (unless they had it before)
7677
updated_values = api.portal.get_registry_record(record_name)
7778
for value in updated_values:
78-
if value["row_type"] not in self.TARGET_ROW_TYPES:
79-
if not non_target_types_fields.get(value["row_type"], False):
80-
self.assertNotIn(
81-
"IFetchPriorityImage.fetchpriority_image",
82-
value["each_row_type_fields"],
83-
f"Field unexpectedly added to non-target row type {value['row_type']}",
84-
)
79+
row_type = value["row_type"]
80+
is_non_target = row_type not in self.TARGET_ROW_TYPES
81+
had_field_before = non_target_types_fields.get(row_type, False)
82+
if is_non_target and not had_field_before:
83+
self.assertNotIn(
84+
"IFetchPriorityImage.fetchpriority_image",
85+
value["each_row_type_fields"],
86+
f"Field unexpectedly added to non-target: {row_type}",
87+
)
8588

8689
def test_upgrade_preserves_existing_fields_in_target_types(self):
8790
"""Test that upgrade preserves existing fields in target row types."""

src/cs_dynamicpages/tests/test_utils.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,39 @@ class TestUrlUsesScheme(unittest.TestCase):
6565
"""Tests for _url_uses_scheme function."""
6666

6767
def test_returns_true_for_mailto(self):
68-
self.assertTrue(_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "mailto:test@example.com"))
68+
self.assertTrue(
69+
_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "mailto:test@example.com")
70+
)
6971

7072
def test_returns_true_for_tel(self):
71-
self.assertTrue(_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "tel:+1234567890"))
73+
self.assertTrue(
74+
_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "tel:+1234567890")
75+
)
7276

7377
def test_returns_true_for_callto(self):
74-
self.assertTrue(_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "callto:username"))
78+
self.assertTrue(
79+
_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "callto:username")
80+
)
7581

7682
def test_returns_false_for_http(self):
77-
self.assertFalse(_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "http://example.com"))
83+
self.assertFalse(
84+
_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "http://example.com")
85+
)
7886

7987
def test_returns_false_for_https(self):
80-
self.assertFalse(_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "https://example.com"))
88+
self.assertFalse(
89+
_url_uses_scheme(NON_REDIRECTABLE_URL_SCHEMES, "https://example.com")
90+
)
8191

8292
def test_returns_true_for_file_in_non_resolvable(self):
83-
self.assertTrue(_url_uses_scheme(NON_RESOLVABLE_URL_SCHEMES, "file:///path/to/file"))
93+
self.assertTrue(
94+
_url_uses_scheme(NON_RESOLVABLE_URL_SCHEMES, "file:///path/to/file")
95+
)
8496

8597
def test_returns_true_for_ftp_in_non_resolvable(self):
86-
self.assertTrue(_url_uses_scheme(NON_RESOLVABLE_URL_SCHEMES, "ftp://server/path"))
98+
self.assertTrue(
99+
_url_uses_scheme(NON_RESOLVABLE_URL_SCHEMES, "ftp://server/path")
100+
)
87101

88102
def test_returns_false_for_empty_schemes_list(self):
89103
self.assertFalse(_url_uses_scheme([], "mailto:test@example.com"))
@@ -152,7 +166,11 @@ def test_add_custom_view_structure(self):
152166
self.assertEqual(len(values), original_len + 1)
153167

154168
# Last entry should be our new one
155-
matching = [v for v in values if v["row_type"] == view_name and v["row_type_icon"] == "heart"]
169+
matching = [
170+
v
171+
for v in values
172+
if v["row_type"] == view_name and v["row_type_icon"] == "heart"
173+
]
156174
self.assertTrue(len(matching) >= 1)
157175

158176
def test_add_custom_view_default_icon_is_bricks(self):

src/cs_dynamicpages/tests/test_vocab_row_width.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_vocab_row_width_term_structure(self):
4343
factory = getUtility(IVocabularyFactory, vocab_name)
4444
vocabulary = factory(self.portal)
4545
if len(vocabulary) > 0:
46-
term = list(vocabulary)[0]
46+
term = next(iter(vocabulary))
4747
self.assertIsNotNone(term.value)
4848
self.assertIsNotNone(term.token)
4949
self.assertIsNotNone(term.title)

0 commit comments

Comments
 (0)