Skip to content

Commit

Permalink
Fix __eq__ not overridden when adding attributes #271
Browse files Browse the repository at this point in the history
  • Loading branch information
giffels committed Nov 10, 2023
1 parent e6efd36 commit 68c8b44
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tardis/utilities/asynccachemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ def __getitem__(self, item):

def __len__(self):
return len(self._data)

def __eq__(self, other):
if not isinstance(other, AsyncCacheMap):
return False

return (
self._update_coroutine == other._update_coroutine
and self._max_age == other._max_age
and self._last_update == other._last_update
and self._data == other._data
and self._lock == other._lock
)
27 changes: 27 additions & 0 deletions tests/utilities_t/test_asynccachemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,30 @@ def test_last_update(self):
self.assertTrue(
datetime.now() - self.async_cache_map.last_update < timedelta(seconds=1)
)

def test_eq_async_cache_map(self):
test_cache_map = AsyncCacheMap(
update_coroutine=self.async_cache_map._update_coroutine
)
# Since both objects have been recently initialized, all values (self._max_age,
# self._last_update, self._data and self._lock) are still the defaults
self.assertTrue(self.async_cache_map == test_cache_map)

Check notice

Code scanning / CodeQL

Imprecise assert Note test

assertTrue(a == b) cannot provide an informative message. Using assertEqual(a, b) instead will give more informative messages.

# Test the opposite
self.assertFalse(self.async_cache_map != test_cache_map)

Check notice

Code scanning / CodeQL

Imprecise assert Note test

assertFalse(a != b) cannot provide an informative message. Using assertEqual(a, b) instead will give more informative messages.

# change default values
run_async(self.async_cache_map.update_status)
self.assertFalse(self.async_cache_map == test_cache_map)

Check notice

Code scanning / CodeQL

Imprecise assert Note test

assertFalse(a == b) cannot provide an informative message. Using assertNotEqual(a, b) instead will give more informative messages.

# update default values, self._last_update, self._lock still differ
run_async(test_cache_map.update_status)
self.assertFalse(self.async_cache_map == test_cache_map)

Check notice

Code scanning / CodeQL

Imprecise assert Note test

assertFalse(a == b) cannot provide an informative message. Using assertNotEqual(a, b) instead will give more informative messages.

# Assimilate lock, self._last_update still differs
test_cache_map._lock = self.async_cache_map._lock
self.assertFalse(self.async_cache_map == test_cache_map)

Check notice

Code scanning / CodeQL

Imprecise assert Note test

assertFalse(a == b) cannot provide an informative message. Using assertNotEqual(a, b) instead will give more informative messages.

# Make them equal again
test_cache_map._last_update = self.async_cache_map._last_update
self.assertTrue(self.async_cache_map == test_cache_map)

Check notice

Code scanning / CodeQL

Imprecise assert Note test

assertTrue(a == b) cannot provide an informative message. Using assertEqual(a, b) instead will give more informative messages.

0 comments on commit 68c8b44

Please sign in to comment.