Add less than comparison method for Addon class#326
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds a __lt__ (less than) comparison method to the Addon class, enabling sorting and comparison operations on Addon instances. The sorting is performed first by the addon's name, and then by branch_display_name as a tiebreaker for addons with the same name.
Changes:
- Added
__lt__method to enable sorting of Addon instances by name and branch_display_name
Comments suppressed due to low confidence (1)
Addon.py:83
- This class implements lt, but does not implement le or ge.
class Addon:
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def __lt__(self, other): | ||
| if not isinstance(other, Addon): | ||
| return NotImplemented | ||
| if self.name == other.name: | ||
| return self.branch_display_name < other.branch_display_name | ||
| return self.name < other.name |
There was a problem hiding this comment.
The new __lt__ method lacks test coverage. Since this method enables sorting behavior that is used in the codebase (for example, external_addons.sort() in the MissingDependencies class), it would be beneficial to add tests that verify the sorting behavior works correctly for different scenarios such as addons with the same name but different branches, and addons with different names.
AddonManagerTest/app/test_addon.py
Outdated
| self.assertLess(aa, ab) | ||
|
|
||
| same = Addon("A", branch="A") | ||
| self.assertFalse(same < aa) |
Check notice
Code scanning / CodeQL
Imprecise assert
AddonManagerTest/app/test_addon.py
Outdated
|
|
||
| same = Addon("A", branch="A") | ||
| self.assertFalse(same < aa) | ||
| self.assertFalse(aa < same) |
Check notice
Code scanning / CodeQL
Imprecise assert
AddonManagerTest/app/test_addon.py
Outdated
| def test_addon_less_than_or_equal_to(self): | ||
| a = Addon("A") | ||
| b = Addon("B") | ||
| self.assertTrue(a <= b) |
Check notice
Code scanning / CodeQL
Imprecise assert
AddonManagerTest/app/test_addon.py
Outdated
|
|
||
| aa = Addon("A", branch="A") | ||
| ab = Addon("A", branch="B") | ||
| self.assertTrue(aa <= ab) |
Check notice
Code scanning / CodeQL
Imprecise assert
| self.assertTrue(aa <= ab) | ||
|
|
||
| same = Addon("A", branch="A") | ||
| self.assertTrue(same <= aa) |
Check notice
Code scanning / CodeQL
Imprecise assert
|
|
||
| same = Addon("A", branch="A") | ||
| self.assertTrue(same <= aa) | ||
| self.assertTrue(aa <= same) |
Check notice
Code scanning / CodeQL
Imprecise assert
| self.assertLessEqual(aa, ab) | ||
|
|
||
| same = Addon("A", branch="A") | ||
| self.assertLessEqual(same, aa) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
|
|
||
| same = Addon("A", branch="A") | ||
| self.assertLessEqual(same, aa) | ||
| self.assertLessEqual(aa, same) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
|
Successfully created backport PR for |
No description provided.