Skip to content

Commit

Permalink
fix(tests): clear cache between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 11, 2023
1 parent db61697 commit 919f88c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/onnx_web/server/model_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def set(self, tag: str, key: Any, value: Any) -> None:
cache.append((tag, key, value))
self.prune()

def clear(self):
global cache

cache.clear()

def prune(self):
global cache

Expand Down
4 changes: 4 additions & 0 deletions api/tests/server/test_model_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@
class TestStringMethods(unittest.TestCase):
def test_drop_existing(self):
cache = ModelCache(10)
cache.clear()
cache.set("foo", ("bar",), {})
self.assertGreater(cache.size, 0)
self.assertEqual(cache.drop("foo", ("bar",)), 1)

def test_drop_missing(self):
cache = ModelCache(10)
cache.clear()
cache.set("foo", ("bar",), {})
self.assertGreater(cache.size, 0)
self.assertEqual(cache.drop("foo", ("bin",)), 0)

def test_get_existing(self):
cache = ModelCache(10)
cache.clear()
value = {}
cache.set("foo", ("bar",), value)
self.assertGreater(cache.size, 0)
self.assertIs(cache.get("foo", ("bar",)), value)

def test_get_missing(self):
cache = ModelCache(10)
cache.clear()
value = {}
cache.set("foo", ("bar",), value)
self.assertGreater(cache.size, 0)
Expand Down

0 comments on commit 919f88c

Please sign in to comment.