Skip to content

Commit a7b6a79

Browse files
committed
Return lists from specs_for*
1 parent 40b4234 commit a7b6a79

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Change log
99

1010
- Fixed the broken argument validation of ``./manage.py f3dumpdata``.
1111
- Switched to hatchling and ruff.
12+
- Made ``specs_for_*_models`` helpers return a list instead of a generator.
1213

1314

1415
`0.5`_ (2023-03-15)

feincms3_data/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _validate_spec(spec):
6363

6464
def specs_for_models(models, spec=None):
6565
spec = {} if spec is None else spec
66-
return (_validate_spec({**spec, "model": cls._meta.label_lower}) for cls in models)
66+
return [_validate_spec({**spec, "model": cls._meta.label_lower}) for cls in models]
6767

6868

6969
def specs_for_derived_models(cls, spec=None):

tests/testapp/test_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_invalid_spec_missing_model(self):
5858

5959
def test_invalid_spec_unknown_keys(self):
6060
with self.assertRaises(InvalidSpec) as cm:
61-
list(specs_for_models([Parent], {"hello": "world"}))
61+
specs_for_models([Parent], {"hello": "world"})
6262
self.assertIn("contains unknown keys: {'hello'}", str(cm.exception))
6363

6464
def test_datasets(self):
@@ -80,15 +80,15 @@ def test_datasets(self):
8080
)
8181

8282
def test_specs_for_derived_models(self):
83-
specs = list(specs_for_derived_models(models.Model))
83+
specs = specs_for_derived_models(models.Model)
8484

8585
self.assertIn({"model": "auth.user"}, specs)
8686
self.assertIn({"model": "testapp.parent"}, specs)
8787
self.assertIn({"model": "testapp.child1"}, specs)
8888
self.assertNotIn({"model": "testapp.child"}, specs)
8989

9090
def test_specs_for_app_models(self):
91-
specs = list(specs_for_app_models("testapp", {"delete_missing": True}))
91+
specs = specs_for_app_models("testapp", {"delete_missing": True})
9292

9393
self.assertCountEqual(
9494
specs,
@@ -347,7 +347,7 @@ def test_pk_cache(self):
347347
self.assertEqual(pks(Parent), set())
348348

349349
def test_mappers(self):
350-
specs = list(specs_for_app_models("testapp"))
350+
specs = specs_for_app_models("testapp")
351351

352352
self.assertCountEqual(
353353
specs,
@@ -439,7 +439,7 @@ def test_should_delete_in_reverse(self):
439439
p = Parent.objects.create()
440440
p.child2_set.create()
441441

442-
specs = list(specs_for_app_models("testapp", {"delete_missing": True}))
442+
specs = specs_for_app_models("testapp", {"delete_missing": True})
443443
data = json.loads(dump_specs(specs))
444444

445445
# Create a situation where the Child2 has to be deleted before Parent

0 commit comments

Comments
 (0)