Skip to content

Commit

Permalink
Fix comparing uncomparable in ItemUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
TojikCZ authored and ondratu committed Jun 27, 2023
1 parent d099f7f commit bb2160f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions prusa/link/printer_adapter/structures/item_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def _default_write(value):
def __repr__(self):
return super().__repr__() + ": " + self.name

def __lt__(self, other):
if not isinstance(other, WatchedItem):
return NotImplemented
return self.name < other.name

def __eq__(self, other):
if not isinstance(other, WatchedItem):
return NotImplemented
return self.name == other.name

def __hash__(self):
return hash(self.name)


class WatchedGroup(Watchable):
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_item_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import math
from queue import PriorityQueue
from time import sleep, time
from unittest.mock import Mock

Expand Down Expand Up @@ -599,3 +600,15 @@ def test_group_updating(updater_instance: ItemUpdater):
updater_instance.invalidate(item)
item_gather.event.wait(THRESHOLD)
item_gather.event.clear()


def test_priority_queue():
"""Tests that you can have two watched items with the same priority
and the app does not throw an error"""
item_1 = WatchedItem("item_1")
item_2 = WatchedItem("item_2")
queue = PriorityQueue()
queue.put((1, item_1))
queue.put((1, item_2))
queue.get()
queue.get()

0 comments on commit bb2160f

Please sign in to comment.