Skip to content

Commit

Permalink
Consolidate threading utility tests into one file
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirving committed Jan 3, 2024
1 parent e2c3f13 commit 2d24a30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 94 deletions.
47 changes: 0 additions & 47 deletions tests/test_locked_object.py

This file was deleted.

47 changes: 0 additions & 47 deletions tests/test_thread_safe_cache.py

This file was deleted.

28 changes: 28 additions & 0 deletions tests/test_named_locks.py → tests/test_thread_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@

import unittest

from lsst.daf.butler._utilities.locked_object import LockedObject
from lsst.daf.butler._utilities.named_locks import NamedLocks
from lsst.daf.butler._utilities.thread_safe_cache import ThreadSafeCache


class ThreadSafeCacheTestCase(unittest.TestCase):
"""Test ThreadSafeCache."""

def test_cache(self):
cache = ThreadSafeCache()
self.assertIsNone(cache.get("unknown"))
self.assertEqual(cache.set_or_get("key", "a"), "a")
self.assertEqual(cache.get("key"), "a")
self.assertEqual(cache.set_or_get("key", "b"), "a")
self.assertEqual(cache.get("key"), "a")
self.assertIsNone(cache.get("other"))


class NamedLocksTestCase(unittest.TestCase):
Expand All @@ -51,5 +66,18 @@ def test_named_locks(self):
self.assertFalse(lock2.locked())


class LockedObjectTestCase(unittest.TestCase):
"""Test LockedObject."""

def test_named_locks(self):
data = object()
locked_obj = LockedObject(data)
self.assertFalse(locked_obj._lock.locked())
with locked_obj.access() as accessed:
self.assertTrue(locked_obj._lock.locked())
self.assertIs(data, accessed)
self.assertFalse(locked_obj._lock.locked())


if __name__ == "__main__":
unittest.main()

0 comments on commit 2d24a30

Please sign in to comment.