@@ -131,3 +131,35 @@ def main(self): ...
131131 filtered = rendering .do_filter_objects (objects , members_list = members , inherited_members = inherited_members )
132132 names = {obj .name for obj in filtered }
133133 assert names == expected_names
134+
135+
136+ @pytest .mark .parametrize (
137+ ("order" , "members_list" , "expected_names" ),
138+ [
139+ (rendering .Order .alphabetical , None , ["a" , "b" , "c" ]),
140+ (rendering .Order .source , None , ["c" , "b" , "a" ]),
141+ (rendering .Order .alphabetical , ["c" , "b" ], ["c" , "b" ]),
142+ (rendering .Order .source , ["a" , "c" ], ["a" , "c" ]),
143+ (rendering .Order .alphabetical , [], ["a" , "b" , "c" ]),
144+ (rendering .Order .source , [], ["c" , "b" , "a" ]),
145+ (rendering .Order .alphabetical , True , ["a" , "b" , "c" ]),
146+ (rendering .Order .source , False , ["c" , "b" , "a" ]),
147+ ],
148+ )
149+ def test_ordering_members (order : rendering .Order , members_list : list [str | None ], expected_names : list [str ]) -> None :
150+ """Assert the objects are correctly ordered.
151+
152+ Parameters:
153+ order: The order to use (alphabetical or source).
154+ members_list: The user specified members list.
155+ expected_names: The expected ordered list of object names.
156+ """
157+
158+ class Obj :
159+ def __init__ (self , name : str , lineno : int | None = None ) -> None :
160+ self .name = name
161+ self .lineno = lineno
162+
163+ members = [Obj ("a" , 10 ), Obj ("b" , 9 ), Obj ("c" , 8 )]
164+ ordered = rendering .do_order_members (members , order , members_list ) # type: ignore[arg-type]
165+ assert [obj .name for obj in ordered ] == expected_names
0 commit comments