Skip to content

Commit c755075

Browse files
authored
Merge pull request piccolo-orm#87 from piccolo-orm/table_finder_type_coercion
table_finder type coercion
2 parents 8d3b28e + bf79e9b commit c755075

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

piccolo/conf/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def table_finder(
4848
imported. `exclude_tags` overrides `include_tags`.
4949
5050
"""
51+
if isinstance(modules, str):
52+
# Guard against the user just entering a string, for example
53+
# 'blog.tables', instead of ['blog.tables'].
54+
modules = [modules]
55+
5156
table_subclasses: t.List[t.Type[Table]] = []
5257

5358
for module_path in modules:

tests/conf/test_apps.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ def test_table_finder(self):
7171
with self.assertRaises(ImportError):
7272
table_finder(modules=["foo.bar.baz"])
7373

74+
def test_table_finder_coercion(self):
75+
"""
76+
Should convert a string argument to a list.
77+
"""
78+
tables = table_finder(modules="tests.example_app.tables")
79+
80+
table_class_names = [i.__name__ for i in tables]
81+
table_class_names.sort()
82+
83+
self.assertEqual(
84+
table_class_names,
85+
["Band", "Concert", "Manager", "Poster", "Ticket", "Venue"],
86+
)
87+
7488
def test_include_tags(self):
7589
"""
7690
Should return all Table subclasses with a matching tag.

0 commit comments

Comments
 (0)