Skip to content

Commit

Permalink
Merge pull request #72 from lsst-sitcom/tickets/DM-41885
Browse files Browse the repository at this point in the history
DM-41885: Make TMAEvents hash so they work with sets
  • Loading branch information
mfisherlevine authored Nov 29, 2023
2 parents eb06a81 + 3179904 commit b5e4c2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/lsst/summit/utils/tmaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,22 @@ def __repr__(self):
f" end={self.end!r}"
)

def __hash__(self):
# deliberately don't hash the blockInfos here, as they are not
# a core part of the event itself, and are listy and cause problems
return hash((self.dayObs,
self.seqNum,
self.type,
self.endReason,
self.duration,
self.begin,
self.end,
self.version,
self._startRow,
self._endRow
)
)

def _ipython_display_(self):
print(self.__str__())

Expand Down
4 changes: 4 additions & 0 deletions tests/test_tmaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ def test_endToEnd(self):
self.assertEqual(event.type.name, types[eventNum])
self.assertEqual(event.endReason.name, endReasons[eventNum])

eventSet = set(slews) # check we can hash
eventSet.update(slews) # check it ignores duplicates
self.assertEqual(len(eventSet), len(slews))

@vcr.use_cassette()
def test_noDataBehaviour(self):
eventMaker = self.tmaEventMaker
Expand Down

0 comments on commit b5e4c2b

Please sign in to comment.